List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java
@SuppressLint("NewApi") @Override/*from w ww .j a va 2s . c om*/ public int onStartCommand(Intent intent, int flags, int startId) { try { SongDetail messageObject = MediaController.getInstance().getPlayingSongDetail(); if (messageObject == null) { MusicPlayerUtility.runOnUIThread(new Runnable() { @Override public void run() { stopSelf(); } }); return START_STICKY; } if (supportLockScreenControls) { ComponentName remoteComponentName = new ComponentName(getApplicationContext(), MusicPlayerReceiver.class.getName()); try { if (remoteControlClient == null) { audioManager.registerMediaButtonEventReceiver(remoteComponentName); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(remoteComponentName); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); audioManager.registerRemoteControlClient(remoteControlClient); } remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); } catch (Exception e) { Log.e("tmessages", e.toString()); } } createNotification(messageObject); } catch (Exception e) { e.printStackTrace(); } return START_STICKY; }
From source file:com.getpillion.gcm.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.d("GcmBroadcastReceiver", "received data in broadcast receiver"); // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);//w w w . j a v a2 s. co m }
From source file:com.actionbarsherlock.internal.view.MenuBuilder.java
@Override public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics, Intent intent, int flags, android.view.MenuItem[] outSpecificItems) { PackageManager pm = mContext.getPackageManager(); final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0); final int N = lri != null ? lri.size() : 0; if ((flags & FLAG_APPEND_TO_GROUP) == 0) { removeGroup(groupId);/*from w w w .ja v a 2s . c o m*/ } for (int i = 0; i < N; i++) { final ResolveInfo ri = lri.get(i); Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]); rintent.setComponent( new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name)); final MenuItem item = add(groupId, itemId, order, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)) .setIntent(rintent); if (outSpecificItems != null && ri.specificIndex >= 0) { outSpecificItems[ri.specificIndex] = item; } } return N; }
From source file:org.altbeacon.beacon.service.Callback.java
/** * Tries making the callback, first via messenger, then via intent * * @param context/*from www .j a v a2 s. co m*/ * @param dataName * @param data * @return false if it callback cannot be made */ public boolean call(Context context, String dataName, Bundle data) { boolean useLocalBroadcast = BeaconManager.getInstanceForApplication(context).getScheduledScanJobsEnabled(); boolean success = false; if (useLocalBroadcast) { String action = null; if (dataName == "rangingData") { action = BeaconLocalBroadcastProcessor.RANGE_NOTIFICATION; } else { action = BeaconLocalBroadcastProcessor.MONITOR_NOTIFICATION; } Intent intent = new Intent(action); intent.putExtra(dataName, data); LogManager.d(TAG, "attempting callback via local broadcast intent: %s", action); success = LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } else { Intent intent = new Intent(); intent.setComponent( new ComponentName(context.getPackageName(), "org.altbeacon.beacon.BeaconIntentProcessor")); intent.putExtra(dataName, data); LogManager.d(TAG, "attempting callback via global broadcast intent: %s", intent.getComponent()); try { context.startService(intent); success = true; } catch (Exception e) { LogManager.e(TAG, "Failed attempting to start service: " + intent.getComponent().flattenToString(), e); } } return success; }
From source file:com.pinplanet.pintact.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. System.out.println("==== Push Notification: GcmBroadcastReceiver::onReceive"); ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);//from ww w. j a v a 2 s .c o m }
From source file:in.risysnetworks.shplayer.mediacontroller.MusicPlayerService.java
@SuppressLint("NewApi") @Override//from www.j av a 2 s . c om public int onStartCommand(Intent intent, int flags, int startId) { try { SongDetail messageObject = MediaController.getInstance().getPlayingSongDetail(); if (messageObject == null) { SHPlayerUtility.runOnUIThread(new Runnable() { @Override public void run() { stopSelf(); } }); return START_STICKY; } if (supportLockScreenControls) { ComponentName remoteComponentName = new ComponentName(getApplicationContext(), MusicPlayerReceiver.class.getName()); try { if (remoteControlClient == null) { audioManager.registerMediaButtonEventReceiver(remoteComponentName); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(remoteComponentName); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); audioManager.registerRemoteControlClient(remoteControlClient); } remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); } catch (Exception e) { Log.e("tmessages", e.toString()); } } createNotification(messageObject); } catch (Exception e) { e.printStackTrace(); } return START_STICKY; }
From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);//from www. j av a 2 s . c o m String message = intent.getStringExtra("message"); String email = intent.getStringExtra("email"); String latitude = intent.getStringExtra("latitude"); String longitude = intent.getStringExtra("longitude"); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!") .setContentText("Alguem precisa de um " + message); Intent resultIntent = null; try { if (isLoggedIn()) { resultIntent = new Intent(context, LoggedInActivity.class); } else { resultIntent = new Intent(context, LoginActivity.class); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.example.itsatrap.app.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.d("IATGcmBroadcastReceiver", "onReceive"); // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), com.example.itsatrap.app.GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/*w ww.j a v a 2 s . c o m*/ }
From source file:com.jens.voicemsg.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Log.i(Configuration.LOG_TAG, "GcmBroadcastReceiver message: " + intent.toString()); // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/*from w ww . j av a2 s . com*/ }
From source file:es.javocsoft.android.lib.toolbox.gcm.core.CustomGCMBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.d(NotificationModule.TAG, "CustomGCMBroadcastReceiver called."); // Explicitly specify that GCMIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GCMIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/*from w w w .j a v a 2s . co m*/ Log.i("SimpleWakefulReceiver", "Starting service @ " + SystemClock.elapsedRealtime()); }