List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:MainActivity.java
private PendingIntent getGeofencePendingIntent() { if (mGeofencePendingIntent != null) { return mGeofencePendingIntent; }//ww w . java 2 s .c o m Intent intent = new Intent(this, GeofenceIntentService.class); return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.jackie.notifyingUser.PingService.java
private void issueNotification(String msg) { // Sets up the Snooze and Dismiss action buttons that will appear in the // expanded view of the notification. Intent dismissIntent = new Intent(this, PingService.class); dismissIntent.setAction(CommonConstants.ACTION_DISMISS); PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0); Intent snoozeIntent = new Intent(this, PingService.class); snoozeIntent.setAction(CommonConstants.ACTION_SNOOZE); PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_notification); builder.setContentTitle(getString(R.string.notification)); builder.setContentText(getString(R.string.ping)); builder.setDefaults(Notification.DEFAULT_ALL); // requires VIBRATE permission; /*/*ww w . j a v a 2 s . c o m*/ * Sets the big view "big text" style and supplies the text (the user's reminder message) * that will be displayed in the detail area of the expanded notification. * these calls are ignored by the support library for pre-5.1 devices. */ builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)); builder.addAction(R.drawable.ic_stat_dismiss, getString(R.string.dismiss), piDismiss); builder.addAction(R.drawable.ic_stat_snooze, getString(R.string.snooze), piSnooze); /* * Clicking the notification itself displays ResultActivity, which provides UI for snoozing * or dismissing the notification. * This is available through either the normal view or big view. */ Intent resultIntent = new Intent(this, ResultActivity.class); resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Because clicking the notification launches a new ("special") activity, // there's no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); // this sets the pending intent that should be fired when the user clicks the // notification. Clicking the notification launches a new activity. builder.setContentIntent(resultPendingIntent); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.notify(CommonConstants.NOTIFICATION_ID, builder.build()); }
From source file:com.mech.tech.meet.activities.scenario.MainActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from w ww.j ava 2 s. co m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.material_wala_deep_blue)); } Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent = new Intent(this, MyNotificationService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 36000 * 1000 * 2, pintent); startService(new Intent(getBaseContext(), MyNotificationService.class)); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); }
From source file:dev.datvt.cloudtracks.noti_service.NotificationUtil.java
public Notification showNotification(Track song, int curPos) { bigViews.setImageViewResource(R.id.btnNotiNext, R.drawable.btn_noti_next); bigViews.setTextViewText(R.id.notiNameMusic, song.title); remoteViews1.setImageViewResource(R.id.btnNotiNext, R.drawable.btn_noti_next); remoteViews1.setTextViewText(R.id.notiNameMusic, song.title); if (song.bpm == ToolsHelper.IS_LOCAL) { bigViews.setTextViewText(R.id.notiSingerMusic, song.license); remoteViews1.setTextViewText(R.id.notiSingerMusic, song.license); } else {//from ww w . j a va 2 s .co m bigViews.setTextViewText(R.id.notiSingerMusic, song.genre); remoteViews1.setTextViewText(R.id.notiSingerMusic, song.genre); } Intent intent = new Intent(context, MainActivity.class); position = curPos; intent.putExtra("pos", curPos); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentIntent(pIntent); notification = mBuilder.setSmallIcon(R.drawable.default_nhaccuatui).setOngoing(true) .setContent(remoteViews1).build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = bigViews; } notification.contentView = remoteViews1; Intent pauseIntent = new Intent(context, MediaPlayerService.class); if (!MediaPlayerService.isNext) { pauseIntent.setAction(ConstantHelper.ACTION_PAUSE); pauseIntent.putExtra("pause", 1); } PendingIntent ppauseIntent = PendingIntent.getService(context, 100, pauseIntent, 0); bigViews.setOnClickPendingIntent(R.id.btnNotiPlay, ppauseIntent); remoteViews1.setOnClickPendingIntent(R.id.btnNotiPlay, ppauseIntent); Intent nextIntent = new Intent(context, MediaPlayerService.class); nextIntent.setAction(ConstantHelper.ACTION_NEXT_NOTI); PendingIntent pnextIntent = PendingIntent.getService(context, 246, nextIntent, 0); bigViews.setOnClickPendingIntent(R.id.btnNotiNext, pnextIntent); remoteViews1.setOnClickPendingIntent(R.id.btnNotiNext, pnextIntent); Intent closeIntent = new Intent(context, MediaPlayerService.class); closeIntent.setAction(ConstantHelper.ACTION_CLOSE_NOTI); PendingIntent pcloseIntent = PendingIntent.getService(context, 0, closeIntent, 0); bigViews.setOnClickPendingIntent(R.id.btnNotiClose, pcloseIntent); remoteViews1.setOnClickPendingIntent(R.id.btnNotiClose, pcloseIntent); return notification; }
From source file:com.jameswolfeoliver.pigeon.Managers.NotificationsManager.java
public static void createNotificationForMessageReceived(Context context, Conversation conversation, Message message, Contact contact) { String summary = String.format(context.getString(R.string.message_notification_summary), contact.getName(), message.getBody());/*from w w w . j a va2 s .c o m*/ Intent conversationIntent = new Intent(context, ConversationActivity.class); conversationIntent.putExtra(ConversationActivity.CONVERSATION_EXTRA, conversation); String replyLabel = context.getString(R.string.message_reply); RemoteInput remoteInput = new RemoteInput.Builder(MessageReplyService.MESSAGE_TEXT_KEY).setLabel(replyLabel) .build(); Intent replyIntent = new Intent(context, MessageReplyService.class); replyIntent.putExtra(MessageReplyService.CONVERSATION_KEY, conversation); PendingIntent replyPendingIntent = PendingIntent.getService(context, 0, replyIntent, 0); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_sms, context.getString(R.string.message_reply), replyPendingIntent).addRemoteInput(remoteInput).build(); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_ONE_SHOT); Notification notification = getNotificationBuilder(context, contact.getName(), summary, message.getBody()) .setContentIntent(pendingIntent).addAction(replyAction).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(CONVERSATION_TAG, conversation.getThreadId(), notification); }
From source file:com.ekasoft.promoexito.MyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.ekasoft.promoexito.R.layout.activity_my); Settings.set(this, "promo_order", "false"); if (!Settings.isKey(this, "install")) { Calendar cal = Calendar.getInstance(); Intent intent = new Intent(this, ServiceWithWebView.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pintent); Intent intent2 = new Intent(MyActivity.this, InstallPromoActivity.class); startActivity(intent2);//www. j a v a 2 s. co m finish(); } ActionBar ab = getSupportActionBar(); ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffe800"))); ab.setIcon(com.ekasoft.promoexito.R.drawable.bar); ab.setLogo(com.ekasoft.promoexito.R.drawable.bar); ab.setDisplayUseLogoEnabled(true); ab.setHomeAsUpIndicator(com.ekasoft.promoexito.R.drawable.bar); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle(""); ActiveAndroid.initialize(this); mAdView = (AdView) findViewById(com.ekasoft.promoexito.R.id.ad_view); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) //.addTestDevice("4CBD3F38AF88E4EFA5FC4FB8B02D8D73") .build(); mAdView.loadAd(adRequest); listPromo = new FragmentListPromo(); listCategories = new CategorysFragment(); getSupportFragmentManager().beginTransaction() .add(com.ekasoft.promoexito.R.id.fragment_container, listPromo).commit(); }
From source file:com.capstone.transit.trans_it.RouteMap.java
@Override protected void onResume() { super.onResume(); setUpMapIfNeeded();/*w ww . j a v a 2 s . c om*/ positionsServiceIntent = new Intent(getApplicationContext(), RefreshPositionsService.class); positionsServiceIntent.putExtra("EXTRA_ROUTE_ID", routeID); positionsServiceIntent.putExtra("EXTRA_RECEIVER", new PositionsReceiver(new Handler())); final PendingIntent pendingIntent = PendingIntent.getService(this, 0, positionsServiceIntent, PendingIntent.FLAG_UPDATE_CURRENT); long trigger = System.currentTimeMillis(); int intervalMillis = 1000 * 60; AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC, trigger, intervalMillis, pendingIntent); }
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) { int backoffTimeMs = getBackoff(prefs); int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs); if (CMAccount.DEBUG) Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for " + intent.getAction());//from w w w. ja va 2 s . c om PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent); if (backoffTimeMs < CMAccount.MAX_BACKOFF_MS) { setBackoff(prefs, backoffTimeMs * 2); } }
From source file:edu.rit.csh.androidwebnews.RecentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); newsgroupListMenu = new NewsgroupListMenu(this); newsgroupListMenu.checkEnabled();// w w w .j ava 2 s. c om dialog = new InvalidApiKeyDialog(this); connectionDialog = new ConnectionExceptionDialog(this); ftd = new FirstTimeDialog(this); setContentView(R.layout.activity_recent); rf = (RecentFragment) getSupportFragmentManager().findFragmentById(R.id.recent_fragment); if (!sharedPref.getBoolean("first_time", true)) { hc.getNewest(true); if (!sharedPref.getString("newsgroups_json_string", "").equals("")) { newsgroupListMenu .update(hc.getNewsGroupFromString(sharedPref.getString("newsgroups_json_string", ""))); hc.startUnreadCountTask(); } else { hc.getNewsGroups(); } Intent intent = new Intent(this, UpdaterService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // if the run service is selected, an alarm is started to repeat over given time if (sharedPref.getBoolean("run_service", false)) { String timeString = sharedPref.getString("time_between_checks", "15"); int time = 15; if (!timeString.equals("")) { time = Integer.valueOf(timeString); } alarm.cancel(pintent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), time * 60000, pintent); } else { alarm.cancel(pintent); } } else { ftd.show(); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("first_time", false); editor.commit(); } setTitle("Recent Posts"); }
From source file:com.example.android.wearable.timer.TimerNotificationService.java
private void deleteTimer() { cancelCountdownNotification();//from ww w. j av a 2 s. c o m AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this, TimerNotificationService.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.cancel(pendingIntent); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Timer deleted."); } }