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.arisprung.tailgate.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from w w w. j av a 2 s . c o m private static void generateNotification(Context context, MessageBean message) { // Intent notificationIntent = new Intent(ctx, MainActivity.class); // PendingIntent contentIntent = PendingIntent.getActivity(ctx, // 10, notificationIntent, // PendingIntent.FLAG_CANCEL_CURRENT); // // NotificationManager nm = (NotificationManager) ctx // .getSystemService(Context.NOTIFICATION_SERVICE); // // Resources res = ctx.getResources(); // Notification.Builder builder = new Notification.Builder(ctx); // // Bitmap profile = TailGateUtility.getUserPic(message.getFaceID()); // // builder.setContentIntent(contentIntent) // .setSmallIcon(R.drawable.ic_launcher) // .setLargeIcon(profile) // .setTicker(res.getString(R.string.app_name)) // .setWhen(System.currentTimeMillis()) // .setAutoCancel(true) // .setContentTitle(message.getUserName()) // .setContentText(message.getMessage()); // Notification n = builder.build(); // // nm.notify(0, n); int icon = R.drawable.fanatic_icon_72px; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message.getMessage(), when); String name = message.getUserName(); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, name, message.getMessage(), intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.ohnemax.android.glass.doseview.CSDataSort.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mLiveCard == null) { // Get an instance of a live card mLiveCard = new LiveCard(this, LIVE_CARD_TAG); // Inflate a layout into a remote view mLiveCardView = new RemoteViews(getPackageName(), R.layout.service_doserate); // Set up the live card's action with a pending intent // to show a menu when tapped Intent menuIntent = new Intent(this, MenuActivity.class); menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); // Publish the live card mLiveCard.publish(PublishMode.REVEAL); // Queue the update text runnable mHandler.post(mUpdateLiveCardRunnable); }//from w w w . j a v a 2 s .c om return START_STICKY; }
From source file:cc.softwarefactory.lokki.android.androidServices.LocationService.java
private void setNotificationAndForeground() { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle("GPS Child Location"); 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.aware.ESM.java
@Override public void onCreate() { super.onCreate(); TAG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;/*from w w w .j a v a 2s. co m*/ DATABASE_TABLES = ESM_Provider.DATABASE_TABLES; TABLES_FIELDS = ESM_Provider.TABLES_FIELDS; CONTEXT_URIS = new Uri[] { ESM_Data.CONTENT_URI }; IntentFilter filter = new IntentFilter(); filter.addAction(ESM.ACTION_AWARE_QUEUE_ESM); registerReceiver(esmMonitor, filter); intent_ESM = new Intent(this, ESM_Queue.class); intent_ESM.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); pending_ESM = PendingIntent.getActivity(this, 0, intent_ESM, PendingIntent.FLAG_UPDATE_CURRENT); if (Aware.DEBUG) Log.d(TAG, "ESM service created!"); }
From source file:at.bitfire.davdroid.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override//from w w w . j a v a 2 s .c o m public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); /* Set class loader for iCal4j ResourceLoader this is required because the various * sync adapters (contacts, events, tasks) share the same :sync process (see AndroidManifest */ Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, WebDavCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, WebDavCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:at.maui.cheapcast.service.CheapCastService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LOG_TAG, "onStartCommand()"); Notification n = null;//from w ww. java2s .com if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Notification.Builder mBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_service) .setContentTitle("CheapCast").setContentText("Service enabled.").setOngoing(true) .addAction(R.drawable.ic_reload, getString(R.string.restart_service), PendingIntent.getBroadcast(this, 1, new Intent(Const.ACTION_RESTART), PendingIntent.FLAG_ONE_SHOT)) .addAction(R.drawable.ic_stop, getString(R.string.stop_service), PendingIntent .getBroadcast(this, 2, new Intent(Const.ACTION_STOP), PendingIntent.FLAG_ONE_SHOT)); Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); mBuilder.setContentIntent(pi); n = mBuilder.build(); } else { Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_service).setContentTitle("CheapCast") .setContentText("Service enabled.").setOngoing(true).setContentIntent(pi); n = mBuilder.getNotification(); } startForeground(1337, n); if (!mRunning) initService(); return START_STICKY; }