List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.google.sample.castcompanionlibrary.cast.VideoCastManager.java
private VideoCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) { super(context, applicationId); LOGD(TAG, "VideoCastManager is instantiated"); mDataNamespace = dataNamespace;// w ww.j a v a 2 s. co m if (null == targetActivity) { targetActivity = VideoCastControllerActivity.class; } mTargetActivity = targetActivity; Utils.saveStringToPreference(mContext, PREFS_KEY_CAST_ACTIVITY_NAME, mTargetActivity.getName()); if (null != mDataNamespace) { Utils.saveStringToPreference(mContext, PREFS_KEY_CAST_CUSTOM_DATA_NAMESPACE, dataNamespace); } mMiniControllers = Collections.synchronizedSet(new HashSet<IMiniController>()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(context, VideoIntentReceiver.class); }
From source file:com.devalladolid.musictoday.MusicService.java
@Override public void onCreate() { if (D)//from w w w.j a v a 2s . c o m Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setUpMediaSession(); mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); 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); 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 wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java
protected VideoCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) {// ww w . j a v a 2 s . c o m super(context, applicationId); LOGD(TAG, "VideoCastManager is instantiated"); mDataNamespace = dataNamespace; if (targetActivity == null) { targetActivity = VideoCastControllerActivity.class; } mTargetActivity = targetActivity; mPreferenceAccessor.saveStringToPreference(PREFS_KEY_CAST_ACTIVITY_NAME, mTargetActivity.getName()); if (!TextUtils.isEmpty(mDataNamespace)) { mPreferenceAccessor.saveStringToPreference(PREFS_KEY_CAST_CUSTOM_DATA_NAMESPACE, dataNamespace); } mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(mContext, VideoIntentReceiver.class); }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
/** * Disable admin privileges.// w w w . j a va 2 s .c o m * @param context - Application context. */ public static void disableAdmin(Context context) { DevicePolicyManager devicePolicyManager; ComponentName demoDeviceAdmin; devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); devicePolicyManager.removeActiveAdmin(demoDeviceAdmin); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
@Override public void onCreate() { super.onCreate(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rec); Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON); i.setComponent(rec);/*w w w. j ava 2 s.c o m*/ PendingIntent pi = PendingIntent.getBroadcast(this /*context*/, 0 /*requestCode, ignored*/, i /*intent*/, 0 /*flags*/); mRemoteControlClient = new RemoteControlClient(pi); mAudioManager.registerRemoteControlClient(mRemoteControlClient); int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; mRemoteControlClient.setTransportControlFlags(flags); mPreferences = getSharedPreferences("Music", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); // Needs to be done in this thread, since otherwise ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); registerReceiver(mIntentReceiver, commandFilter); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:org.gaeproxy.GAEProxyService.java
public void handleCommand(Intent intent) { if (intent == null) { stopSelf();//from ww w. jav a 2 s . com return; } proxyType = settings.getString("proxyType", "GAE"); sitekey = settings.getString("sitekey", ""); try { port = Integer.valueOf(settings.getString("port", "1984")); } catch (NumberFormatException ex) { port = 1984; } isGlobalProxy = settings.getBoolean("isGlobalProxy", false); isGFWList = settings.getBoolean("isGFWList", false); isBypassApps = settings.getBoolean("isBypassApps", false); if (!parseProxyURL(settings.getString("proxy", "proxyofmax.appspot.com"))) { stopSelf(); return; } if (!"GAE".equals(proxyType) && !"PaaS".equals(proxyType)) { proxyType = "GAE"; } if ("fetch.py".equals(appPath)) appPath = "2"; Log.e(TAG, "Proxy: " + appId + " " + appPath); Log.e(TAG, "Local Port: " + port); new Thread(new Runnable() { @Override public void run() { handler.sendEmptyMessage(MSG_CONNECT_START); Log.d(TAG, "IPTABLES: " + Utils.getIptables()); // Test for Redirect Support hasRedirectSupport = Utils.getHasRedirectSupport(); if (handleConnection()) { // Connection and forward successful notifyAlert(getString(R.string.forward_success), getString(R.string.service_running)); handler.sendEmptyMessageDelayed(MSG_CONNECT_SUCCESS, 500); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.on); AppWidgetManager awm = AppWidgetManager.getInstance(GAEProxyService.this); awm.updateAppWidget( awm.getAppWidgetIds( new ComponentName(GAEProxyService.this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } } else { // Connection or forward unsuccessful notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)); stopSelf(); handler.sendEmptyMessageDelayed(MSG_CONNECT_FAIL, 500); } handler.sendEmptyMessageDelayed(MSG_CONNECT_FINISH, 500); } }).start(); markServiceStarted(); }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
private Intent buildIntent(String action, String uri, String type, JSONObject extras, String packagename, String classname, JSONArray categories) throws JSONException { Intent intent = new Intent(action); intent.setDataAndType(uri != null ? Uri.parse(uri) : null, type); if (packagename != null && classname != null) { intent.setComponent(new ComponentName(packagename, classname)); }/*from w ww .j a v a 2 s . c o m*/ if (extras != null) { putExtrasFromJsonObject(extras, intent); } if (categories != null) { for (int i = 0; i < categories.length(); i++) { intent.addCategory(categories.getString(i)); } } return intent; }
From source file:com.bluros.music.MusicService.java
@Override public void onCreate() { if (D)//w w w . j av a 2s .c om Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setUpMediaSession(); mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); 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(SLEEP_MODE_STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); filter.addAction(RemoteSelectDialog.REMOTE_START_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_CONNECT); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); 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 wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:com.android.server.telecom.testapps.TestConnectionService.java
@Override public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerAccount, final ConnectionRequest request) { PhoneAccountHandle accountHandle = request.getAccountHandle(); ComponentName componentName = new ComponentName(this, TestConnectionService.class); if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) { final TestConnection connection = new TestConnection(true); // Get the stashed intent extra that determines if this is a video call or audio call. Bundle extras = request.getExtras(); boolean isVideoCall = extras.getBoolean(EXTRA_IS_VIDEO_CALL); Uri providedHandle = extras.getParcelable(EXTRA_HANDLE); // Use dummy number for testing incoming calls. Uri address = providedHandle == null ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(isVideoCall), null) : providedHandle;/*ww w . j av a 2 s . co m*/ int videoState = isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY; connection.setVideoState(videoState); setAddress(connection, address); addVideoProvider(connection); addCall(connection); ConnectionRequest newRequest = new ConnectionRequest(request.getAccountHandle(), address, request.getExtras(), videoState); connection.setVideoState(videoState); return connection; } else { return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR, "Invalid inputs: " + accountHandle + " " + componentName)); } }
From source file:com.darshancomputing.BatteryIndicator.CurrentInfoFragment.java
private void mStartActivity(Class c) { ComponentName comp = new ComponentName(activity.context.getPackageName(), c.getName()); //startActivity(new Intent().setComponent(comp)); startActivityForResult(new Intent().setComponent(comp), 1); //activity.finish(); }