Unable to retrieve number before incoming call in marshmallow

六眼飞鱼酱① 提交于 2019-12-10 18:44:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!