SecurityException:不允许启动 Activity Intent
SecurityException: Not allowed to start an Activity Intent
我们正准备发布我们的免安装应用程序,但是,当 运行在 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
意图打开应用程序其他功能中列出的活动,非常类似于 Google 提供的示例。
当我们的应用程序通过 URL 打开时,它被发送到我们基本功能中的路由器 Activity 来处理解析 URI 并打开适当的 Activity 来处理 URL路径。
- 基本功能 -- UrlRouterActivity
- 功能 1 -- 功能 1Activity
基本功能清单:
<?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
事实证明,当 运行 来自 Google 的 AIA 应用程序播放时,字符串引用不能很好地与清单一起播放。在方案上明确设置字符串值可解决此问题。
正在替换
<data android:scheme="@string/filter_scheme_secure" />
和
<data android:scheme="https" />
问题已解决。
供参考,data
属性不能是资源,只能是字符串
https://developer.android.com/guide/topics/manifest/data-element.html
与服务标签相比,它确实列出了一些可以是字符串资源的属性。 (标签)
https://developer.android.com/guide/topics/manifest/service-element.html
我能想到的主要原因是标签可以是不同的语言,并且在运行时会发生变化。您没有很多 URI 方案选项,而且它们在应用程序生命周期内不会更改
我们正准备发布我们的免安装应用程序,但是,当 运行在 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
意图打开应用程序其他功能中列出的活动,非常类似于 Google 提供的示例。
当我们的应用程序通过 URL 打开时,它被发送到我们基本功能中的路由器 Activity 来处理解析 URI 并打开适当的 Activity 来处理 URL路径。
- 基本功能 -- UrlRouterActivity
- 功能 1 -- 功能 1Activity
基本功能清单:
<?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
事实证明,当 运行 来自 Google 的 AIA 应用程序播放时,字符串引用不能很好地与清单一起播放。在方案上明确设置字符串值可解决此问题。
正在替换
<data android:scheme="@string/filter_scheme_secure" />
和
<data android:scheme="https" />
问题已解决。
供参考,data
属性不能是资源,只能是字符串
https://developer.android.com/guide/topics/manifest/data-element.html
与服务标签相比,它确实列出了一些可以是字符串资源的属性。 (标签)
https://developer.android.com/guide/topics/manifest/service-element.html
我能想到的主要原因是标签可以是不同的语言,并且在运行时会发生变化。您没有很多 URI 方案选项,而且它们在应用程序生命周期内不会更改