how can we open the android contact activity programatically? - android

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.

Related

Invoke system contact app and retrieve data android

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);

ContactDetailActivity from Lockscreen Activity

I have created a lockscreen widget that starts a custom activity when a click is performed on it. This activity displays a few predefined user selected contact names. When the user click on one of these names, I would like to display contact's information.
Since I have the contact ID when I click on the contact display name, I use an intent to redirect to the builtin ContactDetailActivity by using the following piece of code:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri =
Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId));
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The problem is that I have to unlock the screen to see the contact activity that displays information. I think the problem is due to the fact that I haven't specified flag WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED for ContactDetailActivity, however I cannot figure out how to do nor if it is possible?
Is there a simple mean to achieve my purpose. Otherwise, the last solution I see is to create a custom activity that behaves like ContactDetailActivity so that I can put the WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED flag. However, it seems overkill.
why you don't use QuickContactBadge instead ? here android has good tutorial in how to use it Android Displaying the Quick Contact Badge
Why not dismiss the keyguard when launching the activity with FLAG_DISMISS_KEYGUARD?

How to send email and sms by intent simultaneously in android?

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.

Intent from Android Notepad example

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.

I search, but I don't receive a Intent.ACTION_SEARCH event

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.

Categories

Resources