android.provider.Settings.Secure.android\u ID错误处理

android.provider.Settings.Secure.android\u ID错误处理,android,error-handling,Android,Error Handling,我的应用程序中有以下代码 String deviceIdentifier = android.provider.Settings.System.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); 它似乎99%的时间都能正常工作,但有时应用程序会出现以下错误消息而崩溃 接收广播意图时出错{act=RefreshData flg=0x10} 在com.heyju

我的应用程序中有以下代码

        String deviceIdentifier = android.provider.Settings.System.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
它似乎99%的时间都能正常工作,但有时应用程序会出现以下错误消息而崩溃

接收广播意图时出错{act=RefreshData flg=0x10}
在com.heyjude.heyjudeapp.fragment.TaskFragment中$1@3d173aca


如何进行尝试捕获以避免此错误?我很高兴将该值设置为
null
,否则它会中断

也许这会对您有所帮助

public String getDeviceID(){
    String deviceId = "";
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null){
        deviceId = mTelephony.getDeviceId();
    }else{
        deviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
    }
    return deviceId;
}

也许这对你有帮助

public String getDeviceID(){
    String deviceId = "";
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null){
        deviceId = mTelephony.getDeviceId();
    }else{
        deviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
    }
    return deviceId;
}