如何获得数字模式,如#34;#123456789"从拨号按钮

时间:2016-09-05 06:26:11

标签: android

我尝试使用以下代码:

if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){             
    String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);                     
    Bundle bundle = new Bundle(); 
    bundle.putInt("hideAppPass", Integer.parseInt(number));
    Log.e("number ",number+"");         
}

但它说" NUmberFormateException"。

更新的代码:

public class HideAppIconReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {

 Log.e("app icon receiver ", "onReceive()+");

    if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){

        String number = intent.getStringExtra(Intent.ACTION_DIAL);
        if (number == null){
        Log.e("Error entering number ", "number is null "+ number+"");
        }else{
            Bundle bundle = new Bundle();
            bundle.putInt("hideAppPass", Integer.parseInt(number));
            Log.e("number ",number+"");
        }
    }
}
}

错误日志:

09-05 12:12:00.070 3178-3178/applock.mindorks.com.applock E/app icon receiver: onReceive()+
09-05 12:12:00.070 3178-3178/applock.mindorks.com.applock E/Error entering number: number is null null

0 个答案:

没有答案