I am implementing push notification using Xamarin. The push notification works fine and I can able to receive a push notification. When I click notification message the corresponding page is not open instead loading pop is showing for a long time. I have used the below code to open activity when clicking notification in android project. I want to call the method which is in the portable project from my new activity class.
Intent intent = new Intent(context, typeof(Push));
intent.AddFlags(ActivityFlags.ClearTop);
PendingIntent activity = PendingIntent.GetActivity(context, 0, intent, 0);
I have called the view in portable project like below
public void test(parameters)
{
await Navigation.PushModalAsync(new DescriptionPage(tileGrid,
m_eBookShortName, m_eBookName, false, downloadImage, deleteImageIcon,
m_downloadProgressbar));
}
What is the issue in my code? how can we launch xaml view when click push notification?
Related
I've a problem with my application. I use a class to manage push notification from Azure, extending NotificationsHandler.All works,the method onReceive "catch" the incoming notification,using bundle i can read each field of the json from azure server.If i click on the notification i can start the activity as follows:
fragment_richiesta_tabsV2 dettaglioTabs= new fragment_richiesta_tabsV2();
Intent myIntent = new Intent(contesto, dettaglioTabs.getClass());
contentIntent = PendingIntent.getActivity(contesto, 0,myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
the problem is when the app is closed from the recent apps.The notification arrives,but if i click on the app crash...how can i solve?
thanks
I just succesfully created a bunch of pages notifications on my Wear device.
The only problem is that the PendingIntent does not seems to start an Activity
(which is of course declared in Manifest).
Here is my code:
List extras = new ArrayList();
Intent viewIntent = new Intent(getApplicationContext(), DetailActivity.class);
viewIntent.putExtra("KEY", "TEST123");
//Note: I also tried: Intent viewIntent = new Intent(getApplicationContext(), DetailActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent viewPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, viewIntent, 0);
for (Route aRoute : myRoutes) {
Notification aNotif = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("BUS " + aRoute.route_short_name)
.setContentText(aRoute.directions.get(0).trip_headsign)
.setLargeIcon(bitmap)
.setContentIntent(viewPendingIntent)
.setSmallIcon(R.mipmap.ic_launcher).build();
extras.add(aNotif);
}
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(desc)
.setContentIntent(viewPendingIntent)//Just in case
.setSmallIcon(R.mipmap.ic_launcher);
Notification notification = builder1
.extend(new NotificationCompat.WearableExtender()
.addPages(extras))
.setContentIntent(viewPendingIntent)//Just in case
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, notification);
When I press on a Notification, I expect the intent to start, but nothing happens..
Any suggestion is welcome.
EDIT:
This code works, just after the notification, so, the second activity can easily be launched withour bug:
startActivity(viewIntent);
EDIT2:
There is now an "open" button at the end that works fine, but still nothing happens on individual notifications (every pages)
Pages are not clickable - on Android Wear, only actions are clickable. For phone generated notifications, those only appear after all pages
If you have a content intent on your phone generated notification, that will always appear as an 'Open on phone' action. There is no way to disable this unless you remove your content intent (making the notification unclickable on phones).
I say 'phone generated' as you can also create a Wear app. By using the data layer to push messages to your Wear app, the Wear app can then build custom notifications. These notifications allow you to use setDisplayIntent() and display activities inline (either as the main page or as separate pages). These activities can, of course, contain any View you want, including actions to perform any action (such as send a message back to the phone to start a particular activity).
Note that because pages are not clickable by default, styling of a custom notification should make it very obvious that the items are clickable. Rather than using a custom notification activity, you may consider using setContentAction() to display the action icon inline with the rest of the layout - this removes the action as a separate element past the action and places it directly on the notification/page.
I have a method which receives text from a push notification, via the Parse API, and packages it into a notification object. Pretty standard stuff. My problem is that I'm trying to use a BigTextStyle to display my notification in the list, but it refuses to do so, and only shows one line of text and the two-finger gesture does not cause it to expand.
However, if I tap the notification, which opens the app, then return to the notification list, it is displayed in the BigTextStyle and is responsive to gestures. So, my guess is that somehow tapping on the notification is activating it and allowing the BigTextStyle code to kick in.
I like that tapping on the notification opens the app, but I don't want to force my users to open the app then close it again to see the full text of my messages. So is there a way I could either make the notification display in the BigTextStyle format from the start, or to make it so that the first click "activates" the notification, allowing the full message text to be seen, and then a second click opens the app? Any help would be appreciated.
Here is my code from the Notification method:
public void receiveNotification() {
NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle();
bts.bigText(SplashActivity.globalDataString);
bts.setSummaryText("Tap to open app, swipe to dismiss message");
NotificationCompat.Builder m = new NotificationCompat.Builder(this);
m.setContentTitle("New Push Notification")
.setContentText(SplashActivity.globalDataString)
.setSmallIcon(R.drawable.app_icon)
.setStyle(bts)
.build();
Intent openApp = new Intent(this, MenuActivity.class);
// This ensures that navigating backward from the Activity leads out of
// the application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MenuActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(openApp);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
m.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(pushMessageID, m.build());
pushMessageID++;
//reset notification
flag1 = false;
}
EDIT: I think my problem is with where I'm calling my receiveNotification() method from. Right now I have it in the onCreate() method of my app's starting activity, which doesn't make much sense looking back. Should I put it in my broadcastReceiver class, or would there be a better place to put it?
Yes, the creation and display of the notification is usually done either in the broadcast receiver, or in an intent service started by the broadcast receiver. Only when the user taps the notification, the relevant activity is launched. You can see Google's client code sample here.
I have an android notification bar which uses a remote view. I have 2 buttons on there to play and pause audio and also an icon to return to the application. I want to be able to click the icon (or anywhere but on the 2 buttons) and return to the application. Here is my code
Intent returnIntent = new Intent(_context, SplashScreenActivity.class);
returnIntent.setAction(Intent.ACTION_MAIN);
returnIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent remoteViewPendingIntent = PendingIntent.getActivity(_context,1, returnIntent,0);
remoteView.setOnClickPendingIntent(R.id.btnAppIcon, remoteViewPendingIntent);
This all works fine in the emulator on Android 4.1. When the icon in the notification is pressed it returns successfully to the app. However on Android 4.0.3 on a Samsung S3 the Activity launches in the background but the notification screen is not hidden. I want the notification screen to be cleared once the icon is selected. I have tried using the Notification.FLAG_AUTO_CANCEL in the notification but that did not fix the issue. Any help would be greatly appreciated.
.setOnClickPendingIntent behavior varies on different MFGs and versions as you've experienced.
To accomplish what you want and auto collapse the notification window automatically (without using reflection), you have to set a "global" pending intent for the notification view. You will need to include your R.id.btnAppIcon in that "catch all" intent view as well.
Example of the "global/default" notification pending intent:
contentIntent = PendingIntent.getActivity(YourClass.this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
The "general" notification intent when used with PendingIntent.getActivity will close the notification window on any device (as I've observed).
I successfully created a custom rich notification for Android >= 3.0 that shows some text and an additional button. If you click the notification anywhere but on the button in the notification drop-down, the notification is dismissed, the drop-down closed and the specified Intent is launched as expected.
If the dedicated button in the notification is clicked, a different Intent is successfully launched, but the drop-down keeps open (and the notification is still there, but I cancel it later, that is not the problem). The Intent launches an Activity which appears behind the notifications drop-down.
What I like to achieve is to keep all the current behavior as described, but also close the notification drop-down from the Intent the button launches - is this possible? Alternatively it would be enough if the Activity from the button Intent gains the window focus.
Here the code for the custom notification, if that helps:
Notification.Builder builder = new Notification.Builder(main)
.setSmallIcon(R.drawable.notification)
.setAutoCancel(true)
.setTicker(text)
.setContentIntent(...);
RemoteViews layout = new RemoteViews(
main.getPackageName(), R.layout.notification);
layout.setTextViewText(R.id.title, title);
layout.setTextViewText(R.id.text, text);
Intent i = new Intent(
"snooze", null, main, Snooze.class
);
i.putExtra(KEY_WIDGET_ID, widgetId);
layout.setOnClickPendingIntent(R.id.notification_zzz, PendingIntent.getActivity( main, 0, i, PendingIntent.FLAG_UPDATE_CURRENT ));
builder.setContent(layout);
...
NotificationManager nm =
(NotificationManager)main.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, builder.getNotification());
Asked the question in the Android developer office hours:
http://www.youtube.com/watch?v=XvLBvdml_Fs (question starting 49:10)
The answer was, that it is not possible and I should not even do this, which I question.
That is why I have created a feature request:
http://code.google.com/p/android/issues/detail?id=24762
EDIT 08-10-12:
Starting with Android 4.1 this is possible as notifications can now include additional actions. See the following page for more information:
https://developer.android.com/about/versions/android-4.1.html#UI