重新启动手机时应用程序android错误
问题描述:
我正在做应用程序Android.1活动和1 Boardcast接收。重新启动手机时应用程序android错误
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);
}
}
}
而且manifest资源配置文件
<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>
运行时,应用程序运行时fine.But我重新启动手机,应用程序错误在:
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
如何解决error.Thank
答
您应该检查null为意图。 例如
if(intent != null && !TextUtils.isEmplty(intent.getAction())
{
}
和PLZ发表您的日志错误在这里。
答
您是否在Manifest中有以下代码?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
请发表您的错误日志在这里