2015-11-03 241 views
2

來電我能夠檢索的機器人卻無力其他版本的來電號碼在marshmallow android無法在棉花糖

public void onReceive(Context context, Intent intent) { 
    mContext=context; 
    if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) { 

     String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
     Toast.makeText(context, "Call from:" + incomingNumber, Toast.LENGTH_LONG).show(); 
     final Thread thread=new Thread(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        Thread.sleep(1000); 

        intentStart = new Intent(mContext.getApplicationContext(), MainActivity.class); 
        intentStart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
        mContext.startActivity(intentStart); 
       } 

       catch (InterruptedException e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
     thread.start(); 

    }} 
+0

您是否找到解決方案? – Mainak

回答

0

稍作修改檢索來電號碼之前檢索號碼,你的代碼工作得很好的我的Nexus 6使用MRA58K。我刪除了第2行,並使用context而不是mContext。我還在第13行宣佈了一個本地意向。

+0

在此代碼中當我的手機接到電話時,Toast不會顯示號碼 –