Android - java.lang.SecurityException: Permission Denial: starting Intent
Asked Answered
F

14

120

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

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'.

I have tried all suggestions made on stackoverflow (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.

Here's the logcat output:

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:

<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.

Fao answered 7/11, 2013 at 6:38 Comment(2)
Also tried: project> Java Build Path> Order and Export> put tick on the jar file> Project Clean - Same error while opening the intent.Fao
https://mcmap.net/q/182869/-android-java-lang-securityexception-permission-denial-start-intent can help hereInterconnect
T
251

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

<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>
Twiddle answered 7/11, 2013 at 6:54 Comment(13)
Tried this. I added android:exported="true" in the project manifest.xml file under <activity android:name="com.example.lib.MainActivity". Gives me the same error.Fao
remove intent-filter and try again.Twiddle
Activity in Manifest now loks like this: <activity "com.example.lib.MainActivity" android:label="LibMain" android:exported="true"> </activity> Still same errorFao
try it.setComponent(new ComponentName("com.example.lib", "com.example.lib.MainActivity"));instead of it.setClassNameTwiddle
it.setComponent(new ComponentName("com.example.lib", "com.example.lib.MainActivity")); -- Same Error.Fao
last try. If you are using jar and it is on your build path then your MainActivity in jar file will run in your app process. So you can try with final Intent it = new Intent(this, com.example.lib.MainActivity); startActivity(it);Twiddle
..new Intent(this, com.example.lib.MainActivity); did not help either. I made some changes to manifest.xml and it started working on AVD, but on a device it still throws the same 'SecurityException: Permission Denial' error. I have done multiple uninstall/ re-installs with no luck. Not sure why it would work on AVD and not on a device.Fao
Activities are automatically exported if they contain an intent filter, so you would not not need to set that explicitly as long as you leave the intent filter in.Newscast
That works for me. When I use AVD, I don't need to set the exported=true, but when I use real device, it will throw out the SecurityException.Brynn
android:exported="true" solved the problem for me tooRawson
exporting your activity means it can be exposed to other apps. Beware of doing this. Instead, try to generify your intentsReproduction
how can we avoid this when executing with Appium?Dispersoid
In my case, it looks like it might be device related. I have an LGL322DL/Android 10 and the app works fine but on my Samsung SM-S727VL Android 6.0.1 i get an exception "java.lang.SecurityException: Permission Denial: starting Intent...(pid=27545, uid=10185) not exported from uid 1001". I do have android:exported="true". The old LGE running Android 4.4 can't find the app I want to start but no exception.Dingy
I
43

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.

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.

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.

Interphone answered 8/4, 2014 at 6:21 Comment(2)
thnx brother...it worked...sometime small problems became big...but i learnt something called android:export = true..thnxAllegory
Gah, I ran into this too (after the cat had been sleeping on the keyboard). Took forever to track down the issue. The cat was easy to track down though.Introit
W
27

Select your proper configuration for launching Application.

In my case i found mistake as below image:

enter image description here

I had just changed like:

enter image description here

May it will help to someone, Thanks :)

Woodman answered 23/2, 2015 at 7:42 Comment(0)
N
9

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

From the android:exported documentation,

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.

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

Nelia answered 15/4, 2016 at 12:33 Comment(0)
I
4

I was facing this issue on a react-native project and it came after adding a splash screen activity and making it the launcher activity.

This is the change i made in my android manifest XML file on the MainActivity configuration.

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"/>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

I added the android:exported=true and the activity configuration looked like this.

 <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"/>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
   
Illuminating answered 1/12, 2019 at 11:12 Comment(0)
F
2

Similar to Olayinka's answer about the configuration file for ADT: I just had the same issue on IntelliJ's 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.

After much trial, toil and pain: 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.

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

Flatfooted answered 20/11, 2014 at 18:42 Comment(0)
A
2

android:exported="true" this line add in your first opening activity

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="org.triad.hp">
    
        <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE"
            android:required="false"   tools:node="remove" />
        <uses-permission
            android:name="android.permission.READ_EXTERNAL_STORAGE"
            android:required="false" tools:node="remove" />
        <uses-permission
            android:name="android.permission.READ_SMS"
            android:required="false" tools:node="remove" />
        <uses-permission
            android:name="android.permission.RECEIVE_SMS"
            android:required="false" tools:node="remove" />
    
        <uses-permission android:name="android.permission.INTERNET"/>
    
        <uses-permission android:name="com.hp.kiosk.data.PERMISSION"/>
    
        <application
            android:hardwareAccelerated="true"
            android:usesCleartextTraffic="false"
            android:name=".App"
            android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
            android:icon="@drawable/logo"
            android:allowBackup="false"
            android:label="@string/app_name"
            android:roundIcon="@drawable/logo"
            android:debuggable="false"
            android:theme="@style/AppTheme"
            tools:ignore="HardcodedDebugMode">
            <activity
                android:protectionLevel="signature"
                android:screenOrientation="landscape"
                android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
                android:name=".activities.PaymentActivity"
                tools:ignore="LockedOrientationActivity"
                android:exported="true">
                <intent-filter>
                    <action android:name="org.triad.hp.activities.PaymentActivity" />
                     <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
    
            <activity
                android:screenOrientation="landscape"
                android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
                android:name=".activities.MainActivity"
                tools:ignore="LockedOrientationActivity"
                android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                     <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <activity
                android:exported="false"
                tools:replace="android:screenOrientation"
                android:screenOrientation="landscape"
                 android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
                 android:name="com.paytm.pgsdk.PaytmPGActivity"
                tools:ignore="HardcodedDebugMode,LockedOrientationActivity" />
        </application>
    
    </manifest>
Acciaccatura answered 7/4, 2022 at 5:23 Comment(0)
R
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!

Ransack answered 4/3, 2016 at 12:18 Comment(0)
H
1

In the case you are trying to open a webpage and you get the permission denial error with a crash. You need to make the intent browsable by adding.

intent.addCategory(Intent.CATEGORY_BROWSABLE)
Headed answered 3/9, 2023 at 1:46 Comment(0)
E
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:

<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.

Encumbrance answered 2/10, 2015 at 19:29 Comment(1)
To the person(s) who subtracted points: please explain what the issue is that led you to do that. My example worked in my case. This answer is quite old. If it's obsolete, I'll remove it.Encumbrance
T
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.

Todd answered 4/4, 2016 at 15:31 Comment(0)
G
0

Another reason for this error would be that you have a debug and release version(or different flavors) installed on the same device/emulator. This might also explain the behavior some note here where they install through android studio or not and then have it work or not.

Giraudoux answered 30/5, 2023 at 11:5 Comment(0)
R
0

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"/>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"/>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
Resonator answered 14/11, 2023 at 14:29 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Coil
W
-1

AppActivity of any app which does not contain .SplashActivity at the end will throw this type of permisssion error. Make sure that AppActivity contain .SplashActivity at the end. If .SplashActivity is not present then it means app is not allowing for mobile automating

Wartburg answered 26/5, 2021 at 16:37 Comment(1)
Hi. Welcome to StackOverflow. Could you please make it clearer what your question is?Rubescent

© 2022 - 2024 — McMap. All rights reserved.