Sunday, 8 February 2015

Android Development Tips: Invoking different Android system Activity / Apps 1 (Phone / Dialing related)


When developing Android application, we always need to invoke other system applcation (e.g. contact, phone dialer, camera,etc) In this post, I will summarize some method to invoke different phone and dialing related system activity.
1. Start the phone dialer
Intent intent =new Intent();  
intent.setAction("android.intent.action.CALL_BUTTON");  
startActivity(intent);  
OR
Uri uri = Uri.parse("tel:xxxxxx");   
Intent intent = new Intent(Intent.ACTION_DIAL, uri);     
startActivity(intent); 
2. Go to Dialer Applciation
Intent intent= new Intent("android.intent.action.DIAL");   
intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");  
3. Open Phone Contacts List
Intent intent = new Intent();   
intent.setAction(Intent.ACTION_VIEW);   
intent.setData(Contacts.People.CONTENT_URI);   
startActivity(intent);   
4. Pick a Phone Contact
Intent intent = new Intent();   
intent.setAction(Intent.ACTION_PICK);   
intent.setData(Contacts.People.CONTENT_URI);   
startActivity(intent);   
5. Edit a phone contact
Intent intent=new Intent(Intent.ACTION_EDIT,Uri.parse("content://com.android.contacts/contacts/"+"1"));  
startActivity(intent);  
6. Add a new phone contact
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);  
            intent.setType("vnd.android.cursor.item/person");  
            intent.setType("vnd.android.cursor.item/contact");  
            intent.setType("vnd.android.cursor.item/raw_contact");  
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, name);  
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.COMPANY,company);  
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, tel);  
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE_TYPE, 3);  
7. Invoke send SMS and MMS UI
Intent intent = new Intent(Intent.ACTION_VIEW);  
                intent.setType("vnd.android-dir/mms-sms");  
                startActivity(intent);  

0 comments:

Post a Comment