Created
March 24, 2015 16:09
-
-
Save tajchert/53f728fadae7e3e9d77a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RemoteInput[] remoteInputs = new RemoteInput[notificationWear.remoteInputs.size()]; | |
Intent localIntent = new Intent(); | |
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
Bundle localBundle = notificationWear.bundle; | |
int i = 0; | |
for(RemoteInput remoteIn : notificationWear.remoteInputs){ | |
getDetailsOfNotification(remoteIn); | |
remoteInputs[i] = remoteIn; | |
localBundle.putCharSequence(remoteInputs[i].getResultKey(), "Our answer");//This work, apart from Hangouts as probably they need additional parameter (notification_tag?) | |
i++; | |
} | |
RemoteInput.addResultsToIntent(remoteInputs, localIntent, localBundle); | |
try { | |
notificationWear.pendingIntent.send(MainActivity.this, 0, localIntent); | |
} catch (PendingIntent.CanceledException e) { | |
Log.e(TAG, "replyToLastNotification error: " + e.getLocalizedMessage()); | |
} |
also not sending reply as "Our answer". Instead open LINE window.
@technobhardwaj I think you must have been figure out this. here is my work code base on @tajchert.
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public NotificationWear getNotificationWear(StatusBarNotification statusBarNotification) {
NotificationWear notificationWear = new NotificationWear();
Bundle bundle = statusBarNotification.getNotification().extras;
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if ("android.wearable.EXTENSIONS".equals(key)) {
Bundle wearBundle = ((Bundle) value);
for (String keyInner : wearBundle.keySet()) {
Object valueInner = wearBundle.get(keyInner);
if (keyInner != null && valueInner != null) {
if ("actions".equals(keyInner) && valueInner instanceof ArrayList) {
ArrayList<Notification.Action> actions = new ArrayList<>();
actions.addAll((ArrayList) valueInner);
for (Notification.Action act : actions) {
if (act.getRemoteInputs() != null) {//API > 20 needed
notificationWear.actionIntent = act.actionIntent;
notificationWear.RemoteInputs = act.getRemoteInputs();
return notificationWear;
}
}
}
}
}
}
}
return null;
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public void reply(RemoteInput[] remoteInputs, Bundle bundle, PendingIntent pendingIntent) {
if (remoteInputs == null || bundle == null || pendingIntent == null)
return;
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle localBundle = bundle;
for (RemoteInput remoteInput : remoteInputs) {
localBundle.putCharSequence(remoteInput.getResultKey(), "Our answer");
}
RemoteInput.addResultsToIntent(remoteInputs, localIntent, localBundle);
try {
pendingIntent.send(this.mContext, 0, localIntent);
} catch (PendingIntent.CanceledException e) {
Log.e("", "replyToLastNotification error: " + e.getLocalizedMessage());
}
}
public class NotificationWear{
public android.app.RemoteInput[] RemoteInputs;
public PendingIntent actionIntent;
}
where to call reply() function ??
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its not sending reply as "Our answer". Instead open watsapp window.. please tell me hw to send some fixed reply