باز کردن recent calls و انتخاب یک شماره برای ارسال sms?
چه گونه می توانم با استفاده از یک کلیک لیسنر به Recent Calls برم و بعد از انتخاب یک شماره sms رو که درون app آماده شده است رو ارسال کنم؟
خیلی ممنون از راهنمایی های شما، اما مساله این هست که با لینک هایی که شما معرفی کردید می تونی اطلاعات Calllog.call رو توی اپ خودت از طریق Cursor درون لیست نمایش بدی. و این کار نیازی به رفتن به خود Calllog.call نیست. اما من می خوام دقیقا مثل کد پایین که برای Contact هست برم درون Calllog و یک آیتم رو Pick کنم. ولی مثل اینکه شدنی نیست!!!!
توضیح: کد اول برای رفتن به Contact و Pick کردن یک آیتم هست که به خوبی عمل می کنه. اما کد دوم برای Calllog.call هست که عمل نمی کنه.(آدرس کد ها : http://developer.android.com/training/basics/intents/result.html)
باز هم ممنون می شم اگه راهنمایی کنید.
staticfinalint PICK_CONTACT_REQUEST =1;// The request code
.
.
.
privatevoid pickContact(){
Intent pickContactIntent =newIntent(Intent.ACTION_PICK,Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE);// Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
دریافت اطلاعات و انجام عملیات رو نتیجه :
@Override
protectedvoid onActivityResult(int requestCode,int resultCode,Intent data){
// Check which request it is that we're responding to
if(requestCode == PICK_CONTACT_REQUEST){
// Make sure the request was successful
if(resultCode == RESULT_OK){
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection ={Phone.NUMBER};
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getContentResolver()
.query(contactUri, projection,null,null,null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
}
}
}
حالا کدی که برای Calllog.call نوشتم و عمل نمی کنه :
staticfinalint PICK_CONTACT_REQUEST =1;// The request code
.
.
.
privatevoid pickContact(){
Intent pickContactIntent =newIntent(Intent.ACTION_PICK,Uri.parse("content://CallLog/Calls"));
pickContactIntent.setType(CallLog.Calls.CONTENT_TYPE);// Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
پردازش نتیجه :
@Override
protectedvoid onActivityResult(int requestCode,int resultCode,Intent data){
// Check which request it is that we're responding to
if(requestCode == PICK_CONTACT_REQUEST){
// Make sure the request was successful
if(resultCode == RESULT_OK){
// Get the URI that points to the selected contact
Uri contactUri =CallLog.Calls.CONTENT_URI;
// We only need the NUMBER column, because there will be only one row in the result
String[] projection ={CallLog.Calls.NUMBER};
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getContentResolver()
.query(contactUri, projection,null,null,null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(CallLog.Calls.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
}
}
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .