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:it.gulch.linuxday.android.services.AlarmIntentService.java
private PendingIntent getAlarmPendingIntent(long eventId) { Intent intent = new Intent(this, AlarmReceiver.class); intent.setAction(AlarmReceiver.ACTION_NOTIFY_EVENT); intent.setData(Uri.parse(String.valueOf(eventId))); return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:be.benvd.mvforandroid.data.MVDataService.java
@Override public void onCreate() { super.onCreate(); prefs = PreferenceManager.getDefaultSharedPreferences(this); helper = new DatabaseHelper(this); alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); instance = this; Intent i = new Intent(this, OnAlarmReceiver.class); wakefulWorkIntent = PendingIntent.getBroadcast(this, 0, i, 0); }
From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java
private void updateRemoteViews(Context context, RemoteViews views) { if (title != null) { views.setTextViewText(R.id.title, title); }//ww w . j a v a 2 s .c o m if (image != null) { views.setImageViewBitmap(R.id.image, image); } else { views.setImageViewBitmap(R.id.image, null); } Intent goToSiteIntent = new Intent(Intent.ACTION_VIEW); goToSiteIntent.setData(Uri.parse("http://xkcd.com")); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, goToSiteIntent, 0); views.setOnClickPendingIntent(R.id.image, pendingIntent); if (altText != null) { views.setTextViewText(R.id.alt_text, altText); } Intent intent = new Intent(context, getClass()); intent.setAction(UPDATE); views.setOnClickPendingIntent(R.id.sync, PendingIntent.getBroadcast(context, 0, intent, 0)); }
From source file:com.winsuk.pebbletype.WatchCommunication.java
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) { PebbleKit.sendAckToPebble(context, transactionId); if (data.contains(KEY_REQUEST_THREAD_LIST)) { sendThreadList(context);//from w w w .j a v a2s . c om } if (data.contains(KEY_SEND_MESSAGE)) { String str = data.getString(KEY_SEND_MESSAGE); boolean demoMode = str.startsWith(";"); String address = str.substring(0, str.indexOf(";")); String message = str.substring(str.indexOf(";") + 1, str.length()); if (!demoMode) { SmsManager sms = SmsManager.getDefault(); // Tried to use getService here which makes more sense, but that didn't work PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_SMS_REPLY), PendingIntent.FLAG_ONE_SHOT); sms.sendTextMessage(address, null, message, pi, null); } } }
From source file:com.commonsware.android.sawmonitor.PackageReceiver.java
private void seeSAW(Context ctxt, String pkg, boolean isReplace) { if (hasSAW(ctxt, pkg)) { Uri pkgUri = Uri.parse("package:" + pkg); Intent manage = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); manage.setData(pkgUri);// w w w. ja va 2s . co m Intent whitelist = new Intent(ctxt, WhitelistReceiver.class); whitelist.setData(pkgUri); Intent main = new Intent(ctxt, MainActivity.class); main.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); NotificationCompat.Builder b = new NotificationCompat.Builder(ctxt); String text = String.format(ctxt.getString(R.string.msg_requested), isReplace ? ctxt.getString(R.string.msg_upgraded) : ctxt.getString(R.string.msg_installed), pkg); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis()) .setContentTitle(ctxt.getString(R.string.msg_detected)).setContentText(text) .setSmallIcon(android.R.drawable.stat_notify_error) .setTicker(ctxt.getString(R.string.msg_detected)) .setContentIntent(PendingIntent.getActivity(ctxt, 0, manage, PendingIntent.FLAG_UPDATE_CURRENT)) .addAction(R.drawable.ic_verified_user_24dp, ctxt.getString(R.string.msg_whitelist), PendingIntent.getBroadcast(ctxt, 0, whitelist, 0)) .addAction(R.drawable.ic_settings_24dp, ctxt.getString(R.string.msg_settings), PendingIntent.getActivity(ctxt, 0, main, 0)); NotificationManager mgr = (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE); mgr.notify(NOTIFY_ID, b.build()); } }
From source file:es.udc.robotcontrol.testapp.comunication.ConectorPlaca.java
public void conectarManual(Context ctx) throws TransmisionErrorException { Log.i(Constantes.TAG_CONECTOR, "Conectando manualmente. modo - Host"); /* Get the USB manager from the requesting context */ this.manager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> it = deviceList.values().iterator(); PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); ctx.registerReceiver(mUsbReceiver, filter); if (it.hasNext()) { device = it.next();// ww w . j a v a 2 s .c o m manager.requestPermission(device, mPermissionIntent); conectar(); } else { Log.i(Constantes.TAG_CONECTOR, "No se han encontrado dispositivos"); throw new TransmisionErrorException("No se han encontrado dispositivos"); } }
From source file:com.appdevper.mediaplayer.app.MediaNotificationManager.java
public MediaNotificationManager(MusicService service) throws RemoteException { mService = service;/* ww w . j a v a 2 s . c om*/ updateSessionToken(); mNotificationColor = ResourceHelper.getThemeColor(mService, R.attr.colorPrimary, Color.DKGRAY); mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); String pkg = mService.getPackageName(); mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mStopCastIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_STOP_CASTING).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); // Cancel all notifications to handle the case where the Service was killed and // restarted by the system. mNotificationManager.cancelAll(); }
From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:es.udc.fic.android.robot_control.robot.ConectorPlaca.java
public void conectarManual(Context ctx) throws TransmisionErrorException { Log.i(C.ROBOT_TAG, "Conectando manualmente. modo - Host"); /* Get the USB manager from the requesting context */ this.manager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> it = deviceList.values().iterator(); PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); ctx.registerReceiver(mUsbReceiver, filter); if (it.hasNext()) { device = it.next();/*from ww w . ja v a 2 s. com*/ manager.requestPermission(device, mPermissionIntent); //conectar(); } else { Log.i(C.ROBOT_TAG, "No se han encontrado dispositivos"); throw new TransmisionErrorException("No se han encontrado dispositivos"); } }
From source file:ca.mudar.mtlaucasou.LocationFragmentActivity.java
@Override public void onCreate(Bundle savedInstanceState) { mAppHelper = (AppHelper) getApplicationContext(); mActivityHelper = ActivityHelper.createInstance(this); prefs = getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); prefsEditor = prefs.edit();//from w w w .ja va 2 s .co m locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); /** * Instantiate a LastLocationFinder class. This will be used to find the * last known location when the application starts. */ lastLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); hasRegisteredSingleUpdateReceiver = true; /** * Set the last known location as user's current location. */ mAppHelper.setLocation(lastLocationFinder.getLastBestLocation(Const.MAX_DISTANCE, Const.MAX_TIME)); /** * Specify the Criteria to use when requesting location updates while * the application is Active. */ criteria = new Criteria(); if (Const.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, PassiveLocationChangedReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); locationManager.removeUpdates(locationListenerPassivePendingIntent); /** * Instantiate a Location Update Requester class based on the available * platform version. This will be used to request location updates. */ locationUpdateRequester = PlatformSpecificImplementationFactory .getLocationUpdateRequester(this.getApplicationContext(), locationManager); super.onCreate(savedInstanceState); }