问题
I am able to retrieve incoming call number in other version of android but unable to retrieve incoming call number in 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();
}}
回答1:
With minor modifications, your code worked fine on my Nexus 6 using MRA58K. I removed line 2 and used context
instead of mContext
. I also declared a local intent on line 13.
回答2:
It's happens when application don't have PHONE permission. How it's works - http://developer.android.com/intl/es/training/permissions/index.html#permission-groups
来源:https://stackoverflow.com/questions/33491585/unable-to-retrieve-number-before-incoming-call-in-marshmallow