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.keithandthegirl.services.download.DownloadService.java
@SuppressWarnings("deprecation") private void sendNotification(String description) { mContentTitle = description;/*ww w . ja va 2s . c o m*/ long when = System.currentTimeMillis(); notificationId = (int) when; mNotification = new Notification(android.R.drawable.stat_sys_download, getResources().getString(R.string.app_name), when); Intent notificationIntent = new Intent(); mContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mNotification.setLatestEventInfo(this, getResources().getString(R.string.app_name), mContentTitle, mContentIntent); mNotification.flags = Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(notificationId, mNotification); }
From source file:ca.mcgill.hs.serv.LogFileUploaderService.java
@Override public synchronized void onStart(final Intent intent, final int startId) { // Update the file list updateFileList();/*from w w w.j ava 2 s .c o m*/ // If there are no files, return. if (fileList.size() == 0 && !started) { makeToast(getResources().getString(R.string.uploader_no_new_files), Toast.LENGTH_SHORT); return; } // If it was already started, return. Else, continue. if (started) { return; } // At this point we consider the service to be started. started = true; registerReceiver(wifiOnlyPrefChanged, new IntentFilter(WIFI_ONLY_CHANGED_INTENT)); registerReceiver(autoPrefChanged, new IntentFilter(AUTO_UPLOAD_CHANGED_INTENT)); wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiMgr.getConnectionInfo(); // Register completion receiver registerReceiver(completionReceiver, new IntentFilter(UPLOAD_COMPLETE_INTENT)); // Connect to a network setUpConnection(); notificationMgr = (NotificationManager) getSystemService(NOTIFICATION_STRING); notificationMgr.cancel(NOTIFICATION_ID); final int icon = R.drawable.notification_icon; final String tickerText = getResources().getString(R.string.notification_ticker); final String contentTitle = getResources().getString(R.string.notification_upload_title); final String contentText = getResources().getString(R.string.notification_upload_text); final Notification n = new Notification(icon, tickerText, System.currentTimeMillis()); final Intent i = new Intent(this, HSService.class); n.setLatestEventInfo(this, contentTitle, contentText, PendingIntent.getActivity(this.getBaseContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); notificationMgr.notify(NOTIFICATION_ID, n); filesUploaded = 0; uploadFiles(); }
From source file:it.mb.whatshare.SendToGCMActivity.java
@SuppressWarnings("deprecation") private void showNotification(int sharedWhat, boolean sharedViaWhatsapp) { String title = getString(R.string.whatshare); Intent onNotificationDiscarded = new Intent(this, SendToGCMActivity.class); PendingIntent notificationIntent = PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0); Notification notification = null; int notificationIcon = sharedViaWhatsapp ? R.drawable.notification_icon : R.drawable.whatshare_logo_notification; int notificationNumber = notificationCounter.incrementAndGet(); String content = getString(R.string.share_success, getString(sharedWhat), outboundDevice.type); // @formatter:off NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(notificationIcon, 0) .setContentTitle(title).setContentText(content).setTicker(content) .setContentIntent(notificationIntent) .setDeleteIntent(PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0)) .setNumber(notificationNumber); // @formatter:on if (Build.VERSION.SDK_INT > 15) { notification = buildForJellyBean(builder); } else {// ww w. j a va2 s . com notification = builder.getNotification(); } notification.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // cancel previous notification to clean up garbage in the status bar nm.cancel(notificationNumber - 1); nm.notify(notificationNumber, notification); }
From source file:org.linphone.LinphoneService.java
@Override public void onCreate() { super.onCreate(); theLinphone = this; // Dump some debugging information to the logs Hacks.dumpDeviceInformation();//from w ww . java 2 s.c o m addCallListner(); // tryTogetLastReceive(); // tryTogetLastRequest(); tryKeepOnline(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis()); mNotification.iconLevel = IC_LEVEL_ORANGE; mNotification.flags |= Notification.FLAG_ONGOING_EVENT; Intent notificationIntent = new Intent(this, MainViewActivity.class); mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent); mNotificationManager.notify(NOTIFICATION_ID, mNotification); mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE)); mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); try { copyAssetsFromPackage(); mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC, LINPHONE_FACTORY_RC, null); mLinphoneCore.setPlaybackGain(3); mLinphoneCore.setRing(null); try { initFromConf(); } catch (LinphoneException e) { Log.w(TAG, "no config ready yet"); } TimerTask lTask = new TimerTask() { @Override public void run() { mLinphoneCore.iterate(); } }; mTimer.scheduleAtFixedRate(lTask, 0, 100); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); lFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mKeepAliveMgrReceiver, lFilter); } catch (Exception e) { Log.e(TAG, "Cannot start linphone", e); } }
From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java
private void sendSMS(String phoneNumber, String message) { PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, IntroductionActivity.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, pi, null); }
From source file:jieehd.villain.updater.checkInBackground.java
public void notifyUser() { final NotificationManager nm; nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "Villain Updater"; CharSequence message = "New Updates!"; PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.updates, "New updates!", System.currentTimeMillis()); notif.setLatestEventInfo(mContext, from, message, contentIntent); nm.notify(1, notif);/*from w ww . j a v a 2 s . co m*/ }
From source file:org.ttrssreader.utils.Utils.java
@SuppressWarnings("deprecation") public static Notification buildNotification(Context context, int icon, CharSequence ticker, CharSequence title, CharSequence text, boolean autoCancel, Intent intent) { Notification notification = null; PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); try {//from w w w.j ava 2s. co m Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(icon); builder.setTicker(ticker); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle(title); builder.setContentText(text); builder.setContentIntent(pendingIntent); builder.setAutoCancel(autoCancel); if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) notification = builder.getNotification(); else notification = builder.build(); } catch (Exception re) { Log.e(TAG, "Exception while building notification. Does your device propagate the right API-Level? (" + Build.VERSION.SDK_INT + ")", re); } return notification; }
From source file:com.mobiperf.MeasurementScheduler.java
/** * Create notification that indicates the service is running. *//*www.j a va2 s. c o m*/ private Notification createServiceRunningNotification() { // The intent to launch when the user clicks the expanded notification Intent intent = new Intent(this, SpeedometerApp.class); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // This constructor is deprecated in 3.x. But most phones still run 2.x systems Notification notice = new Notification(R.drawable.icon_statusbar, getString(R.string.notificationSchedulerStarted), System.currentTimeMillis()); notice.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; // This is deprecated in 3.x. But most phones still run 2.x systems notice.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notificationServiceRunning), pendIntent); return notice; }
From source file:com.hhunj.hhudata.ForegroundService.java
void handleCommand(Intent intent) { if (intent == null) { return;// ww w.j a va 2 s . c o m } if (ACTION_FOREGROUND.equals(intent.getAction())) { // In this sample, we'll use the same text for the ticker and the // expanded notification CharSequence text = getText(R.string.foreground_service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.stat_sample, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainTab.class), 0);// // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent); startForegroundCompat(R.string.foreground_service_started, notification); } /* * else if (ACTION_BACKGROUND.equals(intent.getAction())) { * stopForegroundCompat(R.string.foreground_service_started); } */ }
From source file:cc.softwarefactory.lokki.android.androidServices.LocationService.java
private void showArrivalNotification() { Intent showIntent = new Intent(this, BuzzActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, showIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notify).setContentTitle("GPS Child Location") .setContentText(getString(R.string.you_have_arrived)).setAutoCancel(true) .setContentIntent(contentIntent); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(42, mBuilder.build()); }