when you receive a broadcast message from NotificationManager, you need to create a new PendingIntent, which will be launched when the user touches the corresponding notification. Now that PendingIntent must have an internal intention, which will have an action to execute, for example, to start an action.
using the onReceive method in a BroadcastReceiver call for a helper method, for example, showProximityAlertNotification
@Override
public void onReceive(Context context, Intent intent) {
showProximityAlertNotification();
}
private void showProximityAlertNotification( ){
String titulo = getString(R.string.notification_proximity_alerts_fired_title);
String tickerText = getString(R.string.notification_proximity_alerts_fired_ticker);
String contextText = getString(R.string.notification_proximity_alerts_fired_content);
int icon = R.drawable.wk_logo;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Intent launchApp = new Intent(getApplicationContext(), ItemListActivity.class);
launchApp.putExtra("com.xxxxxxx.xxxxxxxxx.bean.Item", "anyObjectYouWant");
launchApp.setAction( "VIEW_DETAILS_PROPERTY" );
PendingIntent launchNotification = PendingIntent.getActivity(getApplicationContext(), 0, launchApp, 0);
notification.setLatestEventInfo(getApplicationContext(), titulo, contextText, launchNotification);
notificationManager.notify(NOTIFICATION_ID_PROXIMITY_ALERT_FIRED, notification);
}
if you are performing a recently launched activity and want to cancel a running notification, simply do the following:
String notManagerName = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(notManagerName);
notificationManager.cancel(ProximityAlerts.NOTIFICATION_ID_PROXIMITY_ALERT_FIRED);
amuses
source
share