单击立即尝试按钮时,即时应用崩溃

时间:2018-12-22 06:52:18

标签: android android-instant-apps crash instant

当我测试即时应用程序时,它可以正常运行,但是当我单击“立即尝试”按钮上传到Play商店后,应用程序崩溃了。

当我单击立即尝试按钮时,这是我的代码:

package com.journaldev.androidinstantapps.feature;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class ActivitySplash extends Activity {


        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.splashfeature);


            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://quickeselling.com/splash"));
            intent.setPackage(getPackageName());
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            startActivity(intent);
        }
    }

清单中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.journaldev.androidinstantapps.feature">

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application>
        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />
        <activity
            android:name=".ActivitySplash"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="default-url"
                android:value="https://quickeselling.com/preview" />

            <intent-filter
                android:autoVerify="true"
                android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="quickeselling.com"
                    android:pathPrefix="/preview"
                    android:scheme="http" />
            </intent-filter>
            <intent-filter
                android:autoVerify="true"
                android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="quickeselling.com"
                    android:pathPrefix="/preview"
                    android:scheme="https" />
            </intent-filter>

        </activity>
    </application>

</manifest>

在URL映射中,我通过启动时的URL打开了我的主应用程序。 这是URL映射图像。

enter image description here

我尝试了很多,但不知道出了什么问题。请帮我解决这个问题。这是崩溃日志:

enter image description here

2 个答案:

答案 0 :(得分:4)

点击尝试现在可以使用,并且您的ActivitySplash已启动。从堆栈跟踪中可以看到,崩溃是由于您在onCreate中启动第二个意图而发生的。问题是您在意图上指定了包装

intent.setPackage(getPackageName());

由于未安装您的应用程序,因此Android找不到符合此意图的任何内容。 如果要启动的Activity在同一模块中,请通过指定Activity类将该意图转换为明确的意图。否则,请移除setPackage,然后Android会加载处理该链接的功能模块并将其显示给用户(或者,如果找不到匹配的功能模块,则在浏览器中打开该URL)

顺便说一句,如果要在意图过滤器中同时支持HTTP和HTTPS,则无需编写两次意图过滤器。只需添加

<data android:scheme="https" />

到现有的HTTP Intent过滤器,这两种方案都将与您的Activity匹配。

答案 1 :(得分:1)

您尝试从即时应用程序ActivitySplash启动的URL:https://quickeselling.com/splash在您的即时应用程序中不受支持(至少从您显示的功能清单中不支持)。您提供的功能清单仅支持/preview

是的,例外是正确的,将找不到任何活动来处理此意图/ URL。

现在,您已经获得了一个屏幕截图,其中显示了支持com.android.application URL的/splash模块。但是,您的应用程序模块不是作为即时应用程序的一部分安装的,只有在用户安装了完整应用程序时才安装。

如果您另有考虑,则无法在即时模块作为即时应用程序的状态下从即时模块访问应用程序模块中的任何内容。

您必须将支持/splash的活动移至您的功能模块之一,才能正常工作。

这将帮助您对即时应用程序的结构有所了解:What dependencies should one be putting in each module of an instant app?

注意:当您从Studio开发时,应该没有办法让它正常工作,除非您在不知不觉中将其作为已安装的应用程序而不是即时应用程序运行的情况(看来确实如此)屏幕截图,其中显示app为选定的运行版本。

相关问题