Android 7意图附加功能缺失

Kon*_*ras 7 android android-intent android-pendingintent android-broadcastreceiver android-7.0-nougat

有没有人知道Android 7.0(Nougat)与Android 6.0(Lollipop)相比如何处理意图附加功能有什么变化?

长话短说:我的应用程序可以在4.1(16)到6.0(23)的所有版本上运行,但在android 7.0(24)上崩溃了!

该应用程序创建一个待定意图,意图是具有附加功能的自定义广播接收器.然而,在android 7上,广播接收器接收的意图中不存在任何附加内容.

MainActivity.java

Intent intent = new Intent(context, PollServerReceiver.class);

// TODO:  Remove after DEBUGGING is completed!
intent.putExtra("TESTING1", "testing1");
intent.putExtra("TESTING2", "testing2");
intent.putExtra("TESTING3", "testing3");

 // PendingIntent to be triggered when the alarm goes off.
 final PendingIntent pIntent = PendingIntent.getBroadcast(context,
            PollServerReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// Setup alarm to schedule our service runs.
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstRun, freqMilis, pIntent);
Run Code Online (Sandbox Code Playgroud)

PollServerReceiver.java

Bundle extras = intent.getExtras();
Log.d(TAG, "onReceive: TESTING1 = " + extras.getString("TESTING1")); // null here

// None of the three "TESTING*" keys are there!
for (String key : extras.keySet()) {
    Object value = extras.get(key);
    Log.d(TAG, String.format("onReceive extra keys: %s %s (%s)", key, value.toString(), value.getClass().getName()));
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪显然将NullPointerException作为崩溃的原因.如果它会在所有版本中崩溃,那就不会那么奇怪了,但在这种情况下它只是最新的android.有人有任何想法吗?

注:我曾尝试创建标志不同,包括(待定意图0,PendingIntent.FLAG_UPDATE_CURRENT,PendingIntent.FLAG_CANCEL_CURRENT)仍然得到了完全相同的结果.

Com*_*are 15

将自定义Parcelable放在一个版本PendingIntent中从来就不是特别可靠,而且AlarmManager PendingIntent在Android 7.0上无法运行.其他进程可能需要填入值Intent,这涉及到操作附加内容,并且除了您自己的进程外,无法在任何进程中完成,因为没有其他进程具有您的自定义Parcelable类.

这个SO答案有一个解决方法,以Parcelable自己转换为/从一个转换byte[].