List of usage examples for android.app PendingIntent getActivity
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.webkey.Ipc.java
public void notiyShow(Context pContext, String message) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(pContext); if (!prefs.getBoolean("statusbar", true)) { notiyDestroy(pContext);//from w ww .j a v a 2 s .c o m return; } Notification notification; // Log.d("Webkey","START_notify"); if (manager == null) manager = (NotificationManager) pContext.getSystemService(Context.NOTIFICATION_SERVICE); notification = new Notification(); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.icon = R.drawable.icon; //notification.tickerText = "Service is running"; notification.when = System.currentTimeMillis(); //Intent notificationIntent = new Intent(); //PendingIntent contentIntent = PendingIntent.getActivity(pContext, 0, notificationIntent, 0); //notification.setLatestEventInfo(pContext, "Webkey", "NotificationContent", contentIntent); Intent notifyIntent = new Intent(pContext, Webkey.class); notification.setLatestEventInfo(pContext, "Webkey", message, PendingIntent.getActivity(pContext, 0, notifyIntent, 0)); manager.notify(1, notification); }
From source file:io.clh.lrt.androidservice.TraceListenerService.java
private void setNotification(String msg, boolean ongoing) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence notiText = msg;//w w w . j ava2s . c o m long meow = System.currentTimeMillis(); Notification notification = new Notification(icon, notiText, meow); Context context = getApplicationContext(); CharSequence contentTitle = "LRT notification"; CharSequence contentText = msg; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); int SERVER_DATA_RECEIVED = 1; if (ongoing) { notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_SHOW_LIGHTS; startForeground(1337, notification); } else { notificationManager.notify(SERVER_DATA_RECEIVED, notification); } }
From source file:com.inloc.dr.StepService.java
/** * Show a notification while this service is running. */// w w w .j a v a 2s . c om private void showNotification() { CharSequence text = getText(R.string.app_name); Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent pedometerIntent = new Intent(); pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class)); pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
@SuppressWarnings("unused") private PendingIntent getInstallPendingIntent(final String fileName) { final String mimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(CommonHelper.getExtension(fileName)); if (mimeType != null) { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(fileName)), mimeType); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); return pi; }//from w ww .j a v a 2 s .c om return null; }
From source file:com.perm.DoomPlay.PlayingService.java
private Notification createOldNotif() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Intent intentActivity;//from w ww .j ava 2 s . co m if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) { intentActivity = new Intent(FullPlaybackActivity.actionReturnFull); intentActivity.setClass(this, FullPlaybackActivity.class); intentActivity.putExtra(FileSystemActivity.keyMusic, audios); } else { intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios); } intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); builder.setContentIntent( PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_UPDATE_CURRENT)) .setOngoing(true) .setSmallIcon(isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play); Audio audio = audios.get(indexCurrentTrack); builder.setContentTitle(audio.getTitle()); builder.setContentText(audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); builder.setLargeIcon(tempBitmap); tempBitmap.recycle(); } else { builder.setLargeIcon(cover); cover.recycle(); } return builder.build(); }
From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java
@SuppressWarnings("deprecation") public void setServiceForeground(Context mContext) { final int myID = 9999; // The intent to launch when the user clicks the expanded notification Intent mIntent = new Intent(mContext, BackgroundActivity.class); mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0, mIntent, 0); // This constructor is deprecated. Use Notification.Builder instead Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name), System.currentTimeMillis()); // This method is deprecated. Use Notification.Builder instead. mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification), pendIntent);/*from w w w . j av a2 s .c o m*/ mNotification.flags |= Notification.FLAG_NO_CLEAR; startForeground(myID, mNotification); }
From source file:com.openerp.base.ir.Attachment.java
@SuppressWarnings("deprecation") private Notification setFileIntent(Uri uri) { Log.v(TAG, "setFileIntent()"); Intent intent = new Intent(Intent.ACTION_VIEW); FileNameMap mime = URLConnection.getFileNameMap(); String mimeType = mime.getContentTypeFor(uri.getPath()); intent.setDataAndType(uri, mimeType); mNotificationResultIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.addAction(R.drawable.ic_oe_notification, "Download attachment", mNotificationResultIntent);//from w w w.j av a2 s.c o m mNotificationBuilder.setOngoing(false); mNotificationBuilder.setAutoCancel(true); mNotificationBuilder.setContentTitle("Attachment downloaded"); mNotificationBuilder.setContentText("Download Complete"); mNotificationBuilder.setProgress(0, 0, false); mNotification = mNotificationBuilder.build(); mNotification.setLatestEventInfo(mContext, "Attachment downloaded", "Download complete", mNotificationResultIntent); return mNotification; }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void oldPushNotification(Context context, Intent intent) { PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground); if (EBrowserActivity.isForground) { if (mContext != null) { intent.putExtra("ntype", F_TYPE_PUSH); ((EBrowserActivity) mContext).handleIntent(intent); }//w ww . j a v a2s . c o m } else { CharSequence tickerText = intent.getStringExtra("title"); // ???? Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); long when = System.currentTimeMillis(); // ? // ??Nofification String notifyTitle = null; String pushMessage = intent.getStringExtra("message"); String value = intent.getStringExtra("data"); // ??json try { JSONObject bodyJson = new JSONObject(value); notifyTitle = bodyJson.getString("msgName");// ? } catch (Exception e) { PushReportUtility.oe("onReceive", e); } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName? } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = "APPCAN";// widgetNameAPPCAN? } CharSequence contentTitle = notifyTitle; // ? Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity notificationIntent.putExtra("data", value); notificationIntent.putExtra("message", pushMessage); notificationIntent.putExtra("ntype", F_TYPE_PUSH); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); Notification notification = new Notification(icon, tickerText, when); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; if (Build.VERSION.SDK_INT >= 16) { try { Field priorityField = Notification.class.getField("priority"); priorityField.setAccessible(true); priorityField.set(notification, 1); } catch (Exception e) { PushReportUtility.oe("onReceive", e); } } PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent); // NotificationNotificationManager mNotificationManager.notify(notificationNB, notification); notificationNB++; } }
From source file:com.easibeacon.examples.shop.MainActivity.java
public void createNotification(String title, String content, String monumentId) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(content); Intent resultIntent = new Intent(getApplicationContext(), MonumentActivity.class); Log.i("Monument", monumentId); resultIntent.putExtra("id", monumentId); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(Integer.parseInt(monumentId), mBuilder.build()); //arrayAdapter.notifyDataSetChanged(); }
From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java
/** * Show a notification while this service is running. *//* ww w . ja v a2 s . c om*/ private void showNotification(String text) { // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.uploadtocloud, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification Intent i = new Intent(this, MeActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /*Bundle bundle = new Bundle(); bundle.putInt("idTrack", soundcloudTrack.getmIdTrack()); i.putExtras(bundle);*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, "Uploading...", text, contentIntent); // We show this for as long as our service is processing a command. notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.number = totalUploads; // Send the notification. // We use a string id because it is a unique number. We use it later to cancel. mNM.notify(777, notification); }