问题描述
我正在创建Android笔记应用,并希望添加功能以编辑存储在通知中的笔记。那么我可以从当前注释(通知)向Android RemoteInput添加初始文本,并允许用户对其进行更改吗?
示例:我需要将通知中的“ hello world”文本设置为“类型注释” RemoteInput字段。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent editIntent = new Intent(ACTION_EDIT,null,context,EditReceiver.class);
editIntent.setAction(ACTION_EDIT);
editIntent.putExtra(NOTIFICATION_ID,id);
PendingIntent replyPendingIntent =
PendingIntent.getbroadcast(context,id,editIntent,PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(EDIT_TEXT)
.setLabel(TYPE_NOTE)
.build();
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send,EDIT,replyPendingIntent)
.addRemoteInput(remoteInput)
.build();
mBuilder.addAction(action);
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.pushpinsm));
}
解决方法
我认为无法设置初始消息。
如果您关于设置标签的问题,此代码将在 RemoteInput 中设置标签。
for key,value in handler.items():
try:
unpacked = struct.unpack('>BBBf',value.encode('latin1'))
if unpacked[:3] == (159,120,4):
'''Checking if data Opaque or not.'''
print(unpacked[-1])
else:
print(value)
except AttributeError:
print(value)