Disable android wear pending intent action confirmation - android

I'm currently working on an app with notification which are shown on a wear device. The notification contains an action binded onto the notification card (.setContentAction(0)).
Everything is working fine, except that it shows a confirmation message everytime someone clicks on the card.
Since the card gets updated as soon as someone clicks on it, it's not necessary to show a confirmation.
I already check the official documentation (https://developer.android.com/training/wearables/ui/confirm.html#show-confirmation) if there is a way to stop the confirmation, unfortunately I didn't find a solution so far.
Edit 09.07.2015
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setGroup("GROUP")
.setGroupSummary(false)
.setAutoCancel(false)
.setPriority(Notification.PRIORITY_HIGH)
.setSmallIcon(R.drawable.ic_timer_white_48dp);
ArrayList<NotificationCompat.Action> actions = new ArrayList<>();
NotificationCompat.Action control = new NotificationCompat.Action.Builder(icon, null, pendingTimeIntent).build();
actions.add(control);
builder.extend(new NotificationCompat.WearableExtender().addActions(actions).setContentAction(0).setBackground(background));
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(context);
notificationManager.notify(Constants.NOTIFICATION_ID_WEAR, builder.build());

you could try modify your constructor like:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setGroup("GROUP")
.setGroupSummary(false)
.setAutoCancel(false)
.setPriority(Notification.PRIORITY_HIGH)
.setShowWhen(true)
.setSmallIcon(R.drawable.ic_timer_white_48dp);
Note the line:
.setShowWhen(true);
And you can modify the flag of the Intent to false:
Intent intent = new Intent(this, ConfirmationActivity.class);
intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
ConfirmationActivity.SUCCESS_ANIMATION);
intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE,
getString(R.string.msg_sent));
intent.putExtra(ConfirmationActivity.EXTRA_SHOW_WHEN, false);
startActivity(intent);
I don't know if it works properly, but I hope it gives you a clue.

Related

Can I perform an action if a notification gets touched?

I have seen a demo of a phone performing an action when a notification on the top of the screen gets pulled down. Usually when you do this on Android the notification menu opens. It works with all apps, so not only from specific supported apps. I have tried implementing this, but couldn't find any way to do this.
.addAction
only allows me to add buttons, but not something like this. Ideally, I think I would need to implement something like an onTouchEvent into all notifications.
Following code create a notification, if you add an intent to it (in my case it is empty) an action can be performed when notification is clicked.
public void buttonClick(View v){
final Intent emptyIntent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(MyActivitity.this, 0, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setAutoCancel(true) //when clicked it disappears
.setContentIntent(pendingIntent); //Required on Gingerbread and below
NotificationManager notificationManager = (NotificationManager) MyActivitity.this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, mBuilder.build());
}

Button/Action not appearing on Wear notification

I'm trying to build an Android application that sends a notification to an Android Wear device.
The notification needs to have a content action set, so that the user can directly activate the action by clicking on the button displayed in the notification.
However, using the below code, the action appears on the next page, just like a regular action, and not on the notification:
Context context = getApplicationContext();
// Create an intent for the reply action
Intent actionIntent = new Intent(this, getClass());
PendingIntent actionPendingIntent =
PendingIntent.getActivity(this, 0, actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Create the action
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.common_signin_btn_icon_dark, "ActionTitle", actionPendingIntent).build();
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.common_signin_btn_icon_dark)
.setContentTitle("Title")
.setContentText("Context Text")
.addAction(action)
.extend(new NotificationCompat.WearableExtender()
.setContentAction(0));
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
// Build the notification and issues it with notification manager.
notificationManager.notify(0, builder.build());
This is how it looks:
After swiping:
It is supposed to all be on a single page, with the Action button imbedded into the notification, like this:
What am I doing wrong?
Please try the possible solutions here:
Android Wear - Notification - setContentAction() not working
Can't create "Single-action control" notification android wear

How can I create a Notification.Action and add it to a custom notification

I'm following Google's instructions here https://developer.android.com/training/wearables/notifications/creating.html
However, unsurprisingly, their code doesn't work. Specifically I'm trying to do this:
// Build the notification and add the action via WearableExtender
Notification notification =
new Notification.Builder(context)
.setSmallIcon(R.drawable.buzz_icon)
.setContentTitle("Buzz")
.setContentText("OpenBuzz")
.extend(new Notification.WearableExtender().addAction(action))
.build();
I want an action specific to the Wearable, so I have no choice but to use Notification.WearableExtender(). But it's addAction method only accepts an action as it's parameter. Here is my code for creating an action:
Notification.Action action =
Notification.Action.Builder(R.drawable.buzz_icon, actionIntent.toString(), pendingIntent);
Which doesn't work, as Android Studio says "Method call expected"
How can I successfully create a Notification.Action?
Or how else might I add a Wearable specific action to my notification?
You're on the right track.
You need to create a new NotificationCompat.Action.Builder and then call build() on it. Like this:
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_call, "Only in wearable", pendingIntent)
.build();
Also, make sure that the action is defined as NotificationCompat.Action, not Notification.Action.
This example illustrates how to add a notification with an action (e.g. open the main activity).
NotificationCompat.Builde mBuilder = new NotificationCompat.Builder(this, null);
Intent myIntent = new Intent(this, MainActivity.class);
PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
mBuilder.setContentTitle("Your_title")
.setContentText("Some_text")
.setSmallIcon(R.drawable.app_icon)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setOngoing(true)
.addAction(R.drawable.open_icon, "Open", myPendingIntent)
.setAutoCancel(false);
NotificationManager mNotifyManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
mNotifyManager.notify(1, mBuilder.build());

Android Wear Notification Page Actions

I have an app that kicks off a notification on a Wear device (the notification is created and shown on the Wear device).
What I want to do is have the "first" notification page display some high level info (app name, scroll to see more, etc...), and then have a list of pages containing content after that.
That works fine. The issue is that I want to attach an Action to each page (to kick off a PendingIntent). However, no matter what I try, I can't get the page to perform the Action.
I've tried:
setContentIntent
addAction
addAction and extend(new Notification.WearableExtender().setContentAction(0))
Anyone have any ideas?
I'm using Notification, not NotificationCompat, but I don't think that should make a difference.
UPDATE: I'm creating the notification on the watch. Here is the code I use:
private void createNotifications(ArrayList<Thing> things) {
DataApi data = Wearable.DataApi;
int notificationId = 0;
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder mainBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.default_icon)
.setContentTitle("Things")
.setContentText("Swipe to see your things")
.setPriority(Notification.PRIORITY_DEFAULT);
List<Notification> pages = new ArrayList<>(things.size());
for(Thing thing : things) {
pages.add(createNotificationPageForThing(data, thing, notificationId).build());
notificationId++;
}
Notification n = new Notification.WearableExtender().addPages(pages).extend(mainBuilder).build();
nm.notify(notificationId, n);
}
private Notification.Builder createNotificationPageForThing(DataApi data, Thing thing, int notificationId) {
Asset bitmapAsset = getBitmapAsset(data, contact);
Intent thingIntent = new Intent(this, WearDetailActivity.class);
thingIntent.putExtra(WearDetailActivity.DETAIL_EXTRA, thing);
PendingIntent thingPendingIntent = PendingIntent.getActivity(this, notificationId, thingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Action action = new Notification.Action(R.drawable.ic_action_social_person, "More details", thingPendingIntent);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_action_social_person)
.setContentTitle(thing.getDisplayName())
.setPriority(Notification.PRIORITY_DEFAULT)
.addAction(action)
.extend(new Notification.WearableExtender().setContentAction(0));
if(bitmapAsset != null) {
try {
Bitmap b = BitmapFactory.decodeStream(
data.getFdForAsset(connection.getClient(), bitmapAsset).await().getInputStream());
builder.setLargeIcon(b);
} catch (Throwable ignore) {}
}
return builder;
}
#Eliezer, reading at the following line I did not understand what exactly is the behaviour you're experiencing ... explaining it in details might be helpful to debug your problem.
However, no matter what I try, I can't get the page to perform the Action.
Using .addAction() should work in your case. You'd want to use WearableExtender if you were creating the notification from the device, not the watch itself. Just to confirm something obvious - you're passing the .addAction a PendingIntent right?
Here's a code snippet from one of my applications, which accomplishes exactly what you're aiming for - I have just "Swipe for actions" text in the first page, and the next 2 pages perform different actions.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent openIntent = new Intent(this, CommonWearIntentService.class);
openIntent.setAction(CommonWearIntentService.ACTION_OPEN_ON_PHONE);
PendingIntent openPendingIntent = PendingIntent.getService(this, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent addTransactionIntent = new Intent(this, CommonWearIntentService.class);
addTransactionIntent.setAction(CommonWearIntentService.ACTION_ADD_TRANSACTION);
PendingIntent addTransactionPendingIntent = PendingIntent.getService(this, 0, addTransactionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.swipe_for_actions))
.addAction(R.drawable.add_transaction, getString(R.string.add_transaction), addTransactionPendingIntent)
.addAction(R.drawable.common_full_open_on_phone, getString(R.string.common_open_on_phone), openPendingIntent)
.setVibrate(new long[]{500, 500, 500, 1000})
.setLights(Color.BLUE, 3000, 3000)
.setOngoing(true);
notificationManager.notify(ONGOING_NOTIFICATION_ID, builder.build());
Hope this helps!
Per the documentation, you must use NotificationCompat. After you switch to that setContentIntent() looks to be the right way to set the PendingIntent.
Example from the linked docs:
// Create builder for the main notification
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.new_message)
.setContentTitle("Page 1")
.setContentText("Short message")
.setContentIntent(viewPendingIntent);
// Create a big text style for the second page
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
.bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setStyle(secondPageStyle)
.build();
// Add second page with wearable extender and extend the main notification
Notification twoPageNotification =
new WearableExtender()
.addPage(secondPageNotification)
.extend(notificationBuilder)
.build();
// Issue the notification
notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, twoPageNotification);

Is possible set Expanded Notification as default in Big Text Notifications?

I followed this Sample Code
In Big Text Notifications section, he said that need expand to see Big text notification form, as image im below :
I wonder that we can not set Expanded Notification as default in Big Text Notifications?
People who know it is can or not,
If can,
Please tell me how to do it,
Thanks,
The documentation states:
A notification's big view appears only when the notification is
expanded, which happens when the notification is at the top of the
notification drawer, or when the user expands the notification with a
gesture.
So my answer is no, you can't expand it by default.
There is however a trick to push the notification to the top of the list where it would be expanded. Simply set the Priority to Notification.PRIORITY_MAX and chances are that your app's notification will make it to the top.
Notification noti = new Notification.Builder()
... // The same notification properties as the others
.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap))
.build();
You change
.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
along with the announcement
notification = new NotificationCompat.Builder(context)
Here is an example:
You can set Code
Intent intent = new Intent(context, ReserveStatusActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
intent = new Intent(String.valueOf(PushActivity.class));
intent.putExtra("message", MESSAGE);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(PushActivity.class);
stackBuilder.addNextIntent(intent);
// PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// android.support.v4.app.NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
// bigStyle.bigText((CharSequence) context);
notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(th_title)
.setContentText(th_alert)
.setAutoCancel(true)
// .setStyle(new Notification.BigTextStyle().bigText(th_alert) ตัวเก่า
// .setStyle(new NotificationCompat.BigTextStyle().bigText(th_title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
.setContentIntent(pendingIntent)
.setNumber(++numMessages)
.build();
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationManager.notify(1000, notification);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Your Long Text here"))
simply setStyle of your notification builder.
No need of doing any kind of modification in the any file for showing of multiple lines of Notification while using Push Notification V5, remove the field "style", from the object you are sending. Automatically the Multiple lines of notification will be seen. For more information, upvote the answer, ask your query. I will help you out.
For reference, visit this question
From this notification code you have got images, and big text or more.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.drawable.small_logo);
mBuilder.setColor(Color.parseColor("#D74F4F"));
} else {
mBuilder.setSmallIcon(icon);
}
mBuilder.setTicker(title).setWhen(when);
mBuilder.setAutoCancel(true);
mBuilder.setContentTitle(title);
mBuilder.setContentIntent(intent);
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), icon));
mBuilder.setContentText(msg);
mBuilder.setPriority(Notification.PRIORITY_MAX);
if (Utils.validateString(banner_path)) {
mBuilder.setStyle(notiStyle);
} else {
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
}
Notification noti = mBuilder.build();
notificationManager.notify(0, noti);

Categories

Resources