重新启动手机时出现App android错误

时间:2016-04-22 06:56:17

标签: android reboot

我正在做应用Android.1活动和1个Boardcast接收。

public abstract class PhonecallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

       if     (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
        savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
    }
    else{
        String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
        String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
        int state = 0;
        if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
            state = TelephonyManager.CALL_STATE_IDLE;
        }
        else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
            state = TelephonyManager.CALL_STATE_OFFHOOK;
        }
        else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
            state = TelephonyManager.CALL_STATE_RINGING;
        }


        onCallStateChanged(context, state, number);
    }
}
 }

和manifestfile

<receiver
android:name=".PhonecallReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
    <action android:name="android.intent.action.PHONE_STATE" />
    <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>

运行时,app运行正常。但是当我重新启动手机时,应用程序错误:

if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))

如何修复错误。谢谢

2 个答案:

答案 0 :(得分:0)

您应该检查null是否有意图。 例如

if(intent != null && !TextUtils.isEmplty(intent.getAction())
{

}

并在此处发布您的日志错误。

答案 1 :(得分:0)

你在Manifest中有以下代码吗?

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">

请在此处发布您的错误日志