0
我有此代碼可以接收來電號碼並在副本中進行查詢TelephonyManager.CALL_STATE_RINGING
我已經獲得來電號碼,但是當我想在側面查詢應用會給我的情況時的錯誤,我不知道爲什麼任何一個可以幫助我,請解決問題獲取來電號碼並進行查詢 - Android
這是我的代碼
public class IncomingCallReciever extends BroadcastReceiver {
protected static final String TAG = "SWAJ";
private Context mContext;
private Intent mIntent;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG ," onCallStateChanged ");
mContext = context;
mIntent = intent;
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
tm.listen(phoneStateListener, events);
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
SilentMeDB databaseHelper = new SilentMeDB(mContext);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor c = db.query("events",null,null, null, null, null, null);
c.moveToFirst();
while(!c.isAfterLast())
{
try
{
Log.d(TAG, "Message is " + c.getString(c.getColumnIndex("Message")));
}
catch(Exception e)
{
Log.d("Exp", e.getMessage());
}
c.moveToNext();
} c.close();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
}
super.onCallStateChanged(state, incomingNumber);
}
};
}
歡迎來到Stackoverflow!如果您發現回覆有幫助,請投票。如果回覆成功回答您的問題,請點擊旁邊的綠色複選標記以接受答案。另請看看http://stackoverflow.com/questions/how-to-ask關於如何寫一個好問題的建議 –
你得到的錯誤是什麼? logcat說什麼? –
@exilimex:請張貼您的logcat。 – Hiral