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.pixmob.r2droid.DeviceRegistrationService.java
@Override public void onCreate() { super.onCreate(); httpClient = AndroidHttpClient.newInstance(getString(R.string.http_user_agent), this); gaeClient = new AppEngineClient(this, getString(R.string.central_host), httpClient); dashboardIntent = PendingIntent.getActivity(this, 0, new Intent(this, DashboardActivity.class), 0); nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); }
From source file:org.roman.findme.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//w w w .j a va2s . co m */ private void sendNotification(String message) { Intent intent = new Intent(this, MessageActivity.class); intent.putExtra("message", message); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Message").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); if (sharedPreferences.getBoolean("display_message", true)) { displayMessage(message); } }
From source file:au.com.wallaceit.reddinator.MailCheckService.java
private void setNotification() { int message = global.mRedditData.getInboxCount(); Intent notifyIntent = new Intent(this, WebViewActivity.class); notifyIntent.setAction(WebViewActivity.ACTION_CLEAR_INBOX_COUNT); notifyIntent.putExtra("url", "http://www.reddit.com/message/unread/.compact"); Notification notification = new NotificationCompat.Builder(this).setContentTitle(message + " New Messages") .setContentText("Click to view reddit messages") .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.reddit_icon_small)) .setSmallIcon(R.drawable.ic_notify) .setContentIntent(// ww w . j av a 2s. c o m PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(1, notification); }
From source file:com.riksof.a320.c2dm.common.C2DMReceiver.java
@Override protected void onMessage(Context contxt, Intent intent) { String unValidatedURL = intent.getStringExtra("payload"); Log.w("C2DMReceiver", unValidatedURL); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; // icon from resources CharSequence tickerText = "You got message !!!"; // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context Intent notificationIntent = new Intent(this, PushEndpointDemo.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); CharSequence contentTitle = "Norification Received !"; // the next two lines initialize the Notification, using the configurations above Notification notification = new Notification(icon, tickerText, when); notification.defaults |= Notification.DEFAULT_LIGHTS; notification.ledARGB = 0xff00ff00;//w ww.java 2 s . c o m notification.ledOnMS = 300; notification.ledOffMS = 1000; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.setLatestEventInfo(context, contentTitle, unValidatedURL, contentIntent); notificationManager.notify(10001, notification); Cache.getInstance().remove(unValidatedURL); FileCache fc = new FileCache(context); fc.clear(); Log.w("C2DMReceiver", "finish"); }
From source file:com.shafiq.myfeedle.core.PhotoUploadService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); if (Myfeedle.ACTION_UPLOAD.equals(action)) { if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE) && intent.hasExtra(Widgets.INSTANT_UPLOAD)) { String place = null; if (intent.hasExtra(Splace)) place = intent.getStringExtra(Splace); String tags = null; if (intent.hasExtra(Stags)) tags = intent.getStringExtra(Stags); // upload a photo Notification notification = new Notification(R.drawable.notification, "uploading photo", System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading", PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification);/*from w w w .ja v a 2s. c o m*/ (new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String response = null; if (params.length > 2) { Log.d(TAG, "upload file: " + params[2]); HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL, Saccess_token, mMyfeedleCrypto.Decrypt(params[0]))); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(params[2]); ContentBody fileBody = new FileBody(file); entity.addPart(Ssource, fileBody); HttpClient httpClient = MyfeedleHttpClient .getThreadSafeClient(getApplicationContext()); try { entity.addPart(Smessage, new StringBody(params[1])); if (params[3] != null) entity.addPart(Splace, new StringBody(params[3])); if (params[4] != null) entity.addPart(Stags, new StringBody(params[4])); httpPost.setEntity(entity); response = MyfeedleHttpClient.httpResponse(httpClient, httpPost); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } } return response; } @Override protected void onPostExecute(String response) { // notify photo success String message = getString(response != null ? R.string.success : R.string.failure); Notification notification = new Notification(R.drawable.notification, "photo upload " + message, System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", message, PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification); stopSelfResult(mStartId); } }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE), intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags); } } } }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateNotification(Context context, String message) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); notificationIntent.putExtra("alert", message); message = message + " would like to add you as friend"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire();/*from w w w. j a v a2 s . c o m*/ // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:com.NotifyMe.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("NotifyMe").setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.jieehd.villain.toolkit.stats.ReportingService.java
private void promptUser() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent nI = new Intent(); nI.setComponent(new ComponentName(getPackageName(), AnonymousStats.class.getName())); PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0); Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true) .setTicker("Annonymous Statistics").setContentIntent(pI).setWhen(0) .setContentTitle("Annonymous Statistics").setContentText("Enable Reporting"); nm.notify(1, builder.getNotification()); }
From source file:com.sip.pwc.sipphone.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 Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/*from ww w. j a va 2 s.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:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java
private void updateRemoteViews(Context context, RemoteViews views) { if (title != null) { views.setTextViewText(R.id.title, title); }/*from w ww. j a va 2 s.c o m*/ if (image != null) { views.setImageViewBitmap(R.id.image, image); } else { views.setImageViewBitmap(R.id.image, null); } Intent goToSiteIntent = new Intent(Intent.ACTION_VIEW); goToSiteIntent.setData(Uri.parse("http://xkcd.com")); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, goToSiteIntent, 0); views.setOnClickPendingIntent(R.id.image, pendingIntent); if (altText != null) { views.setTextViewText(R.id.alt_text, altText); } Intent intent = new Intent(context, getClass()); intent.setAction(UPDATE); views.setOnClickPendingIntent(R.id.sync, PendingIntent.getBroadcast(context, 0, intent, 0)); }