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.sonetel.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/*from w w w. j a va 2s . c o m*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.getNotification() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:com.csipsimple.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/*from w w w . j a va 2s. c o m*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.build() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:addresspager.test_google_cloud_messaging.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.github.rutvijkumar.twittfuse.services.OfflinePostedTweetProcessingService.java
private void sendNotification(Tweet newTweet) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this, TimeLineActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); int random_int = new Random().nextInt(); // build notification // the addAction re-use the same intent to keep the example short Notification n = new Notification.Builder(this).setContentTitle("Tweet posted successfully") .setContentText(newTweet.getBody()).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true).setStyle(new Notification.BigTextStyle().bigText(newTweet.getBody())).build(); notificationManager.notify(random_int, n); }
From source file:hk.edu.cityu.appslab.calmessenger.gcm.GcmIntentService.java
protected void sendNotification(String title, String msg, Intent intent) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent;/*from www .j a va 2 s .c o m*/ if (intent == null) { contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ConversationActivity.class), 0); } else { contentIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // contentIntent = PendingIntent.getActivity(this, 0, intent, // PendingIntent.FLAG_CANCEL_CURRENT); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.unlockdisk.android.opengl.MainGLActivity.java
public void generateNotification(int id, String notificationTitle, String notificationMessage) { notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "A New Message!", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, MainGLActivity.class); // Intent notificationIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com")); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(MainGLActivity.this, notificationTitle, notificationMessage, pendingIntent); //Setting Notification Flags notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.DEFAULT_SOUND; //Adding the Custom Sound notification.audioStreamType = AudioManager.STREAM_NOTIFICATION; String uri = "android.resource://org.openmobster.notify.android.app/" + MainGLActivity.this.findSoundId(MainGLActivity.this, "beep"); notification.sound = Uri.parse(uri); // notification.sound = Uri.fromFile(new File(R.raw.a)); notificationManager.notify(id, notification); }
From source file:com.example.mobileid.GcmIntentService.java
private void sendNotification(Intent intent) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bundle extras = intent.getExtras();//from w w w . j a v a 2s . co m JSONObject gcmObj; try { gcmObj = new JSONObject(extras.getString("message")); String msg = gcmObj.getString("info"); Intent passIntent = new Intent(); passIntent.setClass(this, MainActivity.class); passIntent.putExtra("gcmMsg", gcmObj.toString()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, passIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); if (msg.compareToIgnoreCase("websign") != 0) { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher).setContentTitle("mobileID") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); } else { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Web Sign - " + gcmObj.getString("title")) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(gcmObj.getString("content")); } //default notification sound Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); //cleared after clicking mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } }
From source file:app.taxi.best.bestofthebesttaxiapp.gcm.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_plusone_small_off_client).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.ad.mediasharing.ADUploadMediaTask.java
@SuppressWarnings("deprecation") protected void onPreExecute() { Intent intent = new Intent(); pendingIntent = PendingIntent.getActivity(mActivity, 0, intent, 0); contentTitle = "Uploading Story..."; CharSequence contentText = uploadProgress + "% complete"; // Show the notification progress if (isPreferenceProgressEnabled) { notification = new Notification(R.drawable.ic_launcher_ctv, contentTitle, System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.contentIntent = pendingIntent; notification.setLatestEventInfo(mActivity, contentTitle, contentText, pendingIntent); notificationManager.notify(NOTIFICATION_ID, notification); }//from www . j a va 2 s. c o m // Show the alert progress bar if (isProgressBarEnabled) { pd = new ProgressDialog(mActivity); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMessage(contentTitle); pd.setCancelable(false); pd.show(); } }
From source file:com.arellomobile.android.push.PushGCMIntentService.java
private static void generateNotification(Context context, Intent intent, Handler handler) { Bundle extras = intent.getExtras();//from www. j a v a 2 s. c o m if (extras == null) { return; } extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context)); String title = (String) extras.get("title"); String link = (String) extras.get("l"); // empty message with no data Intent notifyIntent; if (link != null) { // we want main app class to be launched notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else { notifyIntent = new Intent(context, PushHandlerActivity.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); // pass all bundle notifyIntent.putExtra("pushBundle", extras); } // first string will appear on the status bar once when message is added CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo()); if (null == appName) { appName = ""; } NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationFactory notificationFactory; //is this banner notification? String bannerUrl = (String) extras.get("b"); //also check that notification layout has been placed in layout folder int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout", context.getPackageName()); if (layoutId != 0 && bannerUrl != null) { notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title, PushManager.sSoundType, PushManager.sVibrateType); } else { notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title, PushManager.sSoundType, PushManager.sVibrateType); } notificationFactory.generateNotification(); notificationFactory.addSoundAndVibrate(); notificationFactory.addCancel(); Notification notification = notificationFactory.getNotification(); notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (mSimpleNotification) { manager.notify(PushManager.MESSAGE_ID, notification); } else { manager.notify(PushManager.MESSAGE_ID++, notification); } generateBroadcast(context, extras); }