【问题标题】:SecurityException: Not allowed to start an Activity IntentSecurityException:不允许启动 Activity Intent
【发布时间】:2017-08-26 15:30:56
【问题描述】:

我们正准备发布我们的免安装应用,但是在 Google Play 的 AIA 开发轨道中运行我们的 AIA 应用时遇到了问题。
我们的 AIA 应用可以在 Android Studio 中完美运行,但是当尝试从 Play 商店在真实设备上运行时会出现此问题。
感谢您提供任何帮助。

有问题的错误:

java.lang.SecurityException: Not allowed to start activity Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=https://www.example.com/... pkg=com.example (has extras) }

我们的 AIA 设置为运行 ACTION_VIEW Intents 以打开应用程序其他功能中列出的活动,非常类似于 Google 提供的示例。
当我们的应用通过 URL 打开时,它会被发送到 Base Feature 中的路由器 Activity 以处理解析 URI 并打开适当的 Activity 来处理 URL 路径。

  • 基本功能 -- UrlRouterActivity
  • 功能 1 -- Feature1Activity

基本功能清单:

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

    <application>
        <activity
            android:name=".activity.UrlRouterActivity"
            android:noHistory="true"
            android:launchMode="singleInstance"
            android:theme="@style/Theme.AppCompat.NoDisplay">
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.example.com" />
                <data android:pathPrefix="/path" />
            </intent-filter>
        </activity>
    </application>

</manifest>

功能 1 清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rentpath.lib.pdp">

    <application>
        <activity
            android:name=".activity.Feature1Activity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/filter_scheme_secure" /> <!-- String resource for https -->
                <data android:host="www.example.com" />
                <data android:pathPrefix="/action_feature_1" />
            </intent-filter>
            <intent-filter>
                <action android:name="action_feature_1"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

我们的路由器 Activity 获取 URI,解构 URL 参数,然后构造一个 Intent,如下所示:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https:www.example.com/action_feature_1?some_param=some_value"));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setPackage(context.getPackageName());
startActivity(intent);

启动此 Activity 会导致顶部提到的异常。
同样,这只发生在从 Google Play 的开发轨道运行 AIA 应用程序时。
从 Android Studio 运行 AIA 应用时不会出现这种情况。

附加信息:

Android Studio 3.0 Beta 2
Gradle plugin: 3.0.0-beta2
Gradle wrapper distribution: 4.1-rc-1

【问题讨论】:

  • 不,它不是重复的。另外,我已经添加了解决方案。您甚至阅读了整篇文章吗?
  • 请回答下面的问题,而不是对问题的编辑
  • 您不需要任何代表来回答
  • 请查看此问题的公共错误链接:issuetracker.google.com/issues/68084954,以便您也可以在此处跟踪更新。

标签: android android-instant-apps


【解决方案1】:

事实证明,当从 Google Play 运行 AIA 应用程序时,字符串引用不能很好地与清单配合使用。在方案上显式设置字符串值可以解决问题。

替换

<data android:scheme="@string/filter_scheme_secure" /> 

<data android:scheme="https" /> 

解决了问题。

【讨论】:

    【解决方案2】:

    供参考,data属性不能是资源,只能是字符串

    https://developer.android.com/guide/topics/manifest/data-element.html

    与服务标签相比,服务标签确实列出了一些可以是字符串资源的属性。 (标签)

    https://developer.android.com/guide/topics/manifest/service-element.html

    我能想到的主要原因是标签可以是不同的语言并在运行时更改。对于 URI 方案,您没有太多选择,并且它们在应用程序生命周期内不会改变

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      • 2021-12-13
      • 2018-03-08
      相关资源
      最近更新 更多