2016-04-22 114 views
0

我正在做應用程序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

回答

0

您應該檢查null爲意圖。 例如

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

} 

和PLZ發表您的日誌錯誤在這裏。

0

您是否在Manifest中有以下代碼?

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

請發表您的錯誤日誌在這裏

相關問題