gpt4 book ai didi

android - 如何将挂起的 Intent 转换为 byte[]

转载 作者:行者123 更新时间:2023-11-30 04:56:48 25 4
gpt4 key购买 nike

我正在开发通知监听器应用程序。在这里我收到所有通知。但是如何将未决 Intent 从通知转换为 byte[],反之亦然。

   @Override public void onNotificationPosted(StatusBarNotification sbn) { 
System.out.println("Notification_AGS: onNotificationPosted");
if (SharedPreferenceManager.getPrefStoragePermission(context)) {
notificationList.clear();
String packageName = sbn.getPackageName();
PendingIntent pendingIntent = sbn.getNotification().contentIntent
}
}

最佳答案

您可以将 PendingIntent 序列化为 Parcel,然后将 Parcel 转换为字节数组,如下所示:

PendingIntent pendingIntent = ...
Parcel parcel = Parcel.obtain();
pendingIntent.pendingIntent.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();

注意以下事项:

The documentation explicitly states that the resulting byte array should NOT be stored in a persistent storage because the byte array is a highly optimized serialized form and it is not guaranteed that the Parcel can be successfully recreated from the byte array.

关于android - 如何将挂起的 Intent 转换为 byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58969021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com