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.codeskraps.lolo.misc.Utils.java
public static PendingIntent getOnTouchIntent(Context context) { PendingIntent pendingIntent = null;// w w w . j a v a 2 s . c o m Intent intent = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int onClick = Integer.parseInt(prefs.getString(Constants.ONCLICK, "0")); switch (onClick) { case 0: intent = new Intent("com.codeskraps.lol.DO_NOTHING"); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 1: intent = new Intent(context, TweetsFeedActivity.class); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 2: intent = new Intent(); intent.setAction(Constants.BROADCAST_RECEIVER); pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 3: intent = new Intent(context, PrefsActivity.class); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 4: intent = new Intent(Intent.ACTION_VIEW); String url = prefs.getString(Constants.EURL, context.getString(R.string.prefsURL_default)); if (!url.startsWith("http://")) url = "http://" + url; intent.setData(Uri.parse(url)); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; } return pendingIntent; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String mimeType = obj.optString(MIME_TYPE); Uri uri = Uri.parse(obj.optString(URI)); if (fileAvailable(mimeType, uri)) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.addCategory(Intent.CATEGORY_DEFAULT); i.setType(mimeType);// w w w . j a v a 2 s. com i.setData(uri); i.putExtra(Intent.EXTRA_TEXT, uri); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi", mimeType + " " + uri, contentIntent); } else { Log.w(TAG, "Received file, failed to handle: " + uri); } }
From source file:org.openbitcoinwidget.WidgetProvider.java
private static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) { WidgetPreferences preferences = PreferencesActivity.getWidgetPreferences(context, appWidgetId); if (preferences == null) { // Don't do anything unless the rate service has been chosen. // Show a "please remove this widget and add a new one" appWidgetManager.updateAppWidget(appWidgetId, new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me)); return;/* w w w . j ava2s . c o m*/ } boolean isOnLockScreen = isWidgetShownOnLockScreen(appWidgetManager, appWidgetId); RemoteViews views; if (isOnLockScreen) { views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_lock_screen); } else { views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); } Intent clickIntent = new Intent(context, GraphPopupActivity.class); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE // cached intent will be used for all widget instances! PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0); views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent); views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName()); DataOpenHelper dbHelper = new DataOpenHelper(context); TickerData prevData = dbHelper.getLastTickerData(preferences); TickerData newData; String latestQuote = getLatestQuote(preferences); if (latestQuote != null && !latestQuote.equals("")) { newData = preferences.getRateService().parseJSON(latestQuote); newData.setCurrencyConversion(preferences.getCurrencyConversion()); storeLastValueIfNotNull(dbHelper, newData); updateViews(views, prevData, newData, preferences); } else if (prevData != null) { newData = prevData; updateViews(views, prevData, newData, preferences); } else { updateViewsWithError(views, preferences); } appWidgetManager.updateAppWidget(appWidgetId, views); }
From source file:com.otaupdater.utils.RomInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.ROM_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_ROM_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_rom)); builder.setTicker(ctx.getString(R.string.notif_text_rom)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.ROM_NOTIF_ID, builder.build()); }
From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);// www .j a v a 2s . co m String message = intent.getStringExtra("message"); String email = intent.getStringExtra("email"); String latitude = intent.getStringExtra("latitude"); String longitude = intent.getStringExtra("longitude"); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!") .setContentText("Alguem precisa de um " + message); Intent resultIntent = null; try { if (isLoggedIn()) { resultIntent = new Intent(context, LoggedInActivity.class); } else { resultIntent = new Intent(context, LoginActivity.class); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.kasoft.pushnot.GcmIntentService.java
private void sendNotification(String msg, String title, String form) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent appMainIntent = new Intent(getApplicationContext(), MainActivity.class); appMainIntent.putExtra("title", title); appMainIntent.putExtra("form", form); //appMainIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); appMainIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, appMainIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(form)).setContentText(form); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java
@Override protected void onHandleIntent(Intent intent) { // initialize // extract details Server server = intent.getParcelableExtra("server"); String directory = intent.getStringExtra("directory"); String filename = intent.getStringExtra("filename"); // get the json parser from the application JsonParser jsonParser = new JsonParser(); // start the ball rolling... final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(String.format(getString(R.string.notif_ticker), filename)) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large)) .setSmallIcon(R.drawable.ic_stat_notif_small) .setContentTitle(String.format(getString(R.string.notif_title), filename)) .setContentText(getString(R.string.notif_content_init)) // to avoid NPE on android 2.x where content intent is required // set an empty content intent .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true); // notify user that upload is starting mgr.notify(NOTIFICATION_ID, builder.build()); // reset ticker for any subsequent notifications builder.setTicker(null);//from w ww .j ava 2 s. c o m AbstractHttpClient client = CustomHTTPClient.getHttpClient(); // enable digest authentication if (server.getUsername() != null && !server.getUsername().equals("")) { Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); client.getCredentialsProvider().setCredentials( new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials); } final File file = new File(directory, filename); final long length = file.length(); try { CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, new CustomMultiPartEntity.ProgressListener() { @Override public void transferred(long num) { // calculate percentage //System.out.println("transferred: " + num); int progress = (int) ((num * 100) / length); builder.setContentText(String.format(getString(R.string.notif_content), progress)); mgr.notify(NOTIFICATION_ID, builder.build()); } }); multipart.addPart(file.getName(), new FileBody(file)); HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content"); httpRequest.setEntity(multipart); HttpResponse serverResponse = client.execute(httpRequest); BasicResponseHandler handler = new BasicResponseHandler(); JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject(); if (!reply.has("outcome")) { throw new RuntimeException(getString(R.string.invalid_response)); } else { // remove the 'upload in-progress' notification mgr.cancel(NOTIFICATION_ID); String outcome = reply.get("outcome").getAsString(); if (outcome.equals("success")) { String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString(); Intent resultIntent = new Intent(this, UploadCompletedActivity.class); // populate it resultIntent.putExtra("server", server); resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE); resultIntent.putExtra("filename", filename); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // the notification id for the 'completed upload' notification // each completed upload will have a different id int notifCompletedID = (int) System.currentTimeMillis(); builder.setContentTitle(getString(R.string.notif_title_uploaded)) .setContentText(String.format(getString(R.string.notif_content_uploaded), filename)) .setContentIntent( // we set the (2nd param request code to completedID) // see http://tinyurl.com/kkcedju PendingIntent.getActivity(this, notifCompletedID, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setAutoCancel(true).setOngoing(false); mgr.notify(notifCompletedID, builder.build()); } else { JsonElement elem = reply.get("failure-description"); if (elem.isJsonPrimitive()) { throw new RuntimeException(elem.getAsString()); } else if (elem.isJsonObject()) throw new RuntimeException( elem.getAsJsonObject().get("domain-failure-description").getAsString()); } } } catch (Exception e) { builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false); mgr.notify(NOTIFICATION_ID, builder.build()); } }
From source file:me.tassoevan.cordova.ForegroundService.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") private Notification makeNotification() { JSONObject settings = BackgroundPlugin.settings; Context context = getApplicationContext(); String pkgName = context.getPackageName(); Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgName); Notification.Builder notification = new Notification.Builder(context) .setContentTitle(settings.optString("title", "")).setContentText(settings.optString("text", "")) .setTicker(settings.optString("ticker", "")).setOngoing(true).setSmallIcon(getIconResId()); if (intent != null && settings.optBoolean("resume")) { PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setContentIntent(contentIntent); }/*from ww w .ja v a 2s. com*/ if (Build.VERSION.SDK_INT < 16) { return notification.getNotification(); } else { return notification.build(); } }
From source file:mai.whack.StickyNotesActivity.java
/** Called when the activity is first created. */ @Override//from w w w . j av a 2 s.c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); setContentView(R.layout.main); findViewById(R.id.write_tag).setOnClickListener(mTagWriter); // Handle all of our received NFC intents in this activity. mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // Intent filters for reading a note from a tag or exchanging over p2p. IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndefDetected.addDataType("text/plain"); } catch (MalformedMimeTypeException e) { } mNdefExchangeFilters = new IntentFilter[] { ndefDetected }; // Intent filters for writing to a tag IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mWriteTagFilters = new IntentFilter[] { tagDetected }; }
From source file:com.otaupdater.utils.KernelInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.KERNEL_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_KERNEL_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_kernel)); builder.setTicker(ctx.getString(R.string.notif_text_kernel)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.KERNEL_NOTIF_ID, builder.build()); }