Android . lang。SecurityException:权限拒绝:开始意图

时间:2022-10-12 07:25:50

I have a library (jar) on build path of my project. The project accesses the MainActivity in the jar, using the following intent:

我在项目的构建路径上有一个库(jar)。项目使用以下意图访问jar中的主活动:

final Intent it = new Intent();
it.setClassName("com.example.lib", "com.example.lib.MainActivity");
startActivity(it);

It used to work for sometime, but suddenly started getting 'ActivityNotFoundException: No Activity found to handle Intent' which I was able to resolve. But now I am stuck with a 'java.lang.SecurityException: Permission Denial: starting Intent'.

它曾经有一段时间是有效的,但突然开始出现“ActivityNotFoundException:没有发现处理意图的活动”,这是我能够解决的。但现在我只能使用java.lang。SecurityException:权限拒绝:开始意图。

I have tried all suggestions made on * (check for duplicates in manifest file; add android:exported="true" to lib manifest; Eclipse> Project> Clean; adding/ modifying 'intent-filter' tags; etc.). I even tried re-writing the manifest of the project but not going anywhere with it.

我尝试了所有关于*的建议(检查清单文件中的副本;添加android:导出=“true”到lib manifest;Eclipse项目> >清洁;添加/修改“意图过滤器”标签;等等)。我甚至尝试过重写项目的清单,但是没有去任何地方。

Here's the logcat output:

这是logcat输出:

11-07 06:20:52.176: E/AndroidRuntime(4626): FATAL EXCEPTION: main
11-07 06:20:52.176: E/AndroidRuntime(4626): java.lang.SecurityException: Permission     Denial: starting Intent { cmp=com.example.lib/.MainActivity } from ProcessRecord{40dd3778     4626:com.example.project/u0a10046} (pid=4626, uid=10046) not exported from uid 10047
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.os.Parcel.readException(Parcel.java:1425)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.os.Parcel.readException(Parcel.java:1379)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1885)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1412)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Activity.startActivityForResult(Activity.java:3370)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Activity.startActivityForResult(Activity.java:3331)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:824)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Activity.startActivity(Activity.java:3566)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Activity.startActivity(Activity.java:3534)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.example.project.MainActivity.onOptionsItemSelected(MainActivity.java:93)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.Activity.onMenuItemSelected(Activity.java:2548)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:366)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.view.View.performClick(View.java:4204)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.view.View$PerformClick.run(View.java:17355)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.os.Handler.handleCallback(Handler.java:725)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.os.Looper.loop(Looper.java:137)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at android.app.ActivityThread.main(ActivityThread.java:5041)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at java.lang.reflect.Method.invokeNative(Native Method)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at java.lang.reflect.Method.invoke(Method.java:511)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
11-07 06:20:52.176: E/AndroidRuntime(4626):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-07 06:20:52.176: E/AndroidRuntime(4626):     at dalvik.system.NativeStart.main(Native Method)

Manifest XML of Project:

清单XML的项目:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="4"
android:versionName="4.0" >

<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<supports-screens android:anyDensity="true" />

<!-- SDK Settings -->
<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="18" />

<!-- APP Start -->
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

<!-- App Activity -->
    <activity
        android:name="com.example.project.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<!-- Library Activity -->
    <activity android:name="com.example.lib.MainActivity" android:label="LibMain">
         <intent-filter>
        <action android:name="android.intent.action.MAIN"></action>
     </intent-filter>
    </activity>

</application>
<!-- END - APP -->

</manifest>

What am I overlooking? Any suggestions?

我俯瞰着什么呢?有什么建议吗?

EDIT

编辑

I updated the manifest.xml with all other activities & somehow, that resolved the problem. The intent activity starts up without any errors. BUT, this is only on AVD. On actual device, it is still throwing same error. I have uninstalled the app from device completely and reinstalled, yet the same error.

我更新了清单。xml与所有其他活动&以某种方式解决了这个问题。意图活动启动时没有任何错误。但这只是在AVD上。在实际设备上,它仍然抛出相同的错误。我已经完全从设备上卸载并重新安装了应用程序,但是同样的错误。

8 个解决方案

#1


97  

The exception is clear. You need to set android:exported="true" in your AndroidManifest.xml file where you declare this Activity.

例外是明确的。您需要在AndroidManifest中设置android: exports =“true”。声明此活动的xml文件。

Edit

编辑

<activity
    android:name="com.example.lib.MainActivity"
    android:label="LibMain" 
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" >
        </action>
    </intent-filter>
</activity>

#2


38  

This is only for android studio

So I ran into this problem recently. The issue was in the build/run configuration. Apparently android studio had chosen an activity in my project as the launch activity thus disregarding my choice in the manifest file.

所以我最近遇到了这个问题。问题出现在构建/运行配置中。显然,android studio在我的项目中选择了一个活动作为启动活动,从而忽略了我在清单文件中的选择。

Click on the module name just to the left of the run button and click on "Edit configurations..." Now make sure "Launch default Activity" is selected.

