0
當我點擊一個聯繫人,我沒有得到一個電話號碼,我只得到一個聯繫人姓名 ,但沒有號碼。我被提到一個相關的職位,但仍然不滿意,所以 請指導我。選擇一個聯繫人,並獲得電話號碼,並呼叫它
我的代碼如下:
package com.Call_setup;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.widget.ListAdapter;
import android.widget.TextView;
public class Call_setup extends Activity {
/** Called when the activity is first created. */
Intent callIntent;
private ListAdapter mAdapter;
public TextView pbContact;
public static String PBCONTACT;
public static final int ACTIVITY_EDIT=1;
private static final int ACTIVITY_CREATE=0;
private static final int PICK_CONTACT = 0;
private static final int PICK_CONTACT_REQUEST = 2;
String id;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
call();
// onReceive(this,callIntent);
IncomingCallReciever ic = new IncomingCallReciever();
ic.onReceive(getApplicationContext(), callIntent);
}
private void call() {
try {
// Intent callIntent = new Intent(Intent.ACTION_CALL);
/*Intent callIntent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
callIntent.setData(Uri.parse("tel:123456"));
startActivity(callIntent);
// stopService(callIntent);
*/
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
catch (ActivityNotFoundException activityException) {
// Log.e("helloandroid dialing example", "Call failed", e);
}
}
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
ContentResolver cr = getContentResolver();
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(People.Phones.NAME));
String contactId = c.getString(c .getColumnIndex(ContactsContract.Contacts._ID));
// Intent callIntent = new Intent(Intent.ACTION_CALL);
System.out.println("number key is : " + name);
System.out.println("reqCode is : " + reqCode);
System.out.println("resultCode is : " + resultCode);
System.out.println("contactId is :" + contactId);
// String phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
/*callIntent.setData(Uri.parse("tel:"+number));
startActivity(callIntent);*/
}
}
break;
}
}
}
/*public void onReceive(Context context, Intent intent) {
MyPhoneStateListener phoneListener=new MyPhoneStateListener();
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);*/
/* public void onReceive(final Context context, final Intent intent)
{
Log.i("l", "onReceive()");
Log.i("l", "context: " + context);
Log.i("l", "intent: " + intent);
if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))
{
String number = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
Log.i("l", "number: " + number);
}
} */
不工作花花公子 – 2012-03-27 11:33:41