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.
Related
I fell confused about the relationship between the Activity, Action and Intent?
And also an another question about the Implicit intents : for example I want to start this action ACTION_CALL to make a phone call,obviously, this is an Implicit intent, so I should write like this Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
But I should also need to set the data. Here is my question : How can I know what's the uri looks like? What's the schema?Please just don't tell the simple answer.How do you know that? Is there any API I should look for? And I know in the manifest <data android:scheme="xxxxx"/> So where is the manifest about the action or activity Intent.ACTION_CALL? I can't find it.
Activity - It says, from where to where you want to send message e.g: from Activity A to Activity B.
Action - It says, what this message means e.g: Open a URL in webview or make a call etc.
Intent - It says, how to transfer the message and other extra information e.g: directly through explicit intent or indirectly by selecting from multiple options through implicit intent.
Im developing an application where in I have 2 text views and a button.
when I click the button, it should open default system contacts application and upon selecting a contact, it should display the name and number in the text fields respectively.
Now I have implemented ContactsContract and getContentResolver. But, I have seen other apps having this feature, which is quite easy because you need not create a list view and stuffs.
Now how do I start? how do I invoke default contact app and retrieve data from it.
I don't know the details about your problem, but I am pretty sure that you need to use an Implicit Intent (because the Contacts app may be different on different devices). Hopefully this page will help.
You may need to start by using this code:
Intent i = new Intent(); // Declare intent
// Start the intent
startActivity(i);
You may want to use ACTION_GET_CONTENT.
Thanks for the replies. I found out that this is what i need.
Intent localIntent = new Intent("android.intent.action.PICK",ContactsContract.Contacts.CONTENT_URI);
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.
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.
I want to use ActivityGroup to run two activities, but the catch is that those are not necessarily Activities I wrote, for example, I may want to open a contact picker or something that was part of the system. Is this possible? Using the ndk maybe?
EDIT: I want to run both activities on-screen at the same time.
I'm not sure that i understood your question. But if you want to start an activity from another one, you can simply use:
this.startActivity(new Intent(String intent));
Were the parameter of Intent should be the component name of a registered activity, the action or a specific class of your application that you want to start.
i.e. to open a contact detail:
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, ""+contactId)));
take a look here to have a deep view on intent