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.microsoft.graph.connect.AuthenticationManager.java
/** * Starts the authorization flow, which continues to net.openid.appauth.RedirectReceiverActivity * and then to ConnectActivity//from w ww .j a v a 2s.com */ public void startAuthorizationFlow() { Intent intent = new Intent(mContextActivity, ConnectActivity.class); PendingIntent redirectIntent = PendingIntent.getActivity(mContextActivity, mAuthorizationRequest.hashCode(), intent, 0); mAuthorizationService.performAuthorizationRequest(mAuthorizationRequest, redirectIntent, mAuthorizationService.createCustomTabsIntentBuilder() .setToolbarColor(getColorCompat(R.color.colorPrimary)).build()); }
From source file:android.demo.amitrai.gcmdemo.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w w w .jav a 2s . c o m */ private void sendNotification(String message) { Intent intent = new Intent(this, Splash.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.message).setContentTitle("GCM Message").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:de.grobox.blitzmail.SendActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // before doing anything show notification about sending process mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait)) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); // Sets an activity indicator for an operation of indeterminate length mBuilder.setProgress(0, 0, true);/*from w ww. java2 s. com*/ // Create Pending Intent notifyIntent = new Intent(this, NotificationHandlerActivity.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); // Issues the notification mNotifyManager.notify(0, mBuilder.build()); Properties prefs; try { prefs = getPrefs(); } catch (Exception e) { String msg = e.getMessage(); Log.i("SendActivity", "ERROR: " + msg, e); if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) { msg = getString(R.string.error_decrypt); } showError(msg); return; } // get and handle Intent Intent intent = getIntent(); String action = intent.getAction(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); //String email = intent.getStringExtra(Intent.EXTRA_EMAIL); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); String cc = intent.getStringExtra(Intent.EXTRA_CC); String bcc = intent.getStringExtra(Intent.EXTRA_BCC); // Check for empty content if (subject == null && text != null) { // cut all characters from subject after the 128th subject = text.substring(0, (text.length() < 128) ? text.length() : 128); // remove line breaks from subject subject = subject.replace("\n", " ").replace("\r", " "); } else if (subject != null && text == null) { text = subject; } else if (subject == null && text == null) { Log.e("Instant Mail", "Did not send mail, because subject and body empty."); showError(getString(R.string.error_no_body_no_subject)); return; } // create JSON object with mail information mMail = new JSONObject(); try { mMail.put("id", String.valueOf(new Date().getTime())); mMail.put("body", text); mMail.put("subject", subject); mMail.put("cc", cc); mMail.put("bcc", bcc); } catch (JSONException e) { e.printStackTrace(); } // remember mail for later MailStorage.saveMail(this, mMail); // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } else if (action.equals("BlitzMailReSend")) { try { mMail = new JSONObject(intent.getStringExtra("mail")); } catch (JSONException e) { e.printStackTrace(); } // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } finish(); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrBillTask.java
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException { AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google"); String accountName = MyPreferences.getFlowzrAccount(context); if (accountName == null) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder mNotifyBuilder = new NotificationCompat.Builder(context); mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText(context.getString(R.string.flowzr_choose_account)); nm.notify(0, mNotifyBuilder.build()); Log.i("Flowzr", "account name is null"); throw new ImportExportException(R.string.flowzr_choose_account); }//from w w w . ja v a2s .c om Account useCredential = null; for (int i = 0; i < accounts.length; i++) { if (accountName.equals(((android.accounts.Account) accounts[i]).name)) { useCredential = accounts[i]; } } AccountManager.get(context).getAuthToken(useCredential, "ah", null, (Activity) context, new GetAuthTokenCallback(), null); return null; }
From source file:MainActivity.java
private void showNotification() { Intent activityIntent = new Intent(this, MainActivity.class); activityIntent.setAction(ACTION_STOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0); final Builder notificationBuilder = new Builder(this).setContentTitle("Flashlight") .setContentText("Press to turn off the flashlight").setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentIntent(pendingIntent).setVibrate(new long[] { DEFAULT_VIBRATE }) .setPriority(PRIORITY_MAX);/*from www. j a va2 s . co m*/ NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:asia.covisoft.goom.gcm.GoOmGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w ww. ja v a 2 s .co m */ private void sendNotification(String title, 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(title).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.github.secondsun.catfactsdemo.networking.CatFactFetcherService.java
protected void onHandleIntent(Intent intent) { if (intent.getBooleanExtra(LOAD, false)) { CharSequence contentText; if (data.size() > 0) { contentText = "Data Loaded"; } else {//from w w w .ja v a 2 s .co m contentText = "Awaiting Data Load"; } Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText(contentText).setContentIntent(pendingIntent) .build(); startForeground(ONGOING_NOTIFICATION_ID, notification); } else if (intent.getBooleanExtra(UNLOAD, false)) { stopForeground(true); } else { if (intent.getBooleanExtra(RESET, false)) { data.clear(); Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText("Awaiting Data Load") .setContentIntent(pendingIntent).build(); startForeground(ONGOING_NOTIFICATION_ID, notification); } if (data.size() == 0) { try { Thread.sleep(Constants.DELAY); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(Constants.CAT_FACTS_URL).build(); Response response = client.newCall(request).execute(); JSONObject responseJson = new JSONObject(response.body().string()); JSONArray facts = responseJson.getJSONArray("facts"); ArrayList<String> toReturn = new ArrayList<>(facts.length()); for (int i = 0; i < facts.length(); i++) { toReturn.add(facts.getString(i)); } data = toReturn; } catch (InterruptedException | IOException | JSONException e) { ArrayList<String> toReturn = new ArrayList<>(); toReturn.add("Error:" + e.getMessage()); data = toReturn; } } Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText("Data Available") .setContentIntent(pendingIntent).build(); startForeground(ONGOING_NOTIFICATION_ID, notification); sendData(); } }
From source file:be.ppareit.swiftp.gui.FsNotification.java
private void setupNotification(Context context) { Cat.d("Setting up the notification"); // Get NotificationManager reference String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); // get ip address InetAddress address = FsService.getLocalInetAddress(); if (address == null) { Cat.w("Unable to retrieve the local ip address"); return;/*from www . jav a 2 s . c o m*/ } String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/"; // Instantiate a Notification int icon = R.mipmap.notification; CharSequence tickerText = String.format(context.getString(R.string.notification_server_starting), iptext); long when = System.currentTimeMillis(); // Define Notification's message and Intent CharSequence contentTitle = context.getString(R.string.notification_title); CharSequence contentText = String.format(context.getString(R.string.notification_text), iptext); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int stopIcon = android.R.drawable.ic_menu_close_clear_cancel; CharSequence stopText = context.getString(R.string.notification_stop_text); Intent stopIntent = new Intent(FsService.ACTION_STOP_FTPSERVER); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_ONE_SHOT); int preferenceIcon = android.R.drawable.ic_menu_preferences; CharSequence preferenceText = context.getString(R.string.notif_settings_text); Intent preferenceIntent = new Intent(context, MainActivity.class); preferenceIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent preferencePendingIntent = PendingIntent.getActivity(context, 0, preferenceIntent, 0); Notification notification = new NotificationCompat.Builder(context).setContentTitle(contentTitle) .setContentText(contentText).setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(tickerText).setWhen(when).setOngoing(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX) .addAction(stopIcon, stopText, stopPendingIntent) .addAction(preferenceIcon, preferenceText, preferencePendingIntent).setShowWhen(false).build(); // Pass Notification to NotificationManager nm.notify(NOTIFICATION_ID, notification); Cat.d("Notification setup done"); }
From source file:com.Trigger.SmsSendingPlugin.java
private void sendSMS(String phoneNumber, String message) { PendingIntent sentIntent = PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(), 0); smsManager.sendTextMessage(phoneNumber, null, message, sentIntent, null); }
From source file:app.com.locationfetch.GeofenceTransitionsIntentService.java
private void sendNotification(String s) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Location Push").setContentText(s) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }