我正在开发一个应用程序,该应用程序能够直接从notificationlistener回复Whatsapp通知,文本效果很好,但是当我发送图像时,该消息未发送,并且给我敬酒,并显示消息“无法发送空消息”信息”。你能帮我吗?
private NotificationCompat.Action replyAction(Notification notification) {
NotificationCompat.Action action;
for (NotificationCompat.Action action2 : new NotificationCompat.WearableExtender(notification).getActions()) {
if (isAllowFreeFormInput(action2)) {
return action2;
}
}
if (!(notification == null || notification.actions == null)) {
for (int i = 0; i < NotificationCompat.getActionCount(notification); i++) {
action = NotificationCompat.getAction(notification, i);
if (isAllowFreeFormInput(action)) {
return action;
}
}
}
return null;
}
private boolean isAllowFreeFormInput(NotificationCompat.Action action) {
if (action.getRemoteInputs() == null) {
return false;
}
for (RemoteInput allowFreeFormInput : action.getRemoteInputs()) {
if (allowFreeFormInput.getAllowFreeFormInput()) {
return true;
}
}
return false;
}
我在这里发送消息
private void sendMsg(String msg, String base64){
RemoteInput[] allremoteInputs = new
RemoteInput[remoteInputs.size()];
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Iterator it = remoteInputs.iterator();
String encdoedDataString = base64.replace("data:image/png;base64,","");
byte[] decodeString =
Base64.decode(encdoedDataString.getBytes(), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodeString, 0, decodeString.length);
decodedByte.prepareToDraw();
int i=0;
while (it.hasNext()) {
allremoteInputs[i] = (RemoteInput) it.next();
bundle.putParcelable(allremoteInputs[i].getResultKey(), decodedByte); /*my Bitmap*/
//bundle.putCharSequence(allremoteInputs[i].getResultKey(), msg);//This work, apart from Hangouts as probably they need additional parameter (notification_tag?)
i++;
}
RemoteInput.addResultsToIntent(allremoteInputs, localIntent, bundle);
try {
Objects.requireNonNull(replyAction(notification)).actionIntent.send(this, 0, localIntent);
} catch (PendingIntent.CanceledException e) {
Log.e(Const.LOG, "replyToLastNotification error: " + e.getLocalizedMessage());
}
}