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.example.bryan.sunshine.app.gcm.MyGcmListenerService.java
/** * Put the message into a notification and post it. * This is just one simple example of what you might choose to do with a GCM message. * * @param message The alert message to be posted. *//*from w w w. j a v a2 s . c om*/ private void sendNotification(String message) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Notifications using both a large and a small icon (which yours should!) need the large // icon as a bitmap. So we need to create that here from the resource ID, and pass the // object along in our notification builder. Generally, you want to use the app icon as the // small icon, so that users understand what app is triggering this notification. //Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) //.setSmallIcon(R.drawable.art_clear) //.setLargeIcon(largeIcon) .setContentTitle("Weather Alert!").setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentText(message).setPriority(NotificationCompat.PRIORITY_HIGH); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:ar.fi.uba.jobify.service.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */// www. ja v a2 s . c o m private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); 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("FCM Message").setContentText(messageBody).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:kaist.cs492c_2015.washerbrowser.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*w w w .j a va 2 s . c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); 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("Find available washer") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }).setSmallIcon(R.drawable.washer_green) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); launchPopupActivity(this, message); }
From source file:com.klinker.android.twitter.services.TrimDataService.java
public void notifyNewVersion(String version) { Intent goToStore = new Intent(this, RedirectToPlayStore.class); PendingIntent storePending = PendingIntent.getActivity(this, 0, goToStore, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("Talon Version " + version); builder.setContentText("Click to update."); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); builder.setSmallIcon(R.drawable.ic_stat_icon); builder.setContentIntent(storePending); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(552, builder.build()); }
From source file:com.etime.TimeAlarmService.java
/** * Send a notification to the user with the message 'notificationString' * @param notifcationString The message to notify the user with. *///from w w w . ja va2 s.com private void notification(String notifcationString) { CharSequence from = "ETime"; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.icon, notifcationString, System.currentTimeMillis()); notif.flags |= Notification.DEFAULT_LIGHTS; notif.defaults |= Notification.DEFAULT_VIBRATE; notif.setLatestEventInfo(this, from, notifcationString, contentIntent); nm.notify("ETime", APP_ID, notif); }
From source file:com.coderming.weatherwatch.gcm.MyGcmListenerService.java
/** * Put the message into a notification and post it. * This is just one simple example of what you might choose to do with a GCM message. * * @param message The alert message to be posted. *///from w w w . j a v a 2s.c o m private void sendNotification(String message) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Notifications using both a large and a small icon (which yours should!) need the large // icon as a bitmap. So we need to create that here from the resource ID, and pass the // object along in our notification builder. Generally, you want to use the app icon as the // small icon, so that users understand what app is triggering this notification. Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.art_clear).setLargeIcon(largeIcon).setContentTitle("Weather Alert!") .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setPriority(NotificationCompat.PRIORITY_HIGH); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.telepromptu.TeleprompterService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Log.d(TAG, intent.toUri(0));//from ww w .ja v a 2 s .com if (mLiveCard == null) { Log.d(TAG, "Publishing LiveCard"); mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG); // Keep track of the callback to remove it before unpublishing. mCallback = new TeleprompterDrawer(this); mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback); Intent menuIntent = new Intent(this, MenuActivity.class); menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); mLiveCard.publish(PublishMode.REVEAL); Log.d(TAG, "Done publishing LiveCard"); } else { // TODO(alainv): Jump to the LiveCard when API is available. } (new Thread(new Runnable() { @Override public void run() { // String text = "Hi! My name is Waseem Ahmad! I'm a senior studying computer science at Rice University. Today, I'm going to demonstrate an application that my team has created called Telepromptu. It is a Google Glass application that serves as a live automatic teleprompter. The application uses speech recognition to get snippets of text from Google Speech recognition API. Because the speech to text recognition is not fully accurate, our application uses a local subsequence alignment algorithm to match the recognized text with text on the teleprompter."; slides = connect("http://telepromptu.appspot.com/glass?id=" + presentationId); String text = ""; for (Slide slide : slides) { text += slide.notes + " "; } mCallback.mTeleprompterView.setText(text); speechTraverser = new SuperSpeechTraverser(text); } })).start(); startListening(); return START_STICKY; }
From source file:pj.rozkladWKD.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras();/* w w w . j av a2s .co m*/ if (!Prefs.get(context).getBoolean(Prefs.PUSH_TURNED_ON, true)) { RozkladWKDApplication app = (RozkladWKDApplication) getApplication(); SharedPreferences.Editor edit = Prefs.get(context).edit(); edit.putBoolean(Prefs.PUSH_TURNED_ON, false); edit.commit(); app.registerPushes(); } else { if (extras != null) { String type = (String) extras.get("type"); String msg = (String) extras.get("msg"); String username = (String) extras.get("usr"); if (RozkladWKD.DEBUG_LOG) { Log.d("PUSH", type + ": " + msg); } String[] categories = Prefs.getStringArray(context, Prefs.PUSH_CATEGORIES, Prefs.DEFAULT_PUSH_CATEGORIES); Prefs.getNotificationMessageNextNumber(context, type); if (!username.equals(Prefs.get(context).getString(Prefs.USERNAME, "")) && categories != null && type != null) { for (String category : categories) { if (type.equals(category)) { Intent notificationIntent = new Intent(this, MessageActivity.class); notificationIntent.putExtra("page", type.equals(MessagesPagerAdapter.MESSAGE_EVENTS) ? 0 : (type.equals(MessagesPagerAdapter.MESSAGE_WKD) ? 1 : 2)); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); showNotification(msg, String.format(getString(R.string.new_message), getResources().getString(getResources().getIdentifier(type, "string", context.getPackageName()))), msg, contentIntent, Prefs.getNotificationMessageNextNumber(context)); break; } } } context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI")); } } }
From source file:net.olejon.mdapp.NotificationsFromSlvIntentService.java
@Override protected void onHandleIntent(Intent intent) { final Context mContext = this; final MyTools mTools = new MyTools(mContext); if (mTools.getDefaultSharedPreferencesBoolean("NOTIFICATIONS_FROM_SLV_NOTIFY") && mTools.isDeviceConnected()) { RequestQueue requestQueue = Volley.newRequestQueue(mContext); int projectVersionCode = mTools.getProjectVersionCode(); String device = mTools.getDevice(); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest( getString(R.string.project_website_uri) + "api/1/notifications-from-slv/?first&version_code=" + projectVersionCode + "&device=" + device, new Response.Listener<JSONArray>() { @SuppressLint("InlinedApi") @Override/* w ww . j a v a 2 s . c om*/ public void onResponse(JSONArray response) { try { final JSONObject notifications = response.getJSONObject(0); final String title = notifications.getString("title"); final String message = notifications.getString("message"); final String lastTitle = mTools .getSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE"); if (!title.equals(lastTitle)) { if (!lastTitle.equals("")) { Intent launchIntent = new Intent(mContext, NotificationsFromSlvActivity.class); PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); NotificationManagerCompat notificationManager = NotificationManagerCompat .from(mContext); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( mContext); notificationBuilder.setWhen(mTools.getCurrentTime()) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PUBLIC) .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap) .setSmallIcon(R.drawable.ic_local_hospital_white_24dp) .setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLights(Color.BLUE, 1000, 2000).setTicker(title) .setContentTitle(title).setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentIntent(launchPendingIntent) .addAction(R.drawable.ic_notifications_white_24dp, getString( R.string.service_notifications_from_slv_read_more), launchPendingIntent); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } mTools.setSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE", title); } } catch (Exception e) { Log.e("NotificationsFromSlv", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("NotificationsFromSlv", error.toString()); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); } }
From source file:com.portfolio.course.esguti.goubiquitous.mobile.gcm.MyGcmListenerService.java
/** * Put the message into a notification and post it. * This is just one simple example of what you might choose to do with a GCM message. * * @param message The alert message to be posted. */// w ww .j a v a 2s .c o m private void sendNotification(String message) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Notifications using both a large and a small icon (which yours should!) need the large // icon as a bitmap. So we need to create that here from the resource ID, and pass the // object along in our notification builder. Generally, you want to use the com.portfolio.course.esguti.goubiquitous.mobile icon as the // small icon, so that users understand what com.portfolio.course.esguti.goubiquitous.mobile is triggering this notification. Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.art_clear).setLargeIcon(largeIcon).setContentTitle("Weather Alert!") .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setPriority(NotificationCompat.PRIORITY_HIGH); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }