List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void cancelAlarm(Context context, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Cancel Alarm using Reminder ID mPendingIntent = PendingIntent.getBroadcast(context, ID, new Intent(context, AutomuteAlarmReceiver.class), 0);/*from ww w . j a va 2s . co m*/ mAlarmManager.cancel(mPendingIntent); // Disable alarm ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
From source file:com.radioactiveyak.location_best_practices.services.PlaceCheckinService.java
/** * {@inheritDoc}/*from w ww.j a v a2 s. c om*/ * Perform a checkin the specified venue. If the checkin fails, add it to the queue and * set an alarm to retry. * * Query the checkin queue to see if there are pending checkins to be retried. */ @Override protected void onHandleIntent(Intent intent) { // Retrieve the details for the checkin to perform. String reference = intent.getStringExtra(PlacesConstants.EXTRA_KEY_REFERENCE); String id = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID); long timeStamp = intent.getLongExtra(PlacesConstants.EXTRA_KEY_TIME_STAMP, 0); // Check if we're running in the foreground, if not, check if // we have permission to do background updates. boolean backgroundAllowed = cm.getBackgroundDataSetting(); boolean inBackground = sharedPreferences.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true); if (reference != null && !backgroundAllowed && inBackground) { addToQueue(timeStamp, reference, id); return; } // Check to see if we are connected to a data network. NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen // for when we connect to a network and start this service to retry the checkins. if (!isConnected) { // No connection so no point triggering an alarm to retry until we're connected. alarmManager.cancel(retryQueuedCheckinsPendingIntent); // Enable the Connectivity Changed Receiver to listen for connection to a network // so we can commit the pending checkins. PackageManager pm = getPackageManager(); ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class); pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // Add this checkin to the queue. addToQueue(timeStamp, reference, id); } else { // Execute the checkin. If it fails, add it to the retry queue. if (reference != null) { if (!checkin(timeStamp, reference, id)) addToQueue(timeStamp, reference, id); } // Retry the queued checkins. ArrayList<String> successfulCheckins = new ArrayList<String>(); Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null, null, null); try { // Retry each checkin. while (queuedCheckins.moveToNext()) { long queuedTimeStamp = queuedCheckins .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP)); String queuedReference = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE)); String queuedId = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID)); if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId)) successfulCheckins.add(queuedReference); } // Delete the queued checkins that were successful. if (successfulCheckins.size() > 0) { StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='" + successfulCheckins.get(0) + "'"); for (int i = 1; i < successfulCheckins.size(); i++) sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '" + successfulCheckins.get(i) + "'"); sb.append(")"); int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI, sb.toString(), null); Log.d(TAG, "Deleted: " + deleteCount); } // If there are still queued checkins then set a non-waking alarm to retry them. queuedCheckins.requery(); if (queuedCheckins.getCount() > 0) { long triggerAtTime = System.currentTimeMillis() + PlacesConstants.CHECKIN_RETRY_INTERVAL; alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime, retryQueuedCheckinsPendingIntent); } else alarmManager.cancel(retryQueuedCheckinsPendingIntent); } finally { queuedCheckins.close(); } } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java
@Override public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String packageName = obj.optString(PACKAGE_NAME); String arg = obj.optString(ARG); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg); launch.putExtra("creator", false); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); launch.setPackage(packageName);/*from w w w . j a v a 2s . c o m*/ final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved == null || resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite", Toast.LENGTH_SHORT).show(); return; } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received from " + from.name, "Click to launch application.", contentIntent); }
From source file:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java
/** * Cancels the alarm./*from www.jav a 2 s.c om*/ * * @param context */ public void cancelAlarm(Context context) { // If the alarm has been set, cancel it. if (alarmMgr != null) { alarmIntent.cancel(); alarmMgr.cancel(alarmIntent); } mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(NOTIFICATION_ID); ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
From source file:com.perm.DoomPlay.PlayingService.java
@Override public void onDestroy() { super.onDestroy(); dispose();//from w ww .j a v a 2 s. c o m bassPlayer.releaseTotal(); stopForeground(true); serviceAlive = false; isPlaying = false; sendBroadcast(new Intent(actionIconPlay)); sendBroadcast(new Intent(SmallWidget.actionUpdateWidget)); audioManager.abandonAudioFocus(afListener); audioManager.unregisterMediaButtonEventReceiver(new ComponentName(this, MediaButtonReceiver.class)); }
From source file:com.android.usbtuner.UsbInputController.java
/** * Enable/disable the component {@link UsbTunerTvInputService}. * * @param context {@link Context} instance * @param enabled {@code true} to enable the service; otherwise {@code false} */// w w w. j a v a 2 s. c om private void enableUsbTunerTvInputService(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); ComponentName USBTUNER = new ComponentName(context, UsbTunerTvInputService.class); // Don't kill app by enabling/disabling TvActivity. If LC is killed by enabling/disabling // TvActivity, the following pm.setComponentEnabledSetting doesn't work. ((TvApplication) context.getApplicationContext()).handleInputCountChanged(true, enabled, true); // Since PackageManager.DONT_KILL_APP delays the operation by 10 seconds // (PackageManagerService.BROADCAST_DELAY), we'd better avoid using it. It is used only // when the LiveChannels app is active since we don't want to kill the running app. int flags = TvApplication.getSingletons(context).getMainActivityWrapper().isCreated() ? PackageManager.DONT_KILL_APP : 0; int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (newState != pm.getComponentEnabledSetting(USBTUNER)) { // Send/cancel the USB tuner TV input setup recommendation card. TunerSetupActivity.onTvInputEnabled(context, enabled); // Enable/disable the USB tuner TV input. pm.setComponentEnabledSetting(USBTUNER, newState, flags); if (DEBUG) Log.d(TAG, "Status updated:" + enabled); } if (enabled && BuildCompat.isAtLeastN()) { TvInputInfo info = mDvbDeviceAccessor.buildTvInputInfo(context); if (info != null) { Log.i(TAG, "TvInputInfo updated: " + info.toString()); ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)).updateTvInputInfo(info); } } }
From source file:com.example.android.mediabrowserservice.BrowseFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mBrowserAdapter = new BrowseAdapter(getActivity()); View controls = rootView.findViewById(R.id.controls); controls.setVisibility(View.GONE); ListView listView = (ListView) rootView.findViewById(R.id.list_view); listView.setAdapter(mBrowserAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w . j a v a 2 s . c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position); try { FragmentDataHelper listener = (FragmentDataHelper) getActivity(); listener.onMediaItemSelected(item); } catch (ClassCastException ex) { Log.e(TAG, "Exception trying to cast to FragmentDataHelper", ex); } } }); Bundle args = getArguments(); mMediaId = args.getString(ARG_MEDIA_ID, null); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MusicService.class), mConnectionCallback, null); return rootView; }
From source file:codepath.watsiapp.utils.Util.java
private static void startShareIntentWithExplicitSocialActivity(Activity ctx, ShareableItem patient, Set<String> socialActivitiesName, String displayName) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, patient.getShareableUrl()); try {//from w w w . j a v a 2 s. c om final PackageManager pm = ctx.getPackageManager(); final List activityList = pm.queryIntentActivities(shareIntent, 0); int len = activityList.size(); for (int i = 0; i < len; i++) { final ResolveInfo app = (ResolveInfo) activityList.get(i); Log.d("#####################", app.activityInfo.name); if (socialActivitiesName.contains(app.activityInfo.name)) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Fund Treatment"); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setComponent(name); ctx.startActivity(shareIntent); break; } } } catch (final ActivityNotFoundException e) { Toast.makeText(ctx, "Could not find " + displayName + " app", Toast.LENGTH_SHORT).show(); } }
From source file:co.edu.uniajc.vtf.ar.ARViewActivity.java
@Override protected void onResume() { super.onResume(); ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class); this.getPackageManager().setComponentEnabledSetting(loComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); this.loadPosition(); if (this.architectView != null) { this.architectView.onResume(); }//from w w w .j ava2 s. com }
From source file:com.appsaur.tarucassist.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(BaseActivity.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); }