Open "Add Contact Screen" with names already set - android

I'm trying to open the 'Add Contact' screen via an intent, and I want it with the names already set (first name and family name).
For that, I'm trying to do this:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "My Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONETIC_NAME, "Family Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "12345"));
activity.startActivityForResult(intent, 2);
In this case, the second field in the 'Add Contact' screen keeps empty, and a new field appears with the string "Family Name", that's because I've set the PHONETIC_NAME.
What I want to know is, how do I add the family name value to the second field in 'Add Contact' screen?
I've searched for this question but it doesn't solve. It uses some kind of vCards. I don't know anything about it, if this is the right way to implement this, can someone help me understand how to implement it?

Try this:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "FirstName MiddleName LastName");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "12345");
startActivityForResult(intent, 2);
;) Goodluck

Related

open "Pick a Contact" with a name in the search

i want to open the contact intent with a name already in the search box. can id do that?
if so how?
no i'm calling to the intent like that:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, SELECT_PERSON_REQUEST_CODE);
help any one?
thank you from ahead!
Currently this feature doesn't exists.

android 4.0.3 ACTION_INSERT_OR_EDIT intent not working

When i try to use this Intent like so....
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
startActivityForResult(i,INSERT_CONTACT);
it loads the contact list then after selecting or creating a contact I do not return back to my app. i have checked the logs and nothing stands out. Is there a new intent action in ICS?
Thanks
Your missing this line:
intent.putExtra(ContactsContract.Intents.Insert.NAME, "Larry Page");
Valid "fields":
http://developer.android.com/reference/android/provider/ContactsContract.Intents.Insert.html

Post different text on facebook and twitter using Android intents

I want to enable the user of my android app to post some data on fb,twitter and email it to someone as well. I am using Intent.ACTION_SEND for this. I can add the email subject and add test as Intent.EXTRA_TEXT. But I want different texts to be sent to dirrerent applications.
Like the text to be sent to twitter will be short, the text to be sent to facebook will have a link and a shot description, and the on ein email have all the content.
How can I achieve such a functionality?
At most I can let facebook and twitter take the same text but different from what it is in email.
First, create an Intent representing what you want to potentially e-mail, post twitter, etc. Put some good default values in the Intent.EXTRA_TEXT and the subject. Then call, Intent.createChooser() with your intent. This method will return an Intent representing which Activity the user selected. Now, here's where we add the customization you want. Examine the Intent that is returned like so:
Intent intentYouWantToSend = new Intent(Intent.ACTION_SEND);
intentYouWantToSend.putExtra(Intent.EXTRA_TEXT, "Good default text");
List<ResolveInfo> viableIntents = getPackageManager().queryIntentActivities(
intentYouWantToSend, PackageManager.MATCH_DEFAULT_ONLY);
//Here you'll have to insert code to have the user select from the list of
//resolve info you just received.
//Once you've determined what intent the user wants, store it in selectedIntent
//This details of this is left as an exercise for the implementer. but should be fairly
//trivial
if(isTwitterIntent(selectedIntent)){
selectedIntent.putExtra(Intent.EXTRA_TEXT, "Different text for twitter");
}
else if(isFacebookIntent(selectedIntent)){
selectedIntent.putExtra(Intent.EXTRA_TEXT, "Different text for facebook");
}
startActivity(selectedIntent);
By examining the Intent that is returned by Intent.createChooser, we can determine how we need to modify it before launching it. You'll have to implement the isTwiterIntent and isFacebookIntent function yourself though. I imagine this will be relatively easy though, as you probably just have to examine the context of the Intent. I'll do a little more research and see if I can't find an exact solution for determining if an Intent is for Twitter or Facebook, or whatever and try to give you a more complete answer.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
List<ResolveInfo> activities = getPackageManager().queryIntentActivities(sharingIntent, 0);
By this code you get list of applications that support Intent.ACTION_SEND action.
After that u can built a Alert Dialog to display those applications.
then on click listener of the particular application you can make your changes as given code
public void onClick(DialogInterface dialog, int which)
{
ResolveInfo info = (ResolveInfo) adapter.getItem(which);
if(info.activityInfo.packageName.contains("facebook"))
{
shareToFacebook();
}
else {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "hello");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "intent");
startActivity(sharingIntent);
}
}

Android: Get Installed Shortcuts

I have seen ways to make shortcuts, but I need to find a way to get a list of shortcuts installed on the phone.
I want my user to be able to select one of his/her shortcuts and launch it from my application. Is there a way to do this (an API) or will I need a reflection method to call a system service?
Here is how it is done in the Launcher...
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
List<ResolveInfo> shortcuts = getPackageManager().queryIntentActivities(shortcutsIntent, 0);
The shortcuts are private to Launcher. There is no API, and anything you try to do will be very fragile as different launcher implementations (and versions) will have different storage structures.
In addition to Jonathan,
Each app can do shortcuts. Each shortcut specified in app's manifest. So you can get shortcuts list (this method in activity):
Kotlin
fun printShortcuts() {
val shortcutIntent = Intent(Intent.ACTION_CREATE_SHORTCUT)
val shortcuts = packageManager.queryIntentActivities(shortcutIntent, 0)
shortcuts.forEach {
println("name = ${it.activityInfo.name}, label = ${it.loadLabel(packageManager)}")
}
}
It will print something like:
I/System.out: name = com.whatsapp.camera.CameraActivity, label = WhatsApp Camera
I/System.out: name = com.android.contacts.ContactShortcut, label = Contact
I/System.out: name = alias.DialShortcut, label = Direct dial
I/System.out: name = alias.MessageShortcut, label = Direct message
I'm trying to do the same and there a lot of things not clear about this topic, at least not clear to me...........An example is Openapp market that create shortcuts everytime you "download" an app, but the shortcuts it is actually only a link to an html page. Anyway i have 2 android phones and in the firstone is working in the second one is not creating any shortcuts.......
in may app i do the following:
Intent shortcutIntent = new Intent(this,FinestraPrincipaleActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
this.sendBroadcast(addIntent);
But someone told me that the is wrong but i didn't find anyother way to create shortcuts....

Access contacts filters

The contacts on the android phone come with settings like "Filter Contacts" that lets the user set things like "Show only contacts that have phone numbers" and "Only show contacts that are online", and which sets of contacts to display (eg, phone only, phone and google etc.).
When doing this
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
is there any way to get those filters applied to the contacts list? By default it seems to return everything. If you can't, is there some way to access those settings to see what they are, so I can build my own contacts picker list to match how the phone user has set their default? This only needs to work for Android 2 up.
(The ideal option would be a way to invoke the contact picker that lets the user also set the filters from in there.)
I think if you pass a URI to the intent like the one shown here, you should be able to apply your filter. So you'd do something like this:
Intent intent = new Intent(Intent.ACTION_PICK, PhoneLookup.CONTENT_FILTER_URI);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);

Categories

Resources