Error: java.lang.SecurityException: Permission Denial: starting Intent with another flavor
Error: java.lang.SecurityException: Permission Denial: starting Intent with another flavor
我正在开发一个有 2 种风格的应用程序,免费版和专业版。免费似乎工作正常但是当我尝试从首选项 activity 设置转到 activity 名称时出现此错误:
-12 00:41:49.473 18533-18533/com.albertoha94.apps.DuelHelperReloaded.Pro E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.albertoha94.apps.DuelHelperReloaded.Pro, PID: 18533
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW cmp=com.albertoha94.apps.DuelHelperReloaded/.NameList } from ProcessRecord{9f48ed8 18533:com.albertoha94.apps.DuelHelperReloaded.Pro/u0a59} (pid=18533, uid=10059) not exported from uid 10060
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2611)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1502)
at android.app.Activity.startActivityForResult(Activity.java:3825)
at android.app.Activity.startActivityForResult(Activity.java:3785)
at android.app.Activity.startActivity(Activity.java:4100)
at android.app.Activity.startActivity(Activity.java:4068)
at android.preference.Preference.performClick(Preference.java:1012)
at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
at android.widget.AdapterView.performItemClick(AdapterView.java:309)
at android.widget.AbsListView.performItemClick(AbsListView.java:1156)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView.run(AbsListView.java:3899)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5401)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
我的模块结构是这样的:
src
-debug
-java->package->Namelist
-main
-java->package->SettingsDuel
NameListStructure(A class that extends arrayAdapter, i use it to show the list in a format i want)
-pro
-layout->mainscreen(used in Dhmain)
-prodebug
-java->...DHMain
-prorelease
-java->...DHMain
-release
-java->...NameList
没有显示免费版本结构,因为我认为它没有必要,它工作正常。
NameList 在两个版本中都处于调试状态,它们都有细微的变化,我创建了那个目录,所以我不需要在 free/pro 目录中有一个副本。
DHMain 的变化取决于它的 free/pro 和 debug/release。
SettingsDuel 仅在 main 中,永远不会改变。
我通过 SettingsDuel 访问 activity NameList 是这样的:
<Preference
android:enabled="true"
android:title="@string/Names">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.albertoha94.apps.DuelHelperReloaded"
android:targetClass="com.albertoha94.apps.DuelHelperReloaded.NameList"/>
</Preference>
这是在主目录中的一个 xml 文件中,它永远不会改变。这也是访问 NameList activity.
的唯一方法
最后,appid 根据应用风格而变化(我认为这可能是导致问题的原因,因为免费版本不会改变它的 id,而且它工作正常):
免费:
applicationId 'com.albertoha94.apps.DuelHelperReloaded'
亲:
applicationId 'com.albertoha94.apps.DuelHelperReloaded.Pro'
我试过以下方法:
-在class设置决斗中添加android:exported="true"
-在class NameList中添加android:exported="true"。
-在 class 中添加 android:exported="true" classes.
-将 class NameList 添加到专业包(prodebug 和 proRelease)
-正在清理项目。
-重建项目。
此时我不知道还能尝试什么。
编辑:
按照 Minhtdh 在他的回答中所说的进行操作后,它有点奏效了。 activity NameList 仅在我安装了免费版本时才有效。
如果我尝试仅使用专业版访问 activity NameList,它会显示此错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.albertoha94.apps.DuelHelperReloaded/com.albertoha94.apps.DuelHelperReloaded.NameList}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1782)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
at android.app.Activity.startActivityForResult(Activity.java:3825)
at android.app.Activity.startActivityForResult(Activity.java:3785)
at android.app.Activity.startActivity(Activity.java:4100)
at android.app.Activity.startActivity(Activity.java:4068)
at android.preference.Preference.performClick(Preference.java:1012)
at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
at android.widget.AdapterView.performItemClick(AdapterView.java:309)
at android.widget.AbsListView.performItemClick(AbsListView.java:1156)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView.run(AbsListView.java:3899)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5401)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
它说它找不到 activity NameList,即使我在清单中有它(清单在主目录中):
<activity
android:name=".NameList"
android:label="@string/Names"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.albertoha94.apps.DuelHelperReloaded.SettingsDuel" />
</activity>
我认为您的问题是:您的专业版正在尝试启动免费版服务。
而且根据你的描述,我猜你只重建了专业版,对吧?
如果那是真的,你应该试试这个:
- 在 class 名称列表中添加 android:exported="true"。
- 然后重建并安装免费版。
- 然后运行并使用专业版进行测试。
希望这有效。
更新
您的免费版应用程序 ID 是 com.albertoha94.apps.DuelHelperReloaded
专业版是 com.albertoha94.apps.DuelHelperReloaded.Pro
由于 SettingsDuel
偏好中的意图:
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.albertoha94.apps.DuelHelperReloaded"
android:targetClass="com.albertoha94.apps.DuelHelperReloaded.NameList"/>
该意图将尝试从免费应用程序打开 activity(class 两个应用程序中的名称和操作相同,但 targetPackage
限制仅打开免费版本的意图)
-> 所以当从专业应用程序打开时,您将有权限错误(由于不同的过程)或 activitynotfound
如果不安装免费应用程序。
如果您想从专业版打开 activity,只需为每个应用程序使用不同的 targetPackage
。(专业版使用 android:targetPackage="com.albertoha94.apps.DuelHelperReloaded.Pro"
)
我正在开发一个有 2 种风格的应用程序,免费版和专业版。免费似乎工作正常但是当我尝试从首选项 activity 设置转到 activity 名称时出现此错误:
-12 00:41:49.473 18533-18533/com.albertoha94.apps.DuelHelperReloaded.Pro E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.albertoha94.apps.DuelHelperReloaded.Pro, PID: 18533
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW cmp=com.albertoha94.apps.DuelHelperReloaded/.NameList } from ProcessRecord{9f48ed8 18533:com.albertoha94.apps.DuelHelperReloaded.Pro/u0a59} (pid=18533, uid=10059) not exported from uid 10060
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2611)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1502)
at android.app.Activity.startActivityForResult(Activity.java:3825)
at android.app.Activity.startActivityForResult(Activity.java:3785)
at android.app.Activity.startActivity(Activity.java:4100)
at android.app.Activity.startActivity(Activity.java:4068)
at android.preference.Preference.performClick(Preference.java:1012)
at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
at android.widget.AdapterView.performItemClick(AdapterView.java:309)
at android.widget.AbsListView.performItemClick(AbsListView.java:1156)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView.run(AbsListView.java:3899)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5401)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
我的模块结构是这样的:
src
-debug
-java->package->Namelist
-main
-java->package->SettingsDuel
NameListStructure(A class that extends arrayAdapter, i use it to show the list in a format i want)
-pro
-layout->mainscreen(used in Dhmain)
-prodebug
-java->...DHMain
-prorelease
-java->...DHMain
-release
-java->...NameList
没有显示免费版本结构,因为我认为它没有必要,它工作正常。
NameList 在两个版本中都处于调试状态,它们都有细微的变化,我创建了那个目录,所以我不需要在 free/pro 目录中有一个副本。
DHMain 的变化取决于它的 free/pro 和 debug/release。
SettingsDuel 仅在 main 中,永远不会改变。
我通过 SettingsDuel 访问 activity NameList 是这样的:
<Preference
android:enabled="true"
android:title="@string/Names">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.albertoha94.apps.DuelHelperReloaded"
android:targetClass="com.albertoha94.apps.DuelHelperReloaded.NameList"/>
</Preference>
这是在主目录中的一个 xml 文件中,它永远不会改变。这也是访问 NameList activity.
的唯一方法最后,appid 根据应用风格而变化(我认为这可能是导致问题的原因,因为免费版本不会改变它的 id,而且它工作正常):
免费:
applicationId 'com.albertoha94.apps.DuelHelperReloaded'
亲:
applicationId 'com.albertoha94.apps.DuelHelperReloaded.Pro'
我试过以下方法:
-在class设置决斗中添加android:exported="true"
-在class NameList中添加android:exported="true"。
-在 class 中添加 android:exported="true" classes.
-将 class NameList 添加到专业包(prodebug 和 proRelease)
-正在清理项目。
-重建项目。
此时我不知道还能尝试什么。
编辑:
按照 Minhtdh 在他的回答中所说的进行操作后,它有点奏效了。 activity NameList 仅在我安装了免费版本时才有效。
如果我尝试仅使用专业版访问 activity NameList,它会显示此错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.albertoha94.apps.DuelHelperReloaded/com.albertoha94.apps.DuelHelperReloaded.NameList}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1782)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
at android.app.Activity.startActivityForResult(Activity.java:3825)
at android.app.Activity.startActivityForResult(Activity.java:3785)
at android.app.Activity.startActivity(Activity.java:4100)
at android.app.Activity.startActivity(Activity.java:4068)
at android.preference.Preference.performClick(Preference.java:1012)
at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
at android.widget.AdapterView.performItemClick(AdapterView.java:309)
at android.widget.AbsListView.performItemClick(AbsListView.java:1156)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView.run(AbsListView.java:3899)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5401)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
它说它找不到 activity NameList,即使我在清单中有它(清单在主目录中):
<activity
android:name=".NameList"
android:label="@string/Names"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.albertoha94.apps.DuelHelperReloaded.SettingsDuel" />
</activity>
我认为您的问题是:您的专业版正在尝试启动免费版服务。
而且根据你的描述,我猜你只重建了专业版,对吧?
如果那是真的,你应该试试这个:
- 在 class 名称列表中添加 android:exported="true"。
- 然后重建并安装免费版。
- 然后运行并使用专业版进行测试。
希望这有效。
更新
您的免费版应用程序 ID 是 com.albertoha94.apps.DuelHelperReloaded
专业版是 com.albertoha94.apps.DuelHelperReloaded.Pro
由于 SettingsDuel
偏好中的意图:
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.albertoha94.apps.DuelHelperReloaded"
android:targetClass="com.albertoha94.apps.DuelHelperReloaded.NameList"/>
该意图将尝试从免费应用程序打开 activity(class 两个应用程序中的名称和操作相同,但 targetPackage
限制仅打开免费版本的意图)
-> 所以当从专业应用程序打开时,您将有权限错误(由于不同的过程)或 activitynotfound
如果不安装免费应用程序。
如果您想从专业版打开 activity,只需为每个应用程序使用不同的 targetPackage
。(专业版使用 android:targetPackage="com.albertoha94.apps.DuelHelperReloaded.Pro"
)