List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
private PendingIntent createPausePendingIntent(Context context, FixedAlarmSchedule alarmSchedule) { Intent intent = new Intent(context, EndPauseReceiver.class); intent.putExtra(Constants.ALARM_SCHEDULE, alarmSchedule); return PendingIntent.getBroadcast(context, PAUSE_ALARM_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.rickendirk.rsgwijzigingen.ZoekService.java
private void sendNotification(Wijzigingen wijzigingen) { boolean isFoutMelding = wijzigingen.isFoutmelding(); boolean isVerbindFout; boolean isNieuw; //Tot tegendeel bewezen is if (isFoutMelding) { isVerbindFout = wijzigingen.isVerbindfout(); isNieuw = false;/* w w w .j a v a2s. c om*/ } else { isVerbindFout = false; isNieuw = wijzigingen.isNieuw(this); } if (!isFoutMelding) { wijzigingen.saveToSP(this); } if (!isFoutMelding && !isNieuw) { Log.i(TAG, "Geen nieuwe wijzigingen, geen notificatie"); return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_rsg_notific).setContentTitle("Roosterwijzigingen") .setColor(getResources().getColor(R.color.lighter_blue)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); if (isFoutMelding) { if (isVerbindFout) { Log.i(TAG, "Er was geen internetverbinding bij het zoeken"); boolean moetHerhalen = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_auto_herhaal_geenInternet", false); if (moetHerhalen) { setAlarmIn20Min(); Log.i(TAG, "Zal ivm geen internet in 20 minuten opnieuw zoeken"); return; } else { builder.setContentText("Er was geen internetverbinding. Probeer het handmatig opnieuw"); } } else { builder.setContentText("Er was een fout. Probeer het handmatig opnieuw"); } } else { boolean zijnWijzigingen = wijzigingen.zijnWijzigingen; ArrayList<String> wijzigingenList = wijzigingen.getWijzigingen(); addPossibleMessage(wijzigingen, wijzigingenList); if (zijnWijzigingen) { if (wijzigingenList.size() == 1) { builder.setContentText(wijzigingenList.get(0)); } else { builder.setContentText("Er zijn " + wijzigingenList.size() + " wijzigingen!"); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle("De roosterwijzigingen zijn:"); for (int i = 0; i < wijzigingenList.size(); i++) { inboxStyle.addLine(wijzigingenList.get(i)); } builder.setStyle(inboxStyle); } } else { boolean alleenBijWijziging = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_auto_zoek_alleenBijWijziging", true); if (!alleenBijWijziging) { //Dus ook bij geen-wijzigingen builder.setContentText("Er zijn geen roosterwijzigingen"); } else return; } } Intent resultIntent = new Intent(this, MainActivity.class); resultIntent.putExtra("isVanNotificatie", true); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingIntent); NotificationManagerCompat notifManager = NotificationManagerCompat.from(this); notifManager.notify(notifID, builder.build()); vibrate(); Log.i(TAG, "Nieuwe notificatie gemaakt"); }
From source file:com.pinplanet.pintact.GcmIntentService.java
private void sendChatNotification(String customData) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); JSONObject jsonObject = null;/*w ww. j a v a2 s .c o m*/ JSONObject chatObject = null; GroupDTO groupDTO = new GroupDTO(); String chatMessage = "New Chat Message"; String groupId = ""; try { jsonObject = new JSONObject(customData); Log.d(TAG, "groupId: " + jsonObject.getString("groupId")); groupId = jsonObject.getString("groupId"); groupDTO.setId(jsonObject.getString("groupId")); SingletonLoginData.getInstance().setCurGroup(groupDTO); Log.d(TAG, "message: " + jsonObject.getString("message")); chatObject = jsonObject.getJSONObject("message"); chatMessage = chatObject.getString("content"); } catch (JSONException e) { Log.d(TAG, "sendChatNotification error: " + e.toString()); e.printStackTrace(); } //Intent it = new Intent(this, PushNotificationActivity.class); Intent it = new Intent(this, GroupContactsActivity.class); it.putExtra("groupId", groupId); it.putExtra("OpenThreads", true); //it.putExtra(LeftDeckActivity.SELECTED_OPTIONS, LeftDeckActivity.OPTION_NOTIFY); // add the following line would show Pintact to the preview page. // it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("New Message") .setStyle(new NotificationCompat.BigTextStyle().bigText(chatMessage)) .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }).setAutoCancel(true) .setContentText(chatMessage); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); SingletonLoginData.getInstance().mNotificationManager = mNotificationManager; }
From source file:com.ubergeek42.WeechatAndroid.service.RelayService.java
public boolean connect() { // Load the preferences host = prefs.getString("host", null); pass = prefs.getString("password", "password"); port = prefs.getString("port", "8001"); stunnelCert = prefs.getString("stunnel_cert", ""); stunnelPass = prefs.getString("stunnel_pass", ""); sshHost = prefs.getString("ssh_host", ""); sshUser = prefs.getString("ssh_user", ""); sshPass = prefs.getString("ssh_pass", ""); sshPort = prefs.getString("ssh_port", "22"); sshKeyfile = prefs.getString("ssh_keyfile", ""); optimize_traffic = prefs.getBoolean("optimize_traffic", false); // If no host defined, signal them to edit their preferences if (host == null) { Intent i = new Intent(this, WeechatPreferencesActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.app_version)) .setContentText(getString(R.string.notification_update_settings)) .setTicker(getString(R.string.notification_update_settings_details)) .setWhen(System.currentTimeMillis()); Notification notification = builder.getNotification(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; notificationManger.notify(NOTIFICATION_ID, notification); return false; }// w w w. j a va2s . com // Only connect if we aren't already connected if ((relayConnection != null) && (relayConnection.isConnected())) { return false; } shutdown = false; bufferManager = new BufferManager(); hotlistManager = new HotlistManager(); hotlistManager.setBufferManager(bufferManager); msgHandler = new LineHandler(bufferManager); nickHandler = new NicklistHandler(bufferManager); hotlistHandler = new HotlistHandler(bufferManager, hotlistManager); hotlistHandler.registerHighlightHandler(this); relayConnection = new RelayConnection(host, port, pass); String connType = prefs.getString("connection_type", "plain"); if (connType.equals("ssh")) { relayConnection.setSSHHost(sshHost); relayConnection.setSSHUsername(sshUser); relayConnection.setSSHPort(sshPort); relayConnection.setSSHPassword(sshPass); relayConnection.setSSHKeyFile(sshKeyfile); relayConnection.setConnectionType(ConnectionType.SSHTUNNEL); } else if (connType.equals("stunnel")) { relayConnection.setStunnelCert(stunnelCert); relayConnection.setStunnelKey(stunnelPass); relayConnection.setConnectionType(ConnectionType.STUNNEL); } else if (connType.equals("ssl")) { relayConnection.setConnectionType(ConnectionType.SSL); relayConnection.setSSLKeystore(sslKeystore); } else { relayConnection.setConnectionType(ConnectionType.DEFAULT); } relayConnection.setConnectionHandler(this); relayConnection.connect(); return true; }
From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsProviderService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor edit = sharedPreferences.edit(); debugToasts = sharedPreferences.getBoolean(PREF_TOAST_LOGGING, false); int vendorId = sharedPreferences.getInt(PREF_GPS_DEVICE_VENDOR_ID, USBGpsSettingsFragment.DEFAULT_GPS_VENDOR_ID); int productId = sharedPreferences.getInt(PREF_GPS_DEVICE_PRODUCT_ID, USBGpsSettingsFragment.DEFAULT_GPS_PRODUCT_ID); int maxConRetries = Integer.parseInt(sharedPreferences.getString(PREF_CONNECTION_RETRIES, this.getString(R.string.defaultConnectionRetries))); log("prefs device addr: " + vendorId + " - " + productId); if (ACTION_START_GPS_PROVIDER.equals(intent.getAction())) { if (gpsManager == null) { String mockProvider = LocationManager.GPS_PROVIDER; if (!sharedPreferences.getBoolean(PREF_REPLACE_STD_GPS, true)) { mockProvider = sharedPreferences.getString(PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName)); }//from w ww.j a v a 2s . co m gpsManager = new USBGpsManager(this, vendorId, productId, maxConRetries); boolean enabled = gpsManager.enable(); if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled) { edit.putBoolean(PREF_START_GPS_PROVIDER, enabled); edit.apply(); } if (enabled) { gpsManager.enableMockLocationProvider(mockProvider); PendingIntent launchIntent = PendingIntent.getActivity(this, 0, new Intent(this, GpsInfoActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); sharedPreferences.edit().putInt(getString(R.string.pref_disable_reason_key), 0).apply(); Notification notification = new NotificationCompat.Builder(this).setContentIntent(launchIntent) .setSmallIcon(R.drawable.ic_stat_notify).setAutoCancel(true) .setContentTitle(getString(R.string.foreground_service_started_notification_title)) .setContentText(getString(R.string.foreground_gps_provider_started_notification)) .build(); startForeground(R.string.foreground_gps_provider_started_notification, notification); showToast(R.string.msg_gps_provider_started); if (sharedPreferences.getBoolean(PREF_TRACK_RECORDING, false)) { startTracking(); } } else { stopSelf(); } } else { // We received a start intent even though it's already running so restart stopSelf(); startService(new Intent(this, USBGpsProviderService.class).setAction(intent.getAction())); } } else if (ACTION_START_TRACK_RECORDING.equals(intent.getAction())) { startTracking(); } else if (ACTION_STOP_TRACK_RECORDING.equals(intent.getAction())) { if (gpsManager != null) { gpsManager.removeNmeaListener(this); endTrack(); showToast(this.getString(R.string.msg_nmea_recording_stopped)); } if (sharedPreferences.getBoolean(PREF_TRACK_RECORDING, true)) { edit.putBoolean(PREF_TRACK_RECORDING, false); edit.commit(); } } else if (ACTION_STOP_GPS_PROVIDER.equals(intent.getAction())) { if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, true)) { edit.putBoolean(PREF_START_GPS_PROVIDER, false); edit.commit(); } stopSelf(); } else if (ACTION_CONFIGURE_SIRF_GPS.equals(intent.getAction()) || ACTION_ENABLE_SIRF_GPS.equals(intent.getAction())) { if (gpsManager != null) { Bundle extras = intent.getExtras(); if (extras != null) { gpsManager.enableSirfConfig(extras); } else { gpsManager.enableSirfConfig(sharedPreferences); } } } return Service.START_NOT_STICKY; }
From source file:audio.lisn.service.MediaNotificationManager.java
/** * Update the state based on a change on the session token. Called either when * we are running for the first time or when the media session owner has destroyed the session * (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()}) *//* w ww . j ava 2 s . c om*/ /* private void updateSessionToken() { MediaSession.Token freshToken = mService.getSessionToken(); if (mSessionToken == null || !mSessionToken.equals(freshToken)) { if (mController != null) { mController.unregisterCallback(mCb); } mSessionToken = freshToken; mController = new MediaController(mService, mSessionToken); mTransportControls = mController.getTransportControls(); if (mStarted) { mController.registerCallback(mCb); } } } */ private PendingIntent createContentIntent() { Intent openUI = new Intent(mService, PlayerControllerActivity.class); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.bayapps.android.robophish.MediaNotificationManager.java
private PendingIntent createContentIntent(MediaDescriptionCompat description) { Intent openUI = new Intent(mService, MusicPlayerActivity.class); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); openUI.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, true); if (description != null) { openUI.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, description); }/*from w ww.java 2 s. c o m*/ return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.pluscubed.velociraptor.SettingsActivity.java
@SuppressWarnings("ConstantConditions") @Override// w w w. j a v a 2s. co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); ButterKnife.bind(this); setSupportActionBar(toolbar); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions); marshmallowPermissionsCard.setVisibility(View.GONE); } openStreetMapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org") .setType("text/plain").startChooser(); } }); checkCoverageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mGoogleApiClient = new GoogleApiClient.Builder(SettingsActivity.this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override @SuppressWarnings("MissingPermission") public void onConnected(@Nullable Bundle bundle) { String uriString = "http://product.itoworld.com/map/124"; if (isLocationPermissionGranted()) { Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient); if (lastLocation != null) { uriString += "?lon=" + lastLocation.getLongitude() + "&lat=" + lastLocation.getLatitude() + "&zoom=12"; } } Intent intent = new Intent(); intent.setData(Uri.parse(uriString)); intent.setAction(Intent.ACTION_VIEW); try { startActivity(intent); } catch (ActivityNotFoundException e) { Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed, Snackbar.LENGTH_LONG).show(); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int i) { } }).addApi(LocationServices.API).build(); mGoogleApiClient.connect(); } }); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); View notifControls = findViewById(R.id.switch_notif_controls); notifControls.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SettingsActivity.this, FloatingService.class); intent.putExtra(FloatingService.EXTRA_NOTIF_START, true); PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent, PendingIntent.FLAG_CANCEL_CURRENT); Intent intentClose = new Intent(SettingsActivity.this, FloatingService.class); intentClose.putExtra(FloatingService.EXTRA_NOTIF_CLOSE, true); PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE, intentClose, PendingIntent.FLAG_CANCEL_CURRENT); Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class); PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS, settings, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this) .setSmallIcon(R.drawable.ic_speedometer) .setContentTitle(getString(R.string.controls_notif_title)) .setContentText(getString(R.string.controls_notif_desc)) .addAction(0, getString(R.string.show), pending) .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose) .setContentIntent(settingsIntent); Notification notification = builder.build(); notificationManager.notify(NOTIFICATION_CONTROLS, notification); } }); Button openAppSelection = (Button) findViewById(R.id.button_app_selection); openAppSelection.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class)); } }); autoDisplaySwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); autoDisplaySwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean autoDisplayEnabled = autoDisplaySwitch.isChecked(); PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled); updateAppDetectionEnabled(autoDisplayEnabled); } }); enableServiceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)); } catch (ActivityNotFoundException e) { Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility, Snackbar.LENGTH_LONG).show(); } } }); enableFloatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { //Open the current default browswer App Info page openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID); } catch (ActivityNotFoundException ignored) { Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG) .show(); } } }); enableLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(SettingsActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } }); ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { "mph", "km/h" }); unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); unitSpinner.setAdapter(unitAdapter); unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) { PrefUtils.setUseMetric(SettingsActivity.this, position == 1); unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, unitSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0); unitSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48)); ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text, new String[] { getString(R.string.united_states), getString(R.string.international) }); styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); styleSpinner.setAdapter(styleAdapter); styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != PrefUtils.getSignStyle(SettingsActivity.this)) { PrefUtils.setSignStyle(SettingsActivity.this, position); styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this, styleSpinner.getSelectedItemPosition() * -48)); updateFloatingServicePrefs(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); styleSpinner.setSelection(PrefUtils.getSignStyle(this)); styleSpinner .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48)); toleranceView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance"); } }); showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this)); ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked()); PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked()); updateFloatingServicePrefs(); } }); debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this)); ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { debuggingSwitch.setChecked(!debuggingSwitch.isChecked()); PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked()); updateFloatingServicePrefs(); } }); beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this)); beepSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked()); } }); testBeepButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Utils.playBeep(); } }); androidAutoSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this)); androidAutoSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = androidAutoSwitch.isChecked(); if (checked) { new MaterialDialog.Builder(SettingsActivity.this) .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true); } }).show(); } else { PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked); } } }); invalidateStates(); if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) { showChangelog(); } billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key), new BillingProcessor.IBillingHandler() { @Override public void onProductPurchased(String productId, TransactionDetails details) { PrefUtils.setSupported(SettingsActivity.this, true); if (Arrays.asList(PURCHASES).contains(productId)) billingProcessor.consumePurchase(productId); } @Override public void onPurchaseHistoryRestored() { } @Override public void onBillingError(int errorCode, Throwable error) { if (errorCode != 110) { Snackbar.make(findViewById(android.R.id.content), "Billing error: code = " + errorCode + ", error: " + (error != null ? error.getMessage() : "?"), Snackbar.LENGTH_LONG).show(); } } @Override public void onBillingInitialized() { billingProcessor.loadOwnedPurchasesFromGoogle(); } }); PrefUtils.setFirstRun(this, false); PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE); }
From source file:fr.paug.droidcon.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);/* w w w.ja v a2 s . com*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData( new Uri.Builder().authority("fr.paug.droidcon").path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:nuclei.media.MediaNotificationManager.java
private PendingIntent createContentIntent(MediaDescriptionCompat description) { try {/*w ww. j a va 2 s .co m*/ MediaId id = MediaProvider.getInstance().getMediaId(description.getMediaId()); Intent openUI = new Intent(mService, id.type == MediaId.TYPE_AUDIO ? Configuration.AUDIO_ACTIVITY : Configuration.VIDEO_ACTIVITY); openUI.putExtra(MediaService.MEDIA_ID, description.getMediaId()); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); } catch (Exception err) { throw new RuntimeException(err); } }