单击run按钮左边的模块名,然后单击“编辑配置…”现在确保选中“启动默认活动”。

The funny thing when I got this error was that I could still launch the app with from the device and it starts with the preferred Activity. But launching from the IDE seemed impossible.

当我犯这个错误时,有趣的是我仍然可以从设备上启动这个应用程序,它从首选的活动开始。但是从IDE中启动似乎是不可能的。

#3


27  

Select your proper configuration for launching Application.

为启动应用程序选择适当的配置。

In my case i found mistake as below image:

在我的案例中,我发现错误如下图所示:

Android . lang。SecurityException:权限拒绝:开始意图

I had just changed like:

我就像:

Android . lang。SecurityException:权限拒绝:开始意图

May it will help to someone, Thanks :)

希望对某人有所帮助,谢谢

#4


4  

Add android:exported="true" in your 'com.example.lib.MainActivity' activity tag.

添加android:在您的com.example.lib中导出="true"。MainActivity标签”活动。

From the android:exported documentation,

从android:导出的文档,

android:exported Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

android:导出该活动是否可以由其他应用程序的组件启动——如果可以,则为“true”;如果不能,则为“false”。如果“false”,则只能由具有相同用户ID的相同应用程序或应用程序的组件启动活动。

From your logcat output, clearly a mismatch in uid is causing the issue. So adding the android:exported="true" should do the trick.

从logcat输出中,显然是uid的不匹配导致了问题。因此,添加android: exports =“true”就可以了。

#5


2  

Similar to Olayinka's answer about the configuration file for ADT: I just had the same issue on IntelliJ's IdeaU v14.

类似于Olayinka关于ADT配置文件的回答:我刚刚在IntelliJ的IdeaU v14上遇到了同样的问题。

I'm working through a tutorial that had me change the starting activity from MyActivity to MyListActivity (Which is a list of MyActivity). I started getting Permissions Denial.

我正在学习一个教程,该教程让我将开始活动从MyActivity更改为MyListActivity (MyListActivity的一个列表)。我开始拒绝权限。

After much trial, toil and pain: In .idea\workspace.xml:

经过大量的尝试,辛苦和痛苦:In .idea\workspace.xml:

...
<configuration default="false" name="MyApp" type="AndroidRunConfigurationType" factoryName="Android Application">
    <module name="MyApp" />
    <option name="ACTIVITY_CLASS" value="com.domain.MyApp.MyActivity" />
    ...
</configuration>
...

I changed the MyActivity to MyListActivity, reloaded the project and I'm off to a rolling start again.

我将MyActivity更改为MyListActivity,重新加载项目,然后又开始滚动了。

Not sure which IDE you are using, but maybe your IDE is overriding or forcing a specific starting activity?

不确定您正在使用哪个IDE,但是您的IDE可能正在重写或强制执行特定的启动活动?

#6


1  

If you are trying to test your app coded in android studio through your android phone, its generally the issue of your phone. Just uncheck all the USB debugging options and toggle the developer options to OFF. Then restart your phone and switch the developer and USB debugging on. You are ready to go!

如果你想通过你的android手机在android studio中测试你的应用程序,它通常是你手机的问题。只需取消所有USB调试选项并将开发人员选项切换到OFF,然后重新启动手机并打开开发人员和USB调试。你准备好出发了!

#7


0  

In my case, this error was due to incorrect paths used to specify intents in my preferences xml file after I renamed the project. For instance, where I had:

在我的例子中,这个错误是由于在我重命名项目后,在我的首选项xml文件中指定意图的路径错误造成的。例如,我有:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:key="pref_edit_recipe_key"
        android:title="Add/Edit Recipe">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.ssimon.olddirectory"
            android:targetClass="com.ssimon.olddirectory.RecipeEditActivity"/>
    </Preference>
</PreferenceScreen> 

I needed the following instead:

我需要的是以下内容:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:key="pref_edit_recipe_key"
        android:title="Add/Edit Recipe">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.ssimon.newdirectory"
            android:targetClass="com.ssimon.newdirectory.RecipeEditActivity"/>
</Preference>

Correcting the path names fixed the problem.

修正路径名修正了问题。

#8


0  

if we make the particular activity as

如果我们使特定的活动为

android:exported="true"

it will be the launching activity. Click on the module name just to the left of the run button and click on "Edit configurations..." Now make sure "Launch default Activity" is selected.

这将是发射活动。单击run按钮左边的模块名,然后单击“编辑配置…”现在确保选中“启动默认活动”。

#1


97  

The exception is clear. You need to set android:exported="true" in your AndroidManifest.xml file where you declare this Activity.

例外是明确的。您需要在AndroidManifest中设置android: exports =“true”。声明此活动的xml文件。

Edit

编辑

<activity
    android:name="com.example.lib.MainActivity"
    android:label="LibMain" 
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" >
        </action>
    </intent-filter>
</activity>

#2


38  

This is only for android studio

So I ran into this problem recently. The issue was in the build/run configuration. Apparently android studio had chosen an activity in my project as the launch activity thus disregarding my choice in the manifest file.

所以我最近遇到了这个问题。问题出现在构建/运行配置中。显然,android studio在我的项目中选择了一个活动作为启动活动,从而忽略了我在清单文件中的选择。

Click on the module name just to the left of the run button and click on "Edit configurations..." Now make sure "Launch default Activity" is selected.

单击run按钮左边的模块名,然后单击“编辑配置…”现在确保选中“启动默认活动”。

The funny thing when I got this error was that I could still launch the app with from the device and it starts with the preferred Activity. But launching from the IDE seemed impossible.

当我犯这个错误时,有趣的是我仍然可以从设备上启动这个应用程序,它从首选的活动开始。但是从IDE中启动似乎是不可能的。

#3


27  

Select your proper configuration for launching Application.

为启动应用程序选择适当的配置。

In my case i found mistake as below image:

在我的案例中,我发现错误如下图所示:

Android . lang。SecurityException:权限拒绝:开始意图

I had just changed like:

我就像:

Android . lang。SecurityException:权限拒绝:开始意图

May it will help to someone, Thanks :)

希望对某人有所帮助,谢谢

#4


4  

Add android:exported="true" in your 'com.example.lib.MainActivity' activity tag.

添加android:在您的com.example.lib中导出="true"。MainActivity标签”活动。

From the android:exported documentation,

从android:导出的文档,

android:exported Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

android:导出该活动是否可以由其他应用程序的组件启动——如果可以,则为“true”;如果不能,则为“false”。如果“false”,则只能由具有相同用户ID的相同应用程序或应用程序的组件启动活动。

From your logcat output, clearly a mismatch in uid is causing the issue. So adding the android:exported="true" should do the trick.

从logcat输出中,显然是uid的不匹配导致了问题。因此,添加android: exports =“true”就可以了。

#5


2  

Similar to Olayinka's answer about the configuration file for ADT: I just had the same issue on IntelliJ's IdeaU v14.

类似于Olayinka关于ADT配置文件的回答:我刚刚在IntelliJ的IdeaU v14上遇到了同样的问题。

I'm working through a tutorial that had me change the starting activity from MyActivity to MyListActivity (Which is a list of MyActivity). I started getting Permissions Denial.

我正在学习一个教程,该教程让我将开始活动从MyActivity更改为MyListActivity (MyListActivity的一个列表)。我开始拒绝权限。

After much trial, toil and pain: In .idea\workspace.xml:

经过大量的尝试,辛苦和痛苦:In .idea\workspace.xml:

...
<configuration default="false" name="MyApp" type="AndroidRunConfigurationType" factoryName="Android Application">
    <module name="MyApp" />
    <option name="ACTIVITY_CLASS" value="com.domain.MyApp.MyActivity" />
    ...
</configuration>
...

I changed the MyActivity to MyListActivity, reloaded the project and I'm off to a rolling start again.

我将MyActivity更改为MyListActivity,重新加载项目,然后又开始滚动了。

Not sure which IDE you are using, but maybe your IDE is overriding or forcing a specific starting activity?

不确定您正在使用哪个IDE,但是您的IDE可能正在重写或强制执行特定的启动活动?

#6


1  

If you are trying to test your app coded in android studio through your android phone, its generally the issue of your phone. Just uncheck all the USB debugging options and toggle the developer options to OFF. Then restart your phone and switch the developer and USB debugging on. You are ready to go!

如果你想通过你的android手机在android studio中测试你的应用程序,它通常是你手机的问题。只需取消所有USB调试选项并将开发人员选项切换到OFF,然后重新启动手机并打开开发人员和USB调试。你准备好出发了!

#7


0  

In my case, this error was due to incorrect paths used to specify intents in my preferences xml file after I renamed the project. For instance, where I had:

在我的例子中,这个错误是由于在我重命名项目后,在我的首选项xml文件中指定意图的路径错误造成的。例如,我有:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:key="pref_edit_recipe_key"
        android:title="Add/Edit Recipe">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.ssimon.olddirectory"
            android:targetClass="com.ssimon.olddirectory.RecipeEditActivity"/>
    </Preference>
</PreferenceScreen> 

I needed the following instead:

我需要的是以下内容:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:key="pref_edit_recipe_key"
        android:title="Add/Edit Recipe">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.ssimon.newdirectory"
            android:targetClass="com.ssimon.newdirectory.RecipeEditActivity"/>
</Preference>

Correcting the path names fixed the problem.

修正路径名修正了问题。

#8


0  

if we make the particular activity as

如果我们使特定的活动为

android:exported="true"

it will be the launching activity. Click on the module name just to the left of the run button and click on "Edit configurations..." Now make sure "Launch default Activity" is selected.

这将是发射活动。单击run按钮左边的模块名,然后单击“编辑配置…”现在确保选中“启动默认活动”。