I'm trying to implement a search fonctionality in my android app. With my app :
I click on the standard search button.
I
see the standard search dialog with
my icon app.
I see my list of suggests items app
when I type something in the search
field.
When I choose a suggest, something
call the onNewIntent of my standard
activity, but the intent is
*Intent.ACTION_VIEW*, not
*Intent.ACTION_SEARCH*, as I hope ??
I'm losted If it's ok to receive ACTION_VIEW, how I retreive the item searched ? If it's not ok, why ?
If it is the Intent.ACTION_VIEW, you can retrieve the data by using
intent.getData()
which will return a URI that you can parse.
Related
I want to share a text using this:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
As you can see in the below picture, I know how to acheive a dialog which lets user picks his choice (My app). But recently I saw an app which is letting users pick their choice within its activity (Desired).
Any idea how to acheive desired one? Thank you all.
This is the code, I've been using for sharing 'Referral Code' from within my app:
ShareCompat.IntentBuilder
.from(this) // getActivity() or activity field if within Fragment
.setText("message") // This will be populated as user's message
.setType("text/plain") // most general text sharing MIME type
.setChooserTitle("Share code using:")
.startChooser();
It opens up a view similar to your right image.
Create Custom layout. (Right image)
Embed in BottomSheetLayout
Use setState() to show your "Share Screen"
................................................
or You can just do the same inside an AlertDialog. (Left Image)
You can query for the list of apps that are registered to handle the action and then display the result in the way that you like the most. When the user will choose something you can start the selected activity.
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 have created Intent chooser for my application. I want to send email and sms by this. My code is here http://pastie.org/8966227 . But I can get the result properly. The control always comes into second loop only. Any body can help me? thanks in advance.
You can't check which intent has user selected.
Unless you create your own implementation of the dialog for the activity selection.
To create such dialog you need to use PackageManager and its queryIntentActivities() function. The function returns List.
More information is available here and here.
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.
Can you please tell me how can i open the android inbuilt View Contact Activity
Programatically.
I am having a list of contacts in my activity and i want to show the contact details on the selection of list Item, so i basically want to know to which android activity i should send the intent in order to open that activity.
Thanks in Advance.
Use the ACTION_VIEW action in your intent, with the content://contacts/people/1 URI (see javadoc of Intent for more details)
If you want to reach Contacts in Android, you probably want to read on in the Contacts class.