我是android.i中的新手希望在Android中创建一个应用程序,当我错过了我的手机上的一个电话时,我想发送短信给那个号码。任何人都可以帮助我如何识别来自通话记录的最近未接来电。
答案 0 :(得分:1)
首先,通过内容提供商获取该号码的未接来电。并轻松发送该号码的短信。
请试一试。
public class MainActivity extends Activity {
Button FirstActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] strFields = {android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.NUMBER,android.provider.CallLog.Calls.DATE, android.provider.CallLog.Calls.TYPE
};
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor mCallCursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,strFields, null, null, strOrder);
if (mCallCursor.moveToFirst()) {
do {
boolean missed = mCallCursor.getInt(mCallCursor.getColumnIndex(CallLog.Calls.TYPE)) == CallLog.Calls.MISSED_TYPE;
if (missed) {
String name = mCallCursor.getString(mCallCursor
.getColumnIndex(CallLog.Calls.CACHED_NAME));
String number = mCallCursor.getString(mCallCursor
.getColumnIndex(CallLog.Calls.NUMBER));
// String time = DateFormat.getDateTimeInstance(DateFormat., DateFormat.LONG)
// .format(mCallCursor.getLong(mCallCursor
// .getColumnIndex(CallLog.Calls.DATE)));
//
// Log.d("PhoneLog", "You have a missed call from " + name + " on " + number
// + " at " + time);
}
} while (mCallCursor.moveToNext());
}
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
}
}
答案 1 :(得分:0)
阅读CallLogs如果列值为3则有列名称类型,这意味着错过了呼叫且您的应用需要读取呼叫记录的权限More Details