6

I want to know if it is possible to read the value of android:scheme from the Android-manifest-file (example below) programmatically.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="zxtest" />
</intent-filter>
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

2

You should be able to get this information from the PackageManager:

PackageManager pm = getPackageManager();
ActivityInfo activityInfo = pm.getActivityInfo(component,
        PackageManager.GET_INTENT_FILTERS);

Unfortunately, however, you can't :-( This call SHOULD return the intent filters (according to the documentation), but it seems that the Android developers haven't gotten around to actually implementing it yet :-(

See Unable to get intent filters from a package

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • What method on `activityInfo` gives me the name of the URL scheme? – jab Jul 22 '14 at 14:53
  • 1
    Oh, sorry :-( That call SHOULD return the intent filters (according to the documentation), but it seems that the Android developers haven't gotten around to actually implementing it yet :-( See http://stackoverflow.com/questions/18739243/unable-to-get-intent-filters-from-a-package – David Wasser Jul 22 '14 at 15:45
  • I downvoted because the above comment belongs in the answer itself. I'll upvote if you put your comment into the answer. – Heath Borders Apr 03 '20 at 15:15
0

I'm assuming you mean that the intent has been called and you're trying to find the scheme from your activity's code?

In your activity's onCreate method, you can do the following:

Intent intent = getIntent();
Uri data = intent.getData();
String scheme = data.getScheme(); // "zxtest"
Danation
  • 743
  • 8
  • 20
  • 1
    Hi, well, yes and know. I want to get the information before the intent was called. Is this possible? – Sascha Möllering Feb 01 '13 at 11:28
  • @SaschaMöllering Ah, I see. Are you trying to read values from your own app's manifest or values from another app's manifest? Also, what problem are you trying to solve? – Danation Feb 01 '13 at 16:50
  • I'm trying to read the values from my own app's manifest. The problem is that I want to know the value of android:scheme, because I want to send this to a website. – Sascha Möllering Feb 03 '13 at 20:37
  • I'm not fully understanding. If it's already in your app's manifest, you already know what the value is, right? Why do you need to read it? Could you explain in more detail what you're trying to do? – Danation Feb 15 '13 at 20:41
  • Because I have to programmatically send this value to a website. – Sascha Möllering Feb 18 '13 at 12:35
  • Again, I think more detail is required. In detail, please describe what problem you are actually trying to solve. Right now, it seems like since the value is essentially hard coded into your manifest, there shouldn't be a problem hard coding it into your code. – Danation Feb 19 '13 at 17:18