Skip to content

Instantly share code, notes, and snippets.

@deRonbrown
Created January 16, 2015 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deRonbrown/939e4956effaa9528215 to your computer and use it in GitHub Desktop.
Save deRonbrown/939e4956effaa9528215 to your computer and use it in GitHub Desktop.
String message = "Test Message";
CharSequence appName = "Test App";
int appIcon = android.R.drawable.sym_def_app_icon;
try {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
appName = context.getPackageManager().getApplicationLabel(applicationInfo);
appIcon = applicationInfo.icon;
} catch (PackageManager.NameNotFoundException e) {}
Notification notification = new Notification(appIcon, message, System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent launchIntent = new Intent(this, TestActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, appName, message, contentIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(campaignId, notification);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment