Make Android app appear in list of default applications? - android

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) ?"

Related

How to restrict some apps to appear in share chooser?

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.

SingleTask activity, but opened through two different applications

This image was quite helpful for understanding the
functionality offered by the launhmode singleTask, taken from here
however, I understood this in case of the same application, I am having issues understanding
what if both tasks belong to two different Applications
Confusing Scenario(fictional),
I was going through an app and the app offered an action to send
emails, I selected 'send email' option.
My phone's default 'email app' will be picked and its activity (which is
declared as singletask) will be opened.
While I was typing my email content, I switched to some chat app and
the app gets crashed and offered me an option to report an issue
over email to the developer, Now when I will select 'Report' , my email
app(which is the same default email app ) will be opened.
Now as the Email app's root activity is singletask, will my content
which I wrote will be visible to me?
The main thing is this time, the tasks/stacks belong to two different apps.
Even though you are using 2 different applications, it will work in the expected way:
if your singleTask activity already exists, that copy will be used, with the method onNewIntent() being called
if it does not exist, it will be launched as per normal
More technically, reproducing the definition from your link:
The system creates a new task and instantiates the activity at the
root of the new task. However, if an instance of the activity already
exists in a separate task, the system routes the intent to the
existing instance through a call to its onNewIntent() method, rather
than creating a new instance. Only one instance of the activity can
exist at a time.
This can easily be verified by making an activity a target for sharing text and singleTask in the manifest:
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
Now add some logging to the onCreate() and onNewIntent() methods and do some scenario testing.
Something I found particularly useful when testing the various launchmodes is the following ADB command:
adb dumpsys activity activities
This outputs a lot of text (it may help to reboot the phone before doing this - adb reboot) showing details of the activity task stacks. This can be used to show you that your singleTask activity "rehomes" itself as it gets launched via different applications.
As for the question about the emails, I think that will depend on which email client you are using, but I would hope that they handle the onNewIntent() method correctly, and save the current draft before displaying your new email.

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...

Possible to bypass Android Intent Filter?

In my app I have an intent filter set to match certain types of links if clicked in a web browser or other field. It currently looks like this:
<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:host="www.mydomain.com"
android:scheme="http" />
<data
android:host="mydomain.com"
android:scheme="http" />
<data
android:host="m.mydomain.com"
android:scheme="http" />
</intent-filter>
This works well. If you click a link say http://www.mydomain.com/article_name then the user gets the option of opening the article in the app and I can show the content uniquely. Here's the question - in the app I want to provide an option for the user to still break out and "Open in Browser". Yet if I do this and just try to fire off an intent to launch the browser, my app catches the link again and we go around in a circle.
How can I specifically force a link to be opened in the browser?
I believe you can use the answers provided in this thread to achieve your end. Basically, when you go to launch the "open in browser" intent, you can preview the activities that will be able to open it. From there, you can select one that isn't your app and set that as the package on the intent, which will cause the other app to open it.
At worst, you could force the creation of the chooser which would contain both your app and the other apps that can open your site, enabling the user to pick the browser.
This other question might also be useful, as its answers contain an implementation of a custom chooser which apparently allows you to filter the visible activities, so you could remove your app.
I don't know any way to bypass Android Intent Filter.
If user uses Android default Browser or Chrome, you should use the way in following link to open an Intent specifically.
https://developers.google.com/chrome/mobile/docs/intents

Categories

Resources