简体   繁体   English

错误:java.lang.SecurityException:权限拒绝:以另一种方式启动Intent

[英]Error: java.lang.SecurityException: Permission Denial: starting Intent with another flavor

I'm working on an application that has 2 flavors, free and pro. 我正在开发具有2种口味的应用程序,免费和专业。 The free seems to work fine but when i try to go from the preference activity Settings to the activity names It appears this error: 免费似乎工作正常,但是当我尝试从首选项活动设置转到活动名称时,出现此错误:

-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$3.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)

The structure of my module is something like this: 我的模块的结构是这样的:

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

Didn't show the free version structure as i dont think its necessary, its working fine. 没有显示免费版本的结构,因为我认为它不是必需的,它的运行正常。

NameList is in both debug in release, they both have minor changes and i created that directory so i dont need to have a copy in the free/pro directories. NameList在发布中都处于调试状态,它们都进行了较小的更改,并且我创建了该目录,因此不需要在free / pro目录中创建副本。

DHMain changes depending if its free/pro and debug/release. DHMain的更改取决于其免费/专业版和调试/发行版。

SettingsDuel is in main only and it never changes. SettingsDuel仅在main中,并且永远不会更改。

I access the activity NameList through SettingsDuel this way: 我可以通过SettingsDuel通过以下方式访问活动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>

This is in an xml file in the main directory, it never changes. 这是在主目录中的xml文件中,它永远不会更改。 Also its the only way to access the NameList activity. 这也是访问NameList活动的唯一方法。

And finally, the appid changes according to the app flavor (i think this could be causing the problem because the free version doesnt change its id and it works fine): 最后,appid根据应用程序的风格进行更改(我认为这可能是导致问题的原因,因为免费版本不会更改其id且可以正常工作):

free: 自由:

applicationId 'com.albertoha94.apps.DuelHelperReloaded'

pro: 优点:

applicationId 'com.albertoha94.apps.DuelHelperReloaded.Pro'

I've tried the following: 我尝试了以下方法:

-Add android:exported="true" in class SettingsDuel. -在SettingsDuel类中添加android:exported =“ true”。

-Add android:exported="true" in class NameList. -在NameList类中添加android:exported =“ true”。

-Add android:exported="true" in class Both classes. -在两个类中都添加android:exported =“ true”。

-Add the class NameList to the pro packages (prodebug and proRelease) -将类NameList添加到pro软件包(prodebug和proRelease)

-Cleaning the project. -清洁项目。

-Rebuild project. -重建项目。

At this point i dont know what else to try. 在这一点上,我不知道还有什么尝试。

EDIT: 编辑:

After doing what Minhtdh told in his answer it sort of worked. 在完成Minhtdh在他的回答中告诉他的事情后,它确实起作用了。 The activity NameList works ONLY if i have the free version installed to. 仅当我安装了免费版本时,活动NameList才起作用。

If i try to access activity NameList with the pro version only it shows this error: 如果我尝试仅使用专业版访问活动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$3.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)

It says it cant find the activity NameList even if though i have it in the manifest (the manifest is in the main directory): 它说即使我在清单(清单在主目录中)中也找不到活动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>

I think your problem is: your pro version is trying to start an service in free version. 我认为您的问题是:您的专业版正在尝试以免费版启动服务。
And from your description, I guess you only rebuild the pro version, right? 从您的描述来看,我猜您只能重建专业版,对吗?
If that true, you should try this: 如果是这样,则应尝试以下操作:

  • Add android:exported="true" in class NameList. 在类NameList中添加android:exported =“ true”。
  • Then rebuild and install free version . 然后重建并安装免费版本
  • Then run and test with the pro version. 然后运行并测试专业版。

Hope this works. 希望这行得通。
Update 更新资料
Your free version app id is com.albertoha94.apps.DuelHelperReloaded 您的免费版本应用程序ID为com.albertoha94.apps.DuelHelperReloaded
and pro version is com.albertoha94.apps.DuelHelperReloaded.Pro 专业版是com.albertoha94.apps.DuelHelperReloaded.Pro
Because of the intent in SettingsDuel preference: 由于SettingsDuel首选项的意图:

<intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.albertoha94.apps.DuelHelperReloaded"
        android:targetClass="com.albertoha94.apps.DuelHelperReloaded.NameList"/>

That intent will try to open activity from the free app (class name and action are same in both apps, but the targetPackage retrict intent to open free version only) 该意图将尝试从免费应用程序打开活动(两个应用程序中的类名和操作相同,但targetPackage限制意图仅打开免费版本)
-> So when open from pro app, you will have permission error (due different process) or activitynotfound if don't install free app. ->因此,从专业版应用程序打开时,如果不安装免费应用程序,则将出现权限错误(由于不同的过程)或activitynotfound

If you want to open the activity from pro version, just use different targetPackage for each app.(for pro version use android:targetPackage="com.albertoha94.apps.DuelHelperReloaded.Pro" ) 如果您想从专业版打开活动,只需为每个应用使用不同的targetPackage 。(对于专业版,请使用android:targetPackage="com.albertoha94.apps.DuelHelperReloaded.Pro"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.SecurityException:权限拒绝错误 - java.lang.SecurityException: Permission Denial ERROR java.lang.SecurityException:权限拒绝:启动意图{act = android.settings.USAGE_ACCESS_SETTINGS} - java.lang.SecurityException: Permission Denial: starting Intent {act=android.settings.USAGE_ACCESS_SETTINGS} java.lang.SecurityException:权限被拒绝:启动 Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] - java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] 托管小部件获取 java.lang.SecurityException:权限拒绝错误 - Hosting widgets getting java.lang.SecurityException: Permission Denial error Android:java.lang.SecurityException:权限拒绝:开始发送邮件的意图 - Android: java.lang.SecurityException: Permission Denial: start Intent to send mail 应用程序崩溃,并出现java.lang.SecurityException:权限被拒绝 - App crashes with java.lang.SecurityException: Permission Denial android sdk,错误:java.lang.SecurityException:Permission Denial:尝试更改组件状态 - android sdk , error : java.lang.SecurityException: Permission Denial: attempt to change component state java.lang.SecurityException:Permission Denial:需要com.huawei.android.launcher.permission.WRITE_SETTINGS - java.lang.SecurityException: Permission Denial: requires com.huawei.android.launcher.permission.WRITE_SETTINGS java.lang.SecurityException:Permission denial:写入设置需要android.permission.WRITE_SETTINGS - java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS 总是获取java.lang.SecurityException:权限拒绝尝试从外部存储读取数据 - always get java.lang.SecurityException: Permission Denial trying to read the data from external storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM