我是 android 的新手。我希望在 android 中创建一个应用程序,当我错过手机上的电话时,我想向该号码发送一条短信。任何人都可以帮助我如何从通话记录中识别最近未接来电。
问问题
2847 次
2 回答
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);
}
}
于 2013-03-11T12:39:00.670 回答
0
Read CallLogs 存在列名类型,如果值为 3,则表示未接来电,您的应用需要读取通话记录的权限更多详情
于 2013-03-11T12:21:20.967 回答