Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create an intent filter based on query?

I would like to have my application respond to the market link for my application. So the link is market://details?id=my.package.name. Now the reason I want this is so I can send out a link that will open the app if it is installed and open the market page if the application is not installed. The problem I am running into is that my application will respond to all market links and not just my applications link. The reason is the package name is defined in the query part of the Uri. Is there a way to filter an intent based on the query part of the Uri?

like image 565
Bobbake4 Avatar asked May 02 '12 16:05

Bobbake4


People also ask

Can an activity have multiple intent filters?

To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters.

What is intent filters explain intent filters with example?

Implicit intent uses the intent filter to serve the user request. The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond. Intent filters are declared in the Android manifest file. Intent filter must contain <action>

What is the difference between intent and intent filters?

An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.

How does intent filter work?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.


2 Answers

From Android API 19, you can do it, using ssp, sspPrefix or sspPattern. Example:

<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="https"
        android:sspPrefix="//play.google.com/store/apps/details?id=com.example.test"
    />
</intent-filter>

With such filter, the OS will offer your app only for URLs with id=com.example.test parameter, and won't offer it when there is no such parameter. But this works only on Android 4.4+, older versions will ignore sspPrefix.

See also this article: https://chris.orr.me.uk/android-ssp-data-intent-filter/.

like image 131
some.birdie Avatar answered Oct 26 '22 03:10

some.birdie


No, sorry, you cannot. You can constrain a filter based on everything to the left of the ?, but that's it.

like image 35
CommonsWare Avatar answered Oct 26 '22 04:10

CommonsWare