114

I have created an application containing GWVectraNotifier activity which is called from other applications to display Notification.

In the Notification dialog, there will be 'show' button and 'close' button.

Onclick of 'show' button, the corresponding activity will be started.

To check the functionality of the above application,

I started the GWVectraNotifier activity from K9Mail application on checkmail event trigger.

I am able to start the GWVectraNotifier activity successfully, but onclick of 'show' button i will have to start 'MessageList' activity of K9mail.To do so, i wrote the below code:

Intent i = new Intent();
i.setComponent(new ComponentName("com.fsck.k9", "com.fsck.k9.activity.MessageList"));
i.putExtra("account", accUuid);
i.putExtra("folder", accFolder);
startActivity(i); 

which throws :

WARN/ActivityManager(59): Permission denied: checkComponentPermission() reqUid=10050
WARN/ActivityManager(59): Permission Denial: starting Intent { cmp=com.fsck.k9/.activity.MessageList (has extras) } from ProcessRecord{43f6d7c8 675:com.i10n.notifier/10052} (pid=675, uid=10052) requires null
WARN/System.err(675): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.fsck.k9/.activity.MessageList (has extras) } from ProcessRecord{43f6d7c8 675:com.i10n.notifier/10052} (pid=675, uid=10052) requires null
WARN/System.err(675):     at android.os.Parcel.readException(Parcel.java:1247)
WARN/System.err(675):     at android.os.Parcel.readException(Parcel.java:1235)
WARN/System.err(675):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
WARN/System.err(675):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
WARN/System.err(675):     at android.app.Activity.startActivityForResult(Activity.java:2817)
WARN/System.err(675):     at android.app.Activity.startActivity(Activity.java:2923)
WARN/System.err(675):     at com.i10n.notifier.GWVectraNotifier$2$1.run(GWVectraNotifier.java:63)
WARN/System.err(675):     at android.app.Activity.runOnUiThread(Activity.java:3707)
WARN/System.err(675):     at com.i10n.notifier.GWVectraNotifier$2.onClick(GWVectraNotifier.java:53)
WARN/System.err(675):     at android.view.View.performClick(View.java:2408)
WARN/System.err(675):     at android.view.View$PerformClick.run(View.java:8816)
WARN/System.err(675):     at android.os.Handler.handleCallback(Handler.java:587)
WARN/System.err(675):     at android.os.Handler.dispatchMessage(Handler.java:92)
WARN/System.err(675):     at android.os.Looper.loop(Looper.java:123)
WARN/System.err(675):     at android.app.ActivityThread.main(ActivityThread.java:4627)
WARN/System.err(675):     at java.lang.reflect.Method.invokeNative(Native Method)
WARN/System.err(675):     at java.lang.reflect.Method.invoke(Method.java:521)
WARN/System.err(675):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
WARN/System.err(675):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
WARN/System.err(675):     at dalvik.system.NativeStart.main(Native Method)

Actually i am not able to understand what permissions to include in my Notifier application's manifest file to access MessageList of k9Mail. I am pasting below the permissions included in k9mail application's manifest file:

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.READ_OWNER_DATA"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"/>
<permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"
            android:permissionGroup="android.permission-group.MESSAGES"
            android:protectionLevel="dangerous"
            android:label="@string/read_attachment_label"
            android:description="@string/read_attachment_desc"/>
<uses-permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"/>
<permission android:name="com.fsck.k9.permission.REMOTE_CONTROL"
             android:permissionGroup="android.permission-group.MESSAGES"
             android:protectionLevel="dangerous"
             android:label="@string/remote_control_label"
             android:description="@string/remote_control_desc"/>
<uses-permission android:name="com.fsck.k9.permission.REMOTE_CONTROL"/>
<permission android:name="com.fsck.k9.permission.READ_MESSAGES"
            android:permissionGroup="android.permission-group.MESSAGES"
            android:protectionLevel="normal"
            android:label="@string/read_messages_label"
            android:description="@string/read_messages_desc"/>
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES"/>
<permission android:name="com.fsck.k9.permission.DELETE_MESSAGES"
            android:permissionGroup="android.permission-group.MESSAGES"
            android:protectionLevel="normal"
            android:label="@string/delete_messages_label"
            android:description="@string/read_messages_desc"/>
<uses-permission android:name="com.fsck.k9.permission.DELETE_MESSAGES"/>           

Can some one tell me which permission to include in my app? In the above permissions some are only for k9mail , because those are the permission classes written for k9. So, i will only be able to include the built-in permissions of android in the above given permissions. I tried by doing so as well, but it didn't solve my issue :(

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Swathi EP
  • 3,864
  • 6
  • 26
  • 25
  • I resolved this by adding the following intent filter in the manifest file under the MessageList Activity tag in AndroidManifest.xml: – Swathi EP Feb 03 '11 at 05:30
  • i have added both and android:exported="true" but still i am getting java.lang.security exception ? can you please help me to solve this.. – Charan Pai Oct 01 '12 at 09:51

9 Answers9

157

You have to add android:exported="true" in the manifest file in the activity you are trying to start.

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.

The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".

This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the permission attribute).

Flow
  • 23,572
  • 15
  • 99
  • 156
Prateek Thakur
  • 1,622
  • 1
  • 10
  • 4
  • 3
    Fix half of the problem for me, if you try to install application with the exported service first, then install the main application, you will never succeed to reach to remove service ... the other way works fine nevertheless ... This is because permission required is not present when installing main app, but I don't know how to solve it without removing permissions... – Bibu Jul 09 '14 at 18:38
  • Apparently the app hosting the service has to be installed first. Otherwise, the client won't work. Thanks @Bibu We battled with this issue for a couple of days. – odifek Mar 25 '22 at 12:37
102

The java.lang.SecurityException you are seeing is because you may enter two entries pointing to the same activity. Remove the second one and you should be good to go.

More Explanation

You may be declared the activity 2 times in the manifest with different properties, like :

 <activity android:name=".myclass"> </activity>

and

 <activity android:name=".myclass" android:label="@string/app_name"> 
     <intent-filter> 
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
 </activity>

You should remove the unwanted one from the manifest

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
Jomia
  • 3,414
  • 10
  • 46
  • 63
  • 2
    you may be declared the activity 2 times in the manifest with different properties, like : and . you should remove the unwanted one from the manifest – Jomia Sep 12 '11 at 05:28
  • 1
    Great answer jomia.But one question ,at a time i have only one launcher activity.And same code run with eumlaotr but in device it shows security exception.Can you elaborate please. – Tofeeq Ahmad Nov 30 '11 at 07:27
  • I think you have to uninstall the app in device and re-install it again. Then it will work – Jomia Nov 30 '11 at 12:53
16

In your Manifest file write this before </application >

<activity android:name="com.fsck.k9.activity.MessageList">
   <intent-filter>
      <action android:name="android.intent.action.MAIN">
      </action>
   </intent-filter>
</activity>
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Muhammad Shahab
  • 4,187
  • 4
  • 34
  • 44
8

I had this problem with this exact activity.

You can't start com.fsck.k9.activity.MessageList from an external activity.

I solved it with:

Intent LaunchK9 = getPackageManager().getLaunchIntentForPackage("com.fsck.k9"); this.startActivity(LaunchK9);

Using http://developer.android.com/reference/android/content/pm/PackageManager.html

user1305537
  • 81
  • 1
  • 1
  • Every other answer is about how the receiving app activity should be declared, but this answer gets to the point with how to call implicit intents. Thanks! – shaheer_ Oct 16 '20 at 11:58
6

I was running into the same issue and wanted to avoid adding the intent filter as you described. After some digging, I found an xml attribute android:exported that you should add to the activity you would like to be called.

It is by default set to false if no intent filter added to your activity, but if you do have an intent filter it gets set to true.

here is the documentation http://developer.android.com/guide/topics/manifest/activity-element.html#exported

tl;dr: addandroid:exported="true" to your activity in your AndroidManifest.xml file and avoid adding the intent-filter :)

Jason
  • 86
  • 1
  • 2
1

Make sure that the component has the "exported" flag set to true. Also the component defining the permission should be installed before the component that uses it.

Naren
  • 2,706
  • 1
  • 21
  • 15
  • Also you have to make sure that you have you app in system/priv-app partition to enjoy System level luxury. This is required in KitKat onward devices – Naren Jul 24 '14 at 21:28
1

I solved this exception by changing the target sdk version from 19 onwards kitkat version AndroidManifest.xml.

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
Stephen
  • 9,899
  • 16
  • 90
  • 137
1

It's easy maybe you have error in the configuration.

For Example: Manifest.xml

enter image description here

But in my configuration have for default Activity .Splash

enter image description here

you need check this configuration and the file Manifest.xml

Good Luck

David Hackro
  • 3,652
  • 6
  • 41
  • 61
0

My problem was that I had this: wrong Instead of this: correct

Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69