android - 单击“立即尝试”按钮时即时应用程序崩溃

标签 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);
        }
    }

在 list 中:

<?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 映射中,我通过 splash 中的 URL 打开了我的主应用程序。 这是 URL 映射图像。

enter image description here

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

enter image description here

最佳答案

现在点击尝试即可,您的 ActivitySplash 已启动。正如您从堆栈跟踪中看到的那样,崩溃发生在您在 onCreate 中启动自己的第二个 Intent 时。问题是你在 Intent 上指定包

intent.setPackage(getPackageName());

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

顺便说一句,如果你想在 intent-filters 中同时支持 HTTP 和 HTTPS,你不需要写两次 intent-filter。只需添加

<data android:scheme="https" />

到现有的 HTTP intent-filter,这两种方案都将匹配您的 Activity。

关于android - 单击“立即尝试”按钮时即时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53893669/

相关文章:

C++动态整数数组有时会导致崩溃

Android Volley SQLite 集成/组合

android - 在 android 中,我应该在什么时候将主游戏循环放在初始 Activity 类中?

android - 即时应用程序上传失败 - http 和 https 方案都应该是

android - Firebase Analytics 不适用于 Instant App 或 Normal App

java - 如何在Instant Apps中实现Multi Dex?

Xcode9.4.1 : Crash when debugging process as root

android - 在所有安卓设备上显示图像

android - 如何保留 Android 库的源代码?

xcode - 在Iphone Simulator中进行调试时崩溃