List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.adguard.android.service.FilterServiceImpl.java
@Override public void scheduleFiltersUpdate() { Intent alarmIntent = new Intent(AlarmReceiver.UPDATE_FILTER_ACTION); boolean isRunning = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE) != null; if (!isRunning) { LOG.info("Starting scheduler of filters updating"); PendingIntent broadcastIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, UPDATE_INITIAL_PERIOD, AlarmManager.INTERVAL_HOUR, broadcastIntent);// w w w . j av a 2 s. c o m } else { LOG.info("Filters update is running"); } }
From source file:edu.mines.letschat.GcmIntentService.java
protected PendingIntent getDeleteIntent() { Intent resultBroadCastIntent = new Intent(); resultBroadCastIntent.setAction("deletion"); resultBroadCastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT); sendBroadcast(resultBroadCastIntent); return PendingIntent.getBroadcast(getBaseContext(), 0, resultBroadCastIntent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.android.transmart.PlaceActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout setContentView(R.layout.nearby);/*from w w w .jav a2s. co m*/ // Get a handle to the Fragments placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment); checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment); // Get references to the managers packageManager = getPackageManager(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Get a reference to the Shared Preferences and a Shared Preference Editor. prefs = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); prefsEditor = prefs.edit(); // Instantiate a SharedPreferenceSaver class based on the available platform version. // This will be used to save shared preferences sharedPreferenceSaver = PlatformSpecific.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(LocationConstants.SP_KEY_RUN_ONCE, true); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Specify the Criteria to use when requesting location updates while the application is Active criteria = new Criteria(); if (LocationConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE) criteria.setAccuracy(Criteria.ACCURACY_FINE); else criteria.setPowerRequirement(Criteria.POWER_LOW); // Setup the location update Pending Intents Intent activeIntent = new Intent(this, LocationChangedReceiver.class); locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent passiveIntent = new Intent(this, PassiveLocReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Instantiate a LastLocationFinder class. // This will be used to find the last known location when the application starts. lastLocationFinder = PlatformSpecific.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); // Instantiate a Location Update Requester class based on the available platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecific.getLocationUpdateRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(LocationConstants.NEW_CHECKIN_ACTION); // Check to see if an Place ID has been specified in the launch Intent. // If so, we should display the details for the specified venue. if (getIntent().hasExtra(LocationConstants.EXTRA_KEY_ID)) { Intent intent = getIntent(); String key = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID); if (key != null) { selectDetail(null, key); // Remove the ID from the Intent (so that a resume doesn't reselect). intent.removeExtra(LocationConstants.EXTRA_KEY_ID); setIntent(intent); } } }
From source file:com.amaze.filemanager.asynchronous.services.CopyService.java
@Override public int onStartCommand(Intent intent, int flags, final int startId) { Bundle b = new Bundle(); isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false); ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES); String targetPath = intent.getStringExtra(TAG_COPY_TARGET); int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal()); final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c); accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference() .getCurrentUserColorPreferences(this, sharedPreferences).accent; mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); b.putInt(TAG_COPY_START_ID, startId); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small); customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big); Intent stopIntent = new Intent(TAG_BROADCAST_COPY_CANCEL); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(c, 1234, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_content_copy_white_36dp, getString(R.string.stop_ftp), stopPendingIntent); mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_content_copy_white_36dp) .setCustomContentView(customSmallContentViews).setCustomBigContentView(customBigContentViews) .setCustomHeadsUpContentView(customSmallContentViews) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true) .setColor(accentColor);/*from w ww . j a va 2 s .c o m*/ // set default notification views text NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL); startForeground(NotificationConstants.COPY_ID, mBuilder.build()); initNotificationViews(); b.putBoolean(TAG_COPY_MOVE, move); b.putString(TAG_COPY_TARGET, targetPath); b.putInt(TAG_COPY_OPEN_MODE, mode); b.putParcelableArrayList(TAG_COPY_SOURCES, files); super.onStartCommand(intent, flags, startId); super.progressHalted(); //going async new DoInBackground(isRootExplorer).execute(b); // If we get killed, after returning from here, restart return START_STICKY; }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); loadLanguage(LANGUAGE.ENGLISH);/*from w w w . j a v a 2 s .co m*/ setContentView(R.layout.activity_main); context = this; if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } initComponents(savedInstanceState); /* Retrieve a PendingIntent that will perform a broadcast */ Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, 0); UserProfile.getInstance(); PreferenceData.getInstance(context); GeneralSetting.getInstance(); Message msg = Message.obtain(); msg.what = ConstValues.WELCOME; getFlowHandler().sendMessage(msg); }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncManager.java
/** * Retreive the currently installed {@link PendingIntent} for the alarm. * //from w w w . ja v a 2s . c om * @return */ private PendingIntent getAlarmPendingIntent() { final Context context = getContext(); final Intent intent = new Intent(context, OnAlarmReceiver.class); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_NO_CREATE); }
From source file:com.iitb.wicroft.EventAlarmReceiver.java
public static void schedule_event(Context context, RequestEvent e) { Intent intent = new Intent(context, EventAlarmReceiver.class); intent.putExtra("eventid", (int) e.event_id); Random r = new Random(); int i1 = r.nextInt(10000 - 0) + 0; PendingIntent sender = PendingIntent.getBroadcast(context, 123456 + i1, intent, PendingIntent.FLAG_UPDATE_CURRENT); String msg = "Schedule_dependency_event"; msg += "\n Scheduling " + e.event_id + "@ " + e.relative_time; long curr_time = System.currentTimeMillis(); long t = e.relative_time * 1000; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { MainActivity.am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + t, sender); } else {/*w w w. ja v a2s .c om*/ MainActivity.am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + t, sender); } Log.d(Constants.LOGTAG, msg); if (MainActivity.debugging_on) { Calendar cal = Calendar.getInstance(); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); Threads.writeToLogFile(MainActivity.debugfilename, format1.format(cal.getTime()) + " " + Utils.sdf.format(cal.getTime()) + msg); } }
From source file:com.hedgehog.smdb.ActionBarControlScrollViewActivity.java
private void repeat() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override//from w w w. j a va2 s . co m public void onReceive(Context context, Intent intent) { showNotification(); } }; this.registerReceiver(receiver, new IntentFilter("TecxiDriverCheckingForConfirmedBids")); PendingIntent pintent = PendingIntent.getBroadcast(this, 0, new Intent("TecxiDriverCheckingForConfirmedBids"), 0); AlarmManager manager = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE)); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, 1000 * 60 * 30, pintent); }
From source file:com.chintans.venturebox.util.Utils.java
public static void setAlarm(Context context, long time, boolean trigger, boolean isRom) { Intent i = new Intent(context, NotificationAlarm.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getBroadcast(context, isRom ? ROM_ALARM_ID : GAPPS_ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);/*from ww w . j av a 2 s . c o m*/ if (time > 0) { am.setInexactRepeating(AlarmManager.RTC_WAKEUP, trigger ? 0 : time, time, pi); } }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "OnCreate"); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Stop-detection PI stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0); registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION)); // Stationary region PI stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION)); // Stationary location monitor PI stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0); registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION)); // One-shot PI (TODO currently unused) singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION)); //////from ww w .j a va 2s.c o m // DISABLED // Listen to Cell-tower switches (NOTE does not operate while suspended) //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION); // PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire(); // Location criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }