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.mcongrove.glass.chucknorris.JokeService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LIVE_CARD_ID, "onStartCommand"); if (mLiveCard == null) { mLiveCard = mTimelineManager.getLiveCard(LIVE_CARD_ID); mLiveCard.enableDirectRendering(true).getSurfaceHolder().addCallback(mJokeDrawer); mLiveCard.setNonSilent(true);//from w ww . j ava2s .c o m Intent menuIntent = new Intent(this, MenuActivity.class); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); mLiveCard.publish(); getJoke(); } return START_STICKY; }
From source file:com.iniciacomunicacion.devicenotification.DeviceNotification.java
/** * Adds notification//from ww w. jav a 2 s. c om * * @param callbackContext, Callback context of the request from Cordova * @param title, The title of notification * @param message, The content text of the notification * @param Id, The unique ID of the notification * @param seconds */ public void add(CallbackContext callbackContext, String ticker, String title, String message, int id) { Resources res = DeviceNotification.context.getResources(); int ic_launcher = res.getIdentifier("icon", "drawable", cordova.getActivity().getPackageName()); /* Version 4.x NotificationManager notificationManager = (NotificationManager)DeviceNotification.activity.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification.Builder(DeviceNotification.Context) .setTicker(ticker) .setContentTitle(title) .setContentText(message) .setSmallIcon(ic_launcher) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .build(); notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; notificationManager.notify(id, notification);*/ //Version 2.x NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(DeviceNotification.activity) .setSmallIcon(ic_launcher).setWhen(System.currentTimeMillis()).setContentTitle(title) .setContentText(message).setTicker(ticker); Intent resultIntent = new Intent(DeviceNotification.activity, DeviceNotification.activity.getClass()); PendingIntent resultPendingIntent = PendingIntent.getActivity(DeviceNotification.activity, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotifyMgr = (NotificationManager) DeviceNotification.activity .getSystemService(android.content.Context.NOTIFICATION_SERVICE); mNotifyMgr.notify(id, mBuilder.build()); }
From source file:com.example.jkgan.pmot.service.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from ww w.j a va 2s. c om */ private void sendNotification(final String message, final String title, String id) { String url = MyApplication.getApiUrl() + "/promotions/" + id + "?token=" + MyApplication.getUser().getToken(); final Promotion[] promotion = { null }; final OkHttpClient client = new OkHttpClient(); final Request request = new Request.Builder().url(url).build(); // new Thread(new Runnable() { // @Override // public void run() { Response response = null; try { response = client.newCall(request).execute(); JSONObject jsnObj2 = new JSONObject(response.body().string()); promotion[0] = new Promotion(jsnObj2.optString("pName"), jsnObj2.optString("description"), jsnObj2.optString("id"), jsnObj2.getJSONObject("image").getJSONObject("medium").optString("url"), jsnObj2.getJSONObject("image").getJSONObject("small").optString("url"), jsnObj2.optString("term_and_condition"), jsnObj2.optString("name"), jsnObj2.optString("address"), jsnObj2.optString("sId"), getDate(jsnObj2.optString("starts_at")), getDate(jsnObj2.optString("expires_at")), jsnObj2.optString("phone")); Intent intent = new Intent(getApplicationContext(), PromotionActivity.class); intent.putExtra("NAME", promotion[0].getName()); intent.putExtra("SHOP_ID", promotion[0].getId()); intent.putExtra("IMAGE", promotion[0].getImage()); intent.putExtra("DESCRIPTION", promotion[0].getDescription()); intent.putExtra("TNC", promotion[0].getTnc()); intent.putExtra("SHOP_NAME", promotion[0].getShop().getName()); intent.putExtra("ADDRESS", promotion[0].getShop().getAddress()); intent.putExtra("START", promotion[0].getStarts_at()); intent.putExtra("EXPIRE", promotion[0].getExpires_at()); intent.putExtra("PHONE", promotion[0].getShop().getPhone()); intent.putExtra("SUBSCRIBED", true); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (numMessages >= 1) { notificationTitle += (", " + title); notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle((numMessages + 1) + " new promotions") .setContentText(notificationTitle).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); numMessages = 0; notificationBuilder.setContentText(message).setNumber(++numMessages); } else { notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); notificationTitle = title; numMessages++; // notificationBuilder.setContentText(message) // .setNumber(++numMessages); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // On gnre un nombre alatoire pour pouvoir afficher plusieurs notifications notificationManager.notify(notifyID, notificationBuilder.build()); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.hedgehog.smdb.ActionBarControlScrollViewActivity.java
private void showNotification() { Notification notification = null; Intent toLive = new Intent(this, ActionBarControlScrollViewActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), toLive, 0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { notification = new Notification.Builder(this).setContentTitle("Time to Check the new Show!") .setContentInfo("").setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_VIBRATE) .setAutoCancel(true).setOnlyAlertOnce(true) // .setTicker("Show running!") // .addAction(R.mipmap.ic_launcher, "View", pIntent) .build();//from www. ja va 2 s. co m } NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_AUTO_CANCEL; NM.notify(0, notification); }
From source file:com.bluros.updater.service.UpdateCheckService.java
private void recordAvailableUpdates(LinkedList<UpdateInfo> availableUpdates, Intent finishedIntent) { if (availableUpdates == null) { sendBroadcast(finishedIntent);/*from w ww . ja v a 2 s . c o m*/ return; } // Store the last update check time and ensure boot check completed is true Date d = new Date(); PreferenceManager.getDefaultSharedPreferences(UpdateCheckService.this).edit() .putLong(Constants.LAST_UPDATE_CHECK_PREF, d.getTime()) .putBoolean(Constants.BOOT_CHECK_COMPLETED, true).apply(); int realUpdateCount = finishedIntent.getIntExtra(EXTRA_REAL_UPDATE_COUNT, 0); UpdateApplication app = (UpdateApplication) getApplicationContext(); // Write to log Log.i(TAG, "The update check successfully completed at " + d + " and found " + availableUpdates.size() + " updates (" + realUpdateCount + " newer than installed)"); if (realUpdateCount != 0 && !app.isMainActivityActive()) { // There are updates available // The notification should launch the main app Intent i = new Intent(this, UpdatesSettings.class); i.putExtra(UpdatesSettings.EXTRA_UPDATE_LIST_UPDATED, true); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_ONE_SHOT); Resources res = getResources(); String text = res.getQuantityString(R.plurals.not_new_updates_found_body, realUpdateCount, realUpdateCount); // Get the notification ready NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_system_update).setWhen(System.currentTimeMillis()) .setTicker(res.getString(R.string.not_new_updates_found_ticker)) .setContentTitle(res.getString(R.string.not_new_updates_found_title)).setContentText(text) .setContentIntent(contentIntent).setLocalOnly(true).setAutoCancel(true); LinkedList<UpdateInfo> realUpdates = new LinkedList<UpdateInfo>(); for (UpdateInfo ui : availableUpdates) { if (ui.isNewerThanInstalled()) { realUpdates.add(ui); } } Collections.sort(realUpdates, new Comparator<UpdateInfo>() { @Override public int compare(UpdateInfo lhs, UpdateInfo rhs) { /* sort by date descending */ long lhsDate = lhs.getDate(); long rhsDate = rhs.getDate(); if (lhsDate == rhsDate) { return 0; } return lhsDate < rhsDate ? 1 : -1; } }); NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(builder) .setBigContentTitle(text); int added = 0, count = realUpdates.size(); for (UpdateInfo ui : realUpdates) { if (added < EXPANDED_NOTIF_UPDATE_COUNT) { inbox.addLine(ui.getName()); added++; } } if (added != count) { inbox.setSummaryText( res.getQuantityString(R.plurals.not_additional_count, count - added, count - added)); } builder.setStyle(inbox); builder.setNumber(availableUpdates.size()); if (count == 1) { i = new Intent(this, DownloadReceiver.class); i.setAction(DownloadReceiver.ACTION_START_DOWNLOAD); i.putExtra(DownloadReceiver.EXTRA_UPDATE_INFO, (Parcelable) realUpdates.getFirst()); PendingIntent downloadIntent = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_tab_download, res.getString(R.string.not_action_download), downloadIntent); } // Trigger the notification NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(R.string.not_new_updates_found_title, builder.build()); } sendBroadcast(finishedIntent); }
From source file:android.example.com.squawker.fcm.SquawkFirebaseMessageService.java
/** * Create and show a simple notification containing the received FCM message * * @param data Map which has the message data in it *//*from w ww . j a va 2 s . c om*/ private void sendNotification(Map<String, String> data) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Create the pending intent to launch the activity PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String author = data.get(JSON_KEY_AUTHOR); String message = data.get(JSON_KEY_MESSAGE); // If the message is longer than the max number of characters we want in our // notification, truncate it and add the unicode character for ellipsis if (message.length() > NOTIFICATION_MAX_CHARACTERS) { message = message.substring(0, NOTIFICATION_MAX_CHARACTERS) + "\u2026"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_duck) .setContentTitle(String.format(getString(R.string.notification_message), author)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;/*from ww w . jav a 2 s . c o m*/ if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:com.justmoon.glass.bitcoin.price.BitcoinPriceService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mLiveCard == null) { Log.d(TAG, "Publishing LiveCard"); mLiveCard = mTimelineManager.getLiveCard(LIVE_CARD_ID); // Keep track of the callback to remove it before unpublishing. //mCallback = new PriceDrawer(this); //mLiveCard.enableDirectRendering(true).getSurfaceHolder().addCallback(mCallback); mViews = new RemoteViews(getPackageName(), R.layout.card_price); RetrievePriceTask get = new RetrievePriceTask(); get.execute();/*from w ww .ja v a 2s. c o m*/ mViews.setTextViewText(R.id.price, "???"); mLiveCard.setViews(mViews); mLiveCard.setNonSilent(true); Intent menuIntent = new Intent(this, MenuActivity.class); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); mLiveCard.publish(); Log.d(TAG, "Done publishing LiveCard"); } else { // TODO(alainv): Jump to the LiveCard when API is available. } return START_STICKY; }
From source file:luan.com.flippit.GcmIntentService.java
private void extraDialog(String msg, String extraFilename, String extraType) { Log.i(MyActivity.TAG, getClass().getName() + ": " + "Extra notification."); String url = msg;/*from ww w. j ava 2 s . c om*/ Intent intentWeb = new Intent(Intent.ACTION_VIEW); intentWeb.setData(Uri.parse(url)); PendingIntent pendingWeb = PendingIntent.getActivity(mContext, 0, intentWeb, PendingIntent.FLAG_UPDATE_CURRENT); Intent intentCopy = new Intent(mContext, CopyService.class); intentCopy.putExtra("msg", msg); PendingIntent pendingCopy = PendingIntent.getService(mContext, 0, intentCopy, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = GeneralUtilities.createNotificationBuilder(mContext); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setTicker("Rich message") .addAction(R.drawable.send_white, "Open", pendingWeb) .addAction(R.drawable.copy_white, "Copy", pendingCopy).setContentText("Rich message"); mNotificationManager.cancel(1); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); UpdateHistory updateHistory = new UpdateHistory(); updateHistory.updateHistory(mContext); }
From source file:com.amaze.carbonfilemanager.services.ExtractService.java
@Override public int onStartCommand(Intent intent, int flags, final int startId) { Bundle b = new Bundle(); String file = intent.getStringExtra(KEY_PATH_ZIP); String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT); if (extractPath != null) { // a custom dynamic path to extract files to epath = extractPath;/*from w ww. ja va2s . c o m*/ } else { epath = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_PATH_EXTRACT, file); } mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); entries = intent.getStringArrayListExtra(KEY_ENTRIES_ZIP); b.putString(KEY_PATH_ZIP, file); totalSize = getTotalSize(file); progressHandler = new ProgressHandler(1, totalSize); progressHandler.setProgressListener(new ProgressHandler.ProgressListener() { @Override public void onProgressed(String fileName, int sourceFiles, int sourceProgress, long totalSize, long writtenSize, int speed) { publishResults(startId, fileName, sourceFiles, sourceProgress, totalSize, writtenSize, speed, false); } }); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mBuilder = new NotificationCompat.Builder(cd); mBuilder.setContentIntent(pendingIntent); mBuilder.setContentTitle(getResources().getString(R.string.extracting)) .setContentText(new File(file).getName()).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp); startForeground(Integer.parseInt("123" + startId), mBuilder.build()); new DoWork().execute(b); return START_STICKY; }