Showing prefilled contact screen to user on android 1.6 - android

I have got following project requirment.
When user has given android.permission.WRITE_CONTACTSpermission in his manifest then we should add contact programatically. ( This part is done and working perfectly).
Now the challenge is If user has not given this permission then i will not able to add contact programatically but the best effort i want to put is show him prefilled contact screen and let him press add button.
I got this working on Android 2.0 and up.But I am facing issue to make it work on android 1.6 device.
Below is the code which works on Android 2.0 and up.
Intent i = new Intent(ContactsContract.Intents.Insert.ACTION,
ContactsContract.Contacts.CONTENT_URI);
i.putExtra(ContactsContract.Intents.Insert.NAME, "Vipul Shah");
i.putExtra(ContactsContract.Intents.Insert.PHONE, "1234");
startActivity(i);
Any help will be highly appreciated.
Thanks

This is because ContactsContract is only present in API5+ (Android 2.0) environments.
The relevant class in pre-API5 is called Contacts
if (android.os.Build.VERSION.SDK_INT > 5)
Intent i = new Intent(ContactsContract.Intents.Insert.ACTION,
ContactsContract.Contacts.CONTENT_URI);
i.putExtra(ContactsContract.Intents.Insert.NAME, "Vipul Shah");
i.putExtra(ContactsContract.Intents.Insert.PHONE, "1234");
startActivity(i);
} else {
Intent i = new Intent(Contacts.Intents.Insert.ACTION,
People.CONTENT_URI);
i.putExtra(Contacts.Intents.Insert.NAME, "Vipul Shah");
i.putExtra(Contacts.Intents.Insert.PHONE, "1234");
startActivity(i);
}

Related

How to WhatsApp Call without saving number manually

I am trying to write a code to whatsapp call a mobile number, without saving it to the phonebook.
I have written the code as:
Intent callIntent = new Intent("android.intent.action.MAIN");
callIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
callIntent.putExtra("jid", "19876543210#s.whatsapp.net");//phone number without "+" prefix
callIntent.putExtra(Intent.EXTRA_TEXT, "voip-call");
callIntent.putExtra("call", true);
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setPackage("com.whatsapp");
startActivity(callIntent);
But it is not working.
Any sort of help would be beneficial for my learning.

pick contact item in intent

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
// intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
I am working on an application that helps the user to share his/her any accessible item(file) in the device. Codes above help user to select file(s) in the device. It is perfect! But I also want to give an opportunity to users as sharing their contacts(full contact details) with others by using my app. I tried intent.putExtras() but it supported in Build.VERSION.SDK_INT >= 19 devices (my app's min SDK is 17). It seems contact pick action requires different kind of intent type rather than "*/*". So, how merge these types of intents together? What can I do to solve the problem?
p.s I added following line to the manifest:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Brandon Zamudio marked the question as possible duplicate of this question but I can explain why it is not. In original question Hardik Trivedi wanted to pick contacts using intent. But in my case I want to give some different options to user to select. So, my problem should not be same with the original question. I did not share some pieces of my codes, but it is different one. Thanks for attention.
Actually, I wrote almost same codes approximately 2 years ago. In two days I searched for these lines. Fortunately I found them in my second Hello World! application. :)
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // for Camera app
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE); // not necessary, but recommended
Intent contacts = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
contacts.setType(ContactsContract.Contacts.CONTENT_TYPE);
Intent chooserIntent = createChooser(intent, "Select item");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{ takePicture, contacts });
startActivityForResult(chooserIntent, CHOOSE_FILE_RESULT_CODE);

Open a specific application settings screen on Android?

I trying to figure out the intent values to open a specific application settings screen on Android, the one that allows you to "Clear Data", "Force Stop", "Uninstall"...
Thanks,
Adam.
CommonsWare have answered the question. Here is code you can copy/paste directly and use:
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
Use ACTION_APPLICATION_DETAILS_SETTINGS, with a Uri of package:the.app.goes.moo (replacing the package name with the one you want).
Note that this is new to API Level 9, and it might not work on every device.

Android - Add contacts in 1.5

I'm making my application compatible with Android 1.5 (APLI level 3) from 2.3.3. The only thing I have to change (according to the compiler) is the code used to add a contact in the phonebook. The code for 2.3.3 is the following:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "Name");
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "Email");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "phone");
int PICK_CONTACT = 100;
startActivityForResult(intent, PICK_CONTACT);
The problem with 1.5 is that ContactsContract is not recognized.
How can I convert this code for 1.5?
Regards.

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

Categories

Resources