Android - Add contacts in 1.5 - android

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.

Related

How to pick images from Gallery instead of Photos in android?

I am using the following code to pick images.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
photoPickerIntent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(photoPickerIntent, getActivity().getResources().getString(R.string.select_picture)), 1);
Its working fine but it only let me to choose images from default Photos application. I want to pick images from "Gallery" application even in today's latest devices. I don't know how WhatsApp is doing this even for Lollipop.
I am using This code in my app and it works fine for me..
intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/* video/*");
startActivityForResult(intent, 3);

Get all services with PackageInfo

I have a problem with an app of mine. I use this code to uninstall a package, fired from a Service:
Uri packageUri = Uri.parse("package:"+packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(uninstallIntent);
The problem is, I've heard from someone who is using this app that there is no uninstall dialog opening on a Sony Xperia Z. It works on my Samsung phones, one with Touchwiz and one with Cyanogenmod and also on my Nexus 7.
I tried to change the intent to:
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
This also works on my devices but not his. Anyone who has an idea why?
Try this:
Intent deleteIntent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("com.the.package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(deleteIntent);
hope it helps

Showing prefilled contact screen to user on android 1.6

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

Open add contact activity android sdk 2.1 and above

i am using the following code to open android defaults add contact activity to add contact in phone.
Intent intentInsert = new Intent(Contacts.Intents.Insert.ACTION);
intentInsert.setData(People.CONTENT_URI);
startActivity(intentInsert);
But its showing deprecated when using in android sdk 2.1 and above.
how to show add contact activity in new contacts contract api.
Thanks
try this
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME,"Name");
i.putExtra(Insert.PHONE,"Number");
startActivity(i);
yes above method got deprecated after 2.1 or above try to use
intentInsert.setData(ContactsContract.CONTENT_URI);
for sdk 2.1 or above

IntentNotFoundException for TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA

I am trying to implement text to speech by following this article on the Android Developers Blog. It suggests the following code for installing text to speech data if it is not supported.
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
This throws an Exception:
ActivityNotFoundException: No activity
found to handle Intent
However, I am using the code here to determine the the intent is actually supported. Here is the list representation:
[ResolveInfo{43cc5280 com.svox.pico.DownloadVoiceData p=0 o=0 m=0x108000}]
Why doesn't this work?
Update
I don't know why, but it seems to work now.
To check whether the intent is actually supported or not, use the following code :
PackageManager pm = getPackageManager();
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
ResolveInfo resolveInfo = pm.resolveActivity( installIntent, PackageManager.MATCH_DEFAULT_ONLY );
if( resolveInfo == null ) {
// Not able to find the activity which should be started for this intent
} else {
startActivity( installIntent );
}
If it is not able to find the activity using resolveActivity() then it means that the activity requires some other parameters which are not provided. In that case, you should get the class name using the queryIntentActivities() and set the intent component/class name.
What version of Android SDK are you aiming at with your code? Remember that TTS is only available from 1.6 (SDK Level 4) onwards. That code works just ok with 2.0 (SDK Level 5).
<uses-sdk android:minSdkVersion="5" />

Categories

Resources