"Exported activity does not require permission" when attempting to launch from a URI
Asked Answered
E

3

38

I am trying to launch an Android app from a URI using this SO question as a reference.

I have a manifest file with the following declared activity:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" android:host="example.com" />
    </intent-filter>
</activity>

I am attempting to launch MainActivity with the http://example.com link. My issue is that I get the warning

"exported activity does not require permission"

I have looked at other SO questions that report this same warning and all solutions don't seem to work.

How do I write the activity intent-filter correctly to avoid the warning?

Thanks

Energize answered 13/7, 2012 at 1:26 Comment(1)
possible duplicate of Warning: Exported activity does not require permissionBakehouse
H
94

I had the same issue when I updated SDK to version 20. I removed it adding android:exported propery:

<activity 
  android:name=".MainActivity"
  android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" android:host="example.com" />
    </intent-filter>
</activity>

inside the activity declaration in manifest. Of course you may specify this if the activity is intended only for application-internal use

The reason it fixes it is found on docs:

android:exported: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".

Since "Exported receiver does not require permission" (at least the LINT message is clear) ,you got it.

Household answered 17/7, 2012 at 15:40 Comment(4)
I had the same problem when updating the SDK. In my case the warning appeared only for a searchable activityGupton
Thank you for the answer, I have added the "android:exported" attribute to my activity but I had to set it to true, because the intent should be accessible from outside. And now I get the warning "Exported activity does not require permission" again. Does anybody know what is missing if "android:exported" is true?Vintager
I think this answer is wrong. If I set android:exported="false" the choise dialog won't open. To clean the project sloved the problem for me.Chelton
The answer seems also valid for services and receivers.Ocean
F
41

Did you try to clean your project (Project > Clean ...) ? It fixed this warning for my project, maybe yours.

Fineness answered 17/7, 2012 at 14:7 Comment(2)
you are absolutely CORRECT! indeed it did clear lots of messy warnings, these included. "i love the sight of warning-free code in the morning" (d'apres apocalypse now)Marci
Only to make to warning pop-up back again when you compile the project again? That's what happened to me.Indisposed
V
18

To get rid of this warning you have two choices:

  • Either you set the attribute android:exported="false" on the Activity to prevent other Apps from calling your Activity through an intent
  • Or if allowing other Apps to call your Activity is what you want you need to add a android:permission attribute where you can specify which permissions an App needs to have in order to call your activity.
  • If you want to allow other Apps to call your Activity without any special permission it seam you have to get along with having a warning in the Manifest.

You can get further information in the Android Documentation.

Thanks to @furykid for the links.

Vintager answered 27/11, 2012 at 21:45 Comment(1)
I didn't realize that "requires no permission" means I should add "android:permission" to exported service. This is the only answer I found so far. Thanks.Dunaville

© 2022 - 2024 — McMap. All rights reserved.