How to restrict some apps to appear in share chooser? - android

I don't want my app to show in share chooser of certain apps because it's causing some unexpected behaviour in my app. Or in other words, I can say that I only want certain apps to show my app in their share intent chooser. Either way, my objective would be accomplished.
My manifest includes:
<intent-filter android:label="Share with my App">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Moreover, my app has some use cause due to which I've set my launchMode to singleTask
Example of my issue: I want only stores like Amazon, Aliexpress etc. to send share intent to myapp, while I don't want to receive any share intent from say any random notepad text, is it possible to achieve that? if yes then how?

What you want is not possible.
ACTION_SEND has no notion of accepting certain apps while filtering out the others.
It works like a whitelist rather than a blacklist, which means if your app is exposed, it can be seen by all the apps not all the apps minus 1.

Related

How does twitter/facebook know on which apps tweet/status/images can be shared?

My question is when I want to share a tweet on from twitter app when I press the share button a pop up opens and displays all the apps that on which I can share my tweet. How does twitter app knows which apps to display?
This is similar to when an image is opened a pop up comes up and asks for the app we want to view the image in. How does any OS figures out which apps to display.
My guess is that something has to be done with the original application itself.
Attached is an image for reference
In the above screenshot Facebook, Twitter, G+ etc are using Intent Filters.
By defining intent filter you can achieve this. You can register your Android components via intent filters for certain events.If a component does not define one, it can only be called by explicit intents. The key for this registration is that your component registers for the correct action, mime-type and specifies the correct meta-data.
Eg.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
Above code will register an Activity for the Intent which is triggered when someone wants to open a webpage.
Source: http://www.vogella.com/tutorials/AndroidIntent/article.html

Launch a specific android app with NFC

I want to launch a specific android app through a NFC card. I don't want android to ask me which app should be opened. It should instantly open my app. How could I do that?
I already tried it with MIME-Types but it did not work. Could i specify my own MIME-Type? Would it be possible to check the MIME-Type text/plain for a specific text(intent filter?)?
For example: I want my app to start when the NFC card has a specific text stored like "test" or something.
The idea is that it should work on every common mobile OS. Therefore an android application link would not work.
You can create your own application mimeType.
You could create a custom mimeType in your NDEF message and then create an intent-filter which matches it exactly. This would mean your app would be launched as it is the most specific filter.
Example:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.com.my.app.package.customString" />
</intent-filter>
Taken from a previous example I've provided here: https://stackoverflow.com/a/27397938/3312868

Android Intent Filter to receive image files is only working in some apps

I'm experimenting with android development. As an exercise I want to create an app that is able to receive images shared by other apps. I'm testing the app on my phone.
If i share an image in WhatsApp everything works as expected. My app is listed in the share dialogue and the activity is started. But if try to share an image from any other app (e.g. Photos, Album, Gallery) my app is not listed as on of the options.
I'm using a standard Android Studio project and added only the following lines to the manifest.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="ANDROID.INTENT.CATEGORY.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
Why isn't my app listed in the other apps? What do I have to change to make it work?
Android is case-sensitive. By having ANDROID.INTENT.CATEGORY.DEFAULT, you will not match any Intent that is seeking android.intent.category.DEFAULT. Change the case to android.intent.category.DEFAULT, and you will match more activity requests.
In fact, since android.intent.category.DEFAULT is added by default to Intent objects passed to startActivity() or startActivityForResult(), I am not quite certain how your activity worked with WhatsApp...

Make Android app appear in list of default applications?

I have the source code of a 'Phone' app that dials a number and makes a call. How do I make it visible in a list of available applications when a person chooses any 'Phone' shortcut?
I have tried implementing the action intent filters android.intent.action.CALL and android.intent.action.CALL_PRIVILEGED but it only shows my app in the list AFTER I dial a number. In other words, my app gets classified as a Dialer rather than a Phone.
Is there any specific BroadcastReceiver that I need to implement? How do I do that?
I believe this answer is probably what you're looking for. So essentially you'll first need to setup an intent filter on the activity that's going to make the call (in AndroidManifest.xml):
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
This should give your user the option to use your app when placing calls, similarly to how csipsimple works.
well since my comment was what the OP asked for, i replicate it here.
"have you tried CALL_BUTTON (as an intent filter in your manifest) ?"

How to add app to "Share via" list for camera picture on Android

I am building an app that starts when a user takes a picture using their build-in Android camera, then taps the Share button, then chooses my app as the sharer, which is expecting an incoming path to the picture that was just taken, which it uses for processing.
Question: how do I add an option to the "Share via" list that points to my app? Right now there are options like Facebook, Email, Messages, Twitter, Picasa, and I want to add my app w/ an icon.
I'm stuck! And, Google'ing for this is not easy, as "android add to share via list camera" yields a lot of results. I'm building the app with AppInventor (AI), but, AI does not allow developers to edit the Share via list, so maybe this will have to be a separate mini app that just adds to the list...? Hopefully not, because it'd be great to have just 1 app for users to download/install.
Functions like the "share via" in Android work with broadcast intents. The app creates this intent and the system reports all the activities that can execute that (twitter, fb...) You specify what an activity can do by means of intent filters.
In your case I searched for "android camera share intent" and found generally that the intent filter looks like this:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
(not sure about the data section)
I don't know if camera app uses a specific content provider, anyway your app should be able to manage at least the URI scheme that app uses.
I wanted to Share text content and i add the below code in manifest and its works...
<activity android:name=".SendMessage.SendMessageLeads"
android:label="SMS Composer"
android:icon="#drawable/sms_composer">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Categories

Resources