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.bakhtiyor.android.tumblr.TumblrService.java
private void showUploadingNotification(int id) { long when = System.currentTimeMillis(); Notification notification = new Notification(R.drawable.icon, APP_TITLE, when); Intent notificationIntent = new Intent(this, TumblrService.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(getApplicationContext(), APP_TITLE, "Uploading ...", contentIntent); notificationManager.notify(id, notification); }
From source file:net.networksaremadeofstring.rhybudd.WriteNFCActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BugSenseHandler.initAndStartSession(WriteNFCActivity.this, "44a76a8c"); setContentView(R.layout.write_tag_activity); try {/* w w w . j av a 2s.co m*/ getActionBar().setSubtitle(getString(R.string.NFCTitle)); getActionBar().setDisplayHomeAsUpEnabled(true); } catch (Exception gab) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", gab); } //Quick test try { UID = getIntent().getExtras().getString(PAYLOAD_UID).replace("/zport/dmd/Devices/", ""); aaRecord = NdefRecord.createApplicationRecord("net.networksaremadeofstring.rhybudd"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { //idRecord = NdefRecord.createExternal("rhybudd:tag", "z", UID.getBytes(Charset.forName("US-ASCII"))); idRecord = NdefRecord.createMime("application/vnd.rhybudd.device", UID.getBytes()); } else { idRecord = NdefRecord.createUri("rhybudd://" + UID); } ((TextView) findViewById(R.id.SizesText)).setText("This payload is " + (aaRecord.toByteArray().length + idRecord.toByteArray().length) + " bytes.\n\nAn ultralight can store up to 46 bytes.\nAn Ultralight C or NTAG203 can store up to 137 bytes.\nDespite the name a 1K can only store up to 716 bytes."); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", e); try { Toast.makeText(this, "Sorry there was error parsing the passed UID, we cannot continue.", Toast.LENGTH_SHORT).show(); } catch (Exception t) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", t); } finish(); } try { mAdapter = NfcAdapter.getDefaultAdapter(this); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate getDefaultAdapter", e); mAdapter = null; } try { pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate pendingIntent", e); } IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndef.addDataType("*/*"); /* Handles all MIME based dispatches. You should specify only the ones that you need. */ } catch (IntentFilter.MalformedMimeTypeException e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", e); throw new RuntimeException("fail", e); } try { IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); intentFiltersArray = new IntentFilter[] { ndef, td }; techListsArray = new String[][] { new String[] { NfcF.class.getName(), NfcA.class.getName(), Ndef.class.getName(), NdefFormatable.class.getName() } }; } catch (Exception e) { BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate IntentFilter", e); } CreateHandlers(); }
From source file:net.bible.service.device.ProgressNotificationManager.java
/** find the Progress object in our map to the associated Notifications * //from ww w .ja v a 2s.c o m * @param prog * @return */ private Notification findOrCreateNotification(Progress prog) { Notification notification = progressMap.get(prog); if (notification == null) { Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode()); // configure the intent Intent intent = new Intent(BibleApplication.getApplication(), ProgressStatus.class); final PendingIntent pendingIntent = PendingIntent.getActivity(BibleApplication.getApplication(), 0, intent, 0); notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME, R.layout.progress_notification); notification.contentIntent = pendingIntent; notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys); notification.contentView.setTextViewText(R.id.status_text, ""); notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false); progressMap.put(prog, notification); androidNotificationManager.notify(prog.hashCode(), notification); } return notification; }
From source file:com.example.android.wearable.mjpegviewwear.MainActivity.java
@Override public void onCreate(Bundle b) { super.onCreate(b); LOGD(TAG, "onCreate"); setContentView(R.layout.main_activity); mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.running)) .setOngoing(true);/* w w w.j a va 2 s .c o m*/ Intent resultIntent = new Intent(this, MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); // for MJPEG View SharedPreferences preferences = getSharedPreferences("SAVED_VALUES", MODE_PRIVATE); mWidth = preferences.getInt("width", mWidth); mHeight = preferences.getInt("height", mHeight); mIp_ad1 = preferences.getInt("ip_ad1", mIp_ad1); mIp_ad2 = preferences.getInt("ip_ad2", mIp_ad2); mIp_ad3 = preferences.getInt("ip_ad3", mIp_ad3); mIp_ad4 = preferences.getInt("ip_ad4", mIp_ad4); mIp_port = preferences.getInt("ip_port", mIp_port); mIp_command = preferences.getString("ip_command", mIp_command); mFrameSkip = preferences.getInt("frameSkip", mFrameSkip); StringBuilder sb = new StringBuilder(); String s_http = "http://"; String s_dot = "."; String s_colon = ":"; String s_slash = "/"; sb.append(s_http); sb.append(mIp_ad1); sb.append(s_dot); sb.append(mIp_ad2); sb.append(s_dot); sb.append(mIp_ad3); sb.append(s_dot); sb.append(mIp_ad4); sb.append(s_colon); sb.append(mIp_port); sb.append(s_slash); sb.append(mIp_command); mURL = new String(sb); mMv = (MjpegView) findViewById(R.id.mv); if (mMv != null) { mMv.setResolution(mWidth, mHeight); mMv.setFrameSkip(mFrameSkip); } setTitle(R.string.title_connecting); new DoRead().execute(mURL); }
From source file:de.wikilab.android.friendica01.FileUploadService.java
private void showSuccessMsg(Context ctx) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); //Instantiate the Notification: int icon = R.drawable.arrow_up; CharSequence tickerText = "Upload succeeded!"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; /*/*from w ww. ja v a 2s . c om*/ //TODO!!! //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); CharSequence contentTitle = "Upload successful, click to show details!"; CharSequence contentText = targetFilename; Intent notificationIntent = new Intent(this, FilePreview.class); Bundle b = new Bundle(); b.putInt("cid", clipId); notificationIntent.putExtras(b); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); */ //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); notification.setLatestEventInfo(context, tickerText, "Click to dismiss", nullIntent); //Pass the Notification to the NotificationManager: mNotificationManager.notify(UPLOAD_SUCCESS_ID, notification); //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show(); }
From source file:cc.softwarefactory.lokki.android.services.LocationService.java
private void setNotificationAndForeground() { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle("Lokki"); notificationBuilder.setContentText("Running..."); notificationBuilder.setSmallIcon(R.drawable.ic_stat_notify); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); notificationBuilder.setContentIntent(contentIntent); startForeground(NOTIFICATION_SERVICE, notificationBuilder.build()); }
From source file:com.imobilize.blogposts.gcmnotifications.GcmIntentService.java
private void sendNotification(String articleDataString) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); JSONObject articleDataJson = null;//from www.j av a 2 s . c o m try { articleDataJson = new JSONObject(articleDataString); } catch (JSONException e) { e.printStackTrace(); } Intent intentForArticleActivity = new Intent(this, ArticleActivity.class); String notificationMessage = null; try { intentForArticleActivity.putExtra(Constants.ARTICLE_TITLE, articleDataJson.getString("title")); intentForArticleActivity.putExtra(Constants.ARTICLE_METADATA, "Posted by " + articleDataJson.getString("author") + " on " + articleDataJson.getString("creationDate")); intentForArticleActivity.putExtra(Constants.ARTICLE_CONTENT, articleDataJson.getString("content")); intentForArticleActivity.putExtra(Constants.ARTICLE_KEY, articleDataJson.getString("key")); notificationMessage = "Read our new article from category " + articleDataJson.getString("categories") + " called '" + articleDataJson.getString("title") + "'"; } catch (JSONException e) { e.printStackTrace(); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intentForArticleActivity, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_gcm) .setAutoCancel(true).setContentTitle("BLOGPOSTS") .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMessage)) .setContentText(notificationMessage); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java
/** * Adds an onclick handler to the notification *///from www . j a va 2 s . c om protected NotificationCompat.Builder setClickEvent(NotificationCompat.Builder builder) { int requestCode = new Random().nextInt(); Context context = getApplicationContext(); String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT); return builder.setContentIntent(contentIntent); }
From source file:com.bellman.bible.service.device.ProgressNotificationManager.java
/** * find the Progress object in our map to the associated Notifications * * @param prog/* w w w . j a va 2s . co m*/ * @return */ private Notification findOrCreateNotification(Progress prog) { Notification notification = progressMap.get(prog); if (notification == null) { Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode()); // configure the intent Intent intent = new Intent(CurrentActivityHolder.getInstance().getApplication(), ProgressStatus.class); final PendingIntent pendingIntent = PendingIntent .getActivity(CurrentActivityHolder.getInstance().getApplication(), 0, intent, 0); notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME, R.layout.progress_notification); notification.contentIntent = pendingIntent; notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys); notification.contentView.setTextViewText(R.id.status_text, ""); notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false); progressMap.put(prog, notification); androidNotificationManager.notify(prog.hashCode(), notification); } return notification; }