List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:net.sourceforge.kalimbaradio.androidapp.util.Util.java
public static void unregisterMediaButtonEventReceiver(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ComponentName mediaButtonIntentReceiver = new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()); audioManager.unregisterMediaButtonEventReceiver(mediaButtonIntentReceiver); }
From source file:com.blanyal.remindme.MainActivity.java
public static Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent, Context context) { PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0); if (resolveInfoList == null || resolveInfoList.size() != 1) { return null; }/*w ww . j a v a2s. co m*/ ResolveInfo serviceInfo = resolveInfoList.get(0); Log.v("vbharill", "package name" + serviceInfo.serviceInfo.packageName); Log.v("vbharill", "service name" + serviceInfo.serviceInfo.name); ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name); Intent explicitIntent = new Intent(implicitIntent); explicitIntent.setComponent(component); return explicitIntent; }
From source file:com.cyanogenmod.eleven.MusicPlaybackService.java
/** * {@inheritDoc}/*www . jav a 2s .c om*/ */ @Override public void onCreate() { if (D) Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Initialize the favorites and recents databases mRecentsCache = RecentStore.getInstance(this); // gets the song play count cache mSongPlayCountCache = SongPlayCount.getInstance(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); // Initialize the image fetcher mImageFetcher = ImageFetcher.getInstance(this); // Initialize the image cache mImageFetcher.setImageCache(ImageCache.getInstance(this)); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt the UI. mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); // Initialize the handler mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); // Initialize the audio manager and register any headset controls for // playback mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); // Use the remote control APIs to set the playback state setUpMediaSession(); // Initialize the preferences mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); // Initialize the media player mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // Get events when MediaStore content changes mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the delayed shutdown intent final Intent shutdownIntent = new Intent(this, MusicPlaybackService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); // Listen for the idle state scheduleDelayedShutdown(); // Bring the queue back reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:com.android.purenexussettings.TinkerActivity.java
public void setLauncherIconEnabled(boolean enabled) { int newState; PackageManager packman = getPackageManager(); if (enabled) { newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; } else {/*from w ww. ja va2 s. com*/ newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; } packman.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState, PackageManager.DONT_KILL_APP); }
From source file:com.android.purenexussettings.TinkerActivity.java
public boolean isLauncherIconEnabled() { PackageManager packman = getPackageManager(); return (packman.getComponentEnabledSetting(new ComponentName(this, LauncherActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); }
From source file:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java
private void startActivityInPrimary(Intent intent) { // Disable app components in the current profile, so only the counterpart in the other // profile can respond (via cross-profile intent filter) getPackageManager().setComponentEnabledSetting(new ComponentName(this, ByodFlowTestActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); startActivity(intent);// w ww. j ava2s. co m }
From source file:org.gaeproxy.GAEProxyService.java
/** Called when the activity is closed. */ @Override//from w w w . j a v a2 s . c o m public void onDestroy() { EasyTracker.getTracker().trackEvent("service", "stop", getVersionName(), 0L); if (mShutdownReceiver != null) { unregisterReceiver(mShutdownReceiver); mShutdownReceiver = null; } statusLock = true; stopForegroundCompat(1); notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped), Notification.FLAG_AUTO_CANCEL); try { if (dnsServer != null) dnsServer.close(); } catch (Exception e) { Log.e(TAG, "DNS Server close unexpected"); } new Thread() { @Override public void run() { // Make sure the connection is closed, important here onDisconnect(); } }.start(); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.off); AppWidgetManager awm = AppWidgetManager.getInstance(this); awm.updateAppWidget(awm.getAppWidgetIds(new ComponentName(this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } Editor ed = settings.edit(); ed.putBoolean("isRunning", false); ed.putBoolean("isConnecting", false); ed.commit(); try { notificationManager.cancel(0); } catch (Exception ignore) { // Nothing } try { ProxySettings.resetProxy(this); } catch (Exception ignore) { // Nothing } super.onDestroy(); statusLock = false; markServiceStopped(); }
From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java
protected void updateWidgets() { if (PreferencesUtils.getBoolean(context, PreferencesUtils.PREF_WIDGET_UNREAD_EXISTS, false)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] ids = appWidgetManager.getAppWidgetIds(new ComponentName(context, UnreadAppWidgetProvider.class)); Intent intent = new Intent(context, UnreadAppWidgetProvider.class); intent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent);/* w w w . j a va2 s.c o m*/ Log.d(TAG, "Widget update Intent fired"); } }
From source file:com.dmbstream.android.util.Util.java
public static void registerMediaButtonEventReceiver(Context context) { // Only do it if enabled in the settings. SharedPreferences prefs = getPreferences(context); boolean enabled = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true); if (enabled) { // AudioManager.registerMediaButtonEventReceiver() was introduced in Android 2.2. // Use reflection to maintain compatibility with 1.5. try {//from w w w . j av a 2 s .c o m AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ComponentName componentName = new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()); Method method = AudioManager.class.getMethod("registerMediaButtonEventReceiver", ComponentName.class); method.invoke(audioManager, componentName); } catch (Throwable x) { // Ignored. } } }
From source file:com.android.leanlauncher.IconCache.java
/** * Gets an entry for the package, which can be used as a fallback entry for various components. * This method is not thread safe, it must be called from a synchronized method. *//*from ww w .jav a 2s.c o m*/ private CacheEntry getEntryForPackage(String packageName, UserHandleCompat user) { ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME); CacheKey cacheKey = new CacheKey(cn, user); CacheEntry entry = mCache.get(cacheKey); if (entry == null || entry.icon == null) { entry = new CacheEntry(); try { ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0); entry.title = info.loadLabel(mPackageManager); entry.contentDescription = info.loadDescription(mPackageManager); Drawable defaultDrawable = info.loadIcon(mPackageManager); if (!TextUtils.isEmpty(mCurrentIconTheme)) { entry.icon = createNewIconBitmap(null, packageName, null, defaultDrawable); } if (entry.icon == null) { // pick default icon Log.d(TAG, packageName + " icon NOT FOUND in theme = " + mCurrentIconTheme); entry.icon = Utilities.createIconBitmap(defaultDrawable, mContext); } mCache.put(cacheKey, entry); } catch (NameNotFoundException e) { if (DEBUG) Log.d(TAG, "Application not installed " + packageName); } } return entry; }