Android N引入了一些新的API,其中增加了快速回复,捆绑通知,自定义视图和消息样式,这篇文章主要给大家讲一下快速回复功能是如何实现的。
首先我们利用Button的点击事件去触发添加一个Notification,代码如下:
MainActivity.java
public static final String KEY_TEXT_REPLY = "key_text_reply";//获取快速回复内容的key
public static final int NOTIFICATION_ID = 100;
......
private void addNotification(){
String replyLabel = getResources().getString(R.string.reply_label);
//创建一个远程输入(既:通知栏的快捷回复)
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel(replyLabel)
.build();
//点击快速回复中发送按钮的时候,会发送一个广播给GetMessageReceiver
Intent intent = new Intent(MainActivity.this,GetMessageReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,intent,
PendingIntent.FLAG_ONE_SHOT)