2013年5月18日 星期六
get number(uri) from contact & call someone 打電話
package com.example.calltest;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int PICK_CONTACT_REQUEST = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pickContact();
}
private void pickContact() {
Intent pickContactIntent = new Intent( Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI );
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
@Override
public void onActivityResult( int requestCode, int resultCode, Intent intent ) {
super.onActivityResult( requestCode, resultCode, intent );
if ( requestCode == PICK_CONTACT_REQUEST ) {
if ( resultCode == RESULT_OK ) {
Uri pickedPhoneNumber = intent.getData();
// handle the picked phone number in here.
Toast.makeText(getApplicationContext(), pickedPhoneNumber+"",Toast.LENGTH_SHORT).show();
Uri number = Uri.parse(pickedPhoneNumber.toString());
Intent dial = new Intent(Intent.ACTION_CALL, number);
startActivity(dial);
}
}
}
}
------------------------------------------------------------------------------------
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言