From my understanding, if an intent is invoked implicitly, android matches the intent object's contents against all intent filters in the following order: component, action, data and category, filtering out non-matching intents at each step. At this point if there are multiple intents filtered out, then it brings up the activity chooser.
Is there a way by which I can trap the final filtered result and do further filtering based on Extras and Flags? Would ResolveInfo be of any help to me in this case?
In effect, I want to process my custom logic before android brings up the Activity chooser.
Can someone please point me in the right direction, maybe a place in the android source code which helps me to do the above?!
Thanks a lot!
If you are the one calling startActivity(), you can use PackageManager and queryIntentActivities() to find out what the chooser would wind up showing. You can then roll your own chooser if you, er, choose.
If you are trying to intercept the starting of any and all activities on the device, this is not possible.
Related
I have an Activity and assume that has been launched. When the other application use startActivity method to start my Activity, my Activity will show and run the onResume Method, but I can't find any way to get the intent which is used in startActivity method by the other application. I want to get the extra data in the intent. How can I do?
EDIT
My Activity is singleTask, and I want to get the startActivity intents form other applications. I think it is not associate with filters.
Have you tried using getIntent() ?
Then you can do:
this.getIntent().getExtras();
After that if you need new intents just override the onNewIntent function in your activity.
I simply say an example. When we need to share something. We click share button which shows a list of app by which we can share our things.
So, if you want to make that kind of app which can receive other app data then you need make your activity capable of receiving that data. In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter in manifest.
Below this link you will get some more information : http://developer.android.com/training/basics/intents/filters.html
I've read the following for Android Intents:
Think of Intents as a verb and object; a description of what you want done –
E.g. VIEW, CALL, PLAY etc.
I am not able to understand this sentence. Can anyone please explain me this? I know that An Intent is an abstract description of an operation to be performed.
I will try and explain. You use an Intent when you want a particular activity in your application to do something. The action that you want to perform is specified as the Intent itself (Like play music, call someone, take a photo). Verbs are something which represent any action. Intents also represent actions that you app will do with the help of activities and intents.
Also intents always need an object to perform the desired action which is an argument in the Intent. Hence the destination class object in the Intent is the is description (it contains all the detailed methods of the operation to be performed).
Hope it helps!!!
Intent transport infomation between 2 Activity, amagine it's like a transporter send mail, gift, information... between you and I.
So, I want to send you a PhoneNumber and I need you call this number. So the transporter need your name, address,... (--> It's like setClassName() in Intent) and action i want you do (--> like ACTION in Intent). After that, the transporter will send infomation to you and you will call the phonenumber for me.
can anybody tell what is capablity of component in android.I know intent filter is capablity of component.can anybody explain what is that?
thanks
An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity).
action: android.intent.action.PICK
data: content://com.google.provider.NotePad/notes
Asks the activity to display a list of the notes under content://com.google.provider.NotePad/notes. The user can then pick a note from the list, and the activity will return the URI for that item back to the activity that started the NoteList activity.
action: android.intent.action.GET_CONTENT
data type: vnd.android.cursor.item/vnd.google.note
Asks the activity to supply a single item of Note Pad data.
The above is directly from Android Notepad example.
My question is, why have they defined two intent actions that perform the same task?? When will one or the other action be performed?
Also in the code, they have defined
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
Could someone please clarify, when will an action be set and on ListItemClick how will getAction resolve to either ACTION_PICK or ACTION_GET_CONTENT
Thanks in advance
My question is, why have they defined two intent actions that perform the same task?
They are not the same task. Quoting the documentation for ACTION_GET_CONTENT:
This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browser over the web and download the desired data, etc.
When will one or the other action be performed?
When somebody calls startActivity() with an Intent containing one of those two actions, plus a content Uri pointing to this application (in this case).
Could someone please clarify, when will an action be set
It is set in the Intent used with the startActivity() call that was used to start the activity.
how will getAction resolve to either ACTION_PICK or ACTION_GET_CONTENT
By executing the code you included in your question.
Is there a way to know which Intent Filter is responsible for launching an Activity which has two Intent Filters defined in AndroidManifest.xml? I want a slightly different set of logic, but not enough that should require a whole new Activity.
Thanks!
Never mind, found it. Just wasn't looking hard enough...
Using this.getIntent().getAction() in your Activity will spit out exactly what I was looking for, a String to identify which Intent Filter Action opened it.