List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.androzic.location.LocationService.java
private Notification getNotification() { int msgId = R.string.notif_loc_started; int ntfId = R.drawable.ic_stat_locating; if (trackingEnabled) { msgId = R.string.notif_trk_started; ntfId = R.drawable.ic_stat_tracking; }// w w w. ja v a2 s . c om if (gpsStatus != LocationService.GPS_OK) { msgId = R.string.notif_loc_waiting; ntfId = R.drawable.ic_stat_waiting; } if (gpsStatus == LocationService.GPS_OFF) { ntfId = R.drawable.ic_stat_off; } if (errorTime > 0) { msgId = R.string.notif_trk_failure; ntfId = R.drawable.ic_stat_failure; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setWhen(errorTime); builder.setSmallIcon(ntfId); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(getApplicationContext(), Splash.class)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, intent, 0); builder.setContentIntent(contentIntent); builder.setContentTitle(getText(R.string.notif_loc_short)); if (errorTime > 0 && DEBUG_ERRORS) builder.setContentText(errorMsg); else builder.setContentText(getText(msgId)); builder.setOngoing(true); Notification notification = builder.getNotification(); return notification; }
From source file:edu.umich.oasis.service.Sandbox.java
private Sandbox(int id) { mID = id;//from w w w . jav a 2 s . c o m mApplication = OASISApplication.getInstance(); try { Class<?> clazz = Class.forName(String.format(SandboxService.SERVICE_FORMAT, id)); PackageManager pm = mApplication.getPackageManager(); mComponent = new ComponentName(mApplication, clazz); ServiceInfo svcInfo = pm.getServiceInfo(mComponent, 0); if ((svcInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) { throw new RuntimeException("Sandbox " + id + " is not isolated!"); } } catch (ClassNotFoundException cnfe) { Log.e(TAG, "Could not load sandbox class", cnfe); throw new RuntimeException(cnfe); } catch (PackageManager.NameNotFoundException nnfe) { Log.e(TAG, "Service class not declared in manifest", nnfe); throw new RuntimeException(nnfe); } mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { handleConnected(service); } @Override public void onServiceDisconnected(ComponentName name) { handleDisconnected(); } }; mSandboxService = null; mTaintSet = null; mIsRestarting = false; g_onCreated.fire(this, null); }
From source file:edu.umich.flowfence.service.Sandbox.java
private Sandbox(int id) { mID = id;/*from w w w .j a v a2s.c o m*/ mApplication = FlowfenceApplication.getInstance(); try { Class<?> clazz = Class.forName(String.format(SandboxService.SERVICE_FORMAT, id)); PackageManager pm = mApplication.getPackageManager(); mComponent = new ComponentName(mApplication, clazz); ServiceInfo svcInfo = pm.getServiceInfo(mComponent, 0); if ((svcInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) { throw new RuntimeException("Sandbox " + id + " is not isolated!"); } } catch (ClassNotFoundException cnfe) { Log.e(TAG, "Could not load sandbox class", cnfe); throw new RuntimeException(cnfe); } catch (PackageManager.NameNotFoundException nnfe) { Log.e(TAG, "Service class not declared in manifest", nnfe); throw new RuntimeException(nnfe); } mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { handleConnected(service); } @Override public void onServiceDisconnected(ComponentName name) { handleDisconnected(); } }; mSandboxService = null; mTaintSet = null; mIsRestarting = false; g_onCreated.fire(this, null); }
From source file:com.darshancomputing.alockblock.ALockBlockService.java
private void minimize() { mNotificationManager.cancelAll();//from w ww.ja v a2 s. c om stopForeground(true); if (!settings.getBoolean(SettingsActivity.KEY_ALWAYS_SHOW_NOTIFICATION, false)) return; Intent mainWindowIntent = new Intent(context, ALockBlockActivity.class); mainWindowPendingIntent = PendingIntent.getActivity(context, 0, mainWindowIntent, 0); ComponentName comp = new ComponentName(getPackageName(), ALockBlockService.class.getName()); Intent disableIntent = new Intent().setComponent(comp).putExtra(EXTRA_ACTION, ACTION_DISABLE); PendingIntent disablePendingIntent = PendingIntent.getService(this, 0, disableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder kgunb = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.kg_unlocked) .setLargeIcon(largeIconL).setContentTitle("Lock Screen Enabled").setContentText("A Lock Block") .setContentIntent(mainWindowPendingIntent).setShowWhen(false).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN); if (settings.getBoolean(SettingsActivity.KEY_REENABLE_FROM_NOTIFICATION, false)) kgunb.addAction(R.drawable.ic_menu_login, "Disable", disablePendingIntent); mNotificationManager.notify(NOTIFICATION_KG_UNLOCKED, kgunb.build()); }
From source file:com.cognizant.trumobi.em.Email.java
public static void setServicesEnabled(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /*//ww w. j ava 2 s .c o m * If no accounts now exist but the service is still enabled we're * about to disable it so we'll reschedule to kill off any existing * alarms. */ EmMailService.actionReschedule(context); } pm.setComponentEnabledSetting(new ComponentName(context, EmMessageCompose.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmAccountShortcutPicker.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmMailService.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /* * And now if accounts do exist then we've just enabled the service * and we want to schedule alarms for the new accounts. */ EmMailService.actionReschedule(context); } }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
private VideoChromeCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) {/*www. ja v a2s .com*/ super(context, applicationId); mContext = context; Log.d(TAG, "VideoChromeCastManager is instantiated"); mVideoConsumers = Collections.synchronizedSet(new HashSet<IVideoCastConsumer>()); mDataNamespace = dataNamespace; if (null == targetActivity) { targetActivity = VideoPlayerActivity.class; } mTargetActivity = targetActivity; Utils.saveStringToPreference(context, Constants.PREFS_KEY_CAST_ACTIVITY_NAME, mTargetActivity.getName()); mMiniControllers = Collections.synchronizedSet(new HashSet<IMiniController>()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(context, VideoIntentReceiver.class); mHandler = new Handler(new UpdateNotificationHandlerCallback()); }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
private VideoCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) { super(context, applicationId); LOGD(TAG, "VideoCastManager is instantiated"); mVideoConsumers = Collections.synchronizedSet(new HashSet<IVideoCastConsumer>()); mDataNamespace = dataNamespace;/*from w w w . j a v a 2 s. c o 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); mHandler = new Handler(new UpdateNotificationHandlerCallback()); }
From source file:name.setup.dance.StepService.java
/** * Show a notification while this service is running. *//*from w w w . j a v a 2 s . c om*/ private void showNotification() { CharSequence text = getText(R.string.app_name); Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent DanceStepAppIntent = new Intent(); DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class)); DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }
From source file:com.example.android.mediarouter.player.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); if (savedInstanceState != null) { mPlayer = (Player) savedInstanceState.getSerializable("mPlayer"); }//from w w w . ja v a2s . c o m // Get the media router service. mMediaRouter = MediaRouter.getInstance(this); // Create a route selector for the type of routes that we care about. mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build(); // Add a fragment to take care of media route discovery. // This fragment automatically adds or removes a callback whenever the activity // is started or stopped. FragmentManager fm = getSupportFragmentManager(); DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG); if (fragment == null) { fragment = new DiscoveryFragment(mMediaRouterCB); fragment.setRouteSelector(mSelector); fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit(); } else { fragment.setCallback(mMediaRouterCB); fragment.setRouteSelector(mSelector); } // Populate an array adapter with streaming media items. String[] mediaNames = getResources().getStringArray(R.array.media_names); String[] mediaUris = getResources().getStringArray(R.array.media_uris); mLibraryItems = new LibraryAdapter(); for (int i = 0; i < mediaNames.length; i++) { mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4")); } // Scan local external storage directory for media files. File externalDir = Environment.getExternalStorageDirectory(); if (externalDir != null) { File list[] = externalDir.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { String filename = list[i].getName(); if (filename.matches(".*\\.(m4v|mp4)")) { mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4")); } } } } mPlayListItems = new PlaylistAdapter(); // Initialize the layout. setContentView(R.layout.sample_media_router); TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); String tabName = getResources().getString(R.string.library_tab_text); TabSpec spec1 = tabHost.newTabSpec(tabName); spec1.setContent(R.id.tab1); spec1.setIndicator(tabName); tabName = getResources().getString(R.string.playlist_tab_text); TabSpec spec2 = tabHost.newTabSpec(tabName); spec2.setIndicator(tabName); spec2.setContent(R.id.tab2); tabName = getResources().getString(R.string.statistics_tab_text); TabSpec spec3 = tabHost.newTabSpec(tabName); spec3.setIndicator(tabName); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { updateUi(); } }); mLibraryView = (ListView) findViewById(R.id.media); mLibraryView.setAdapter(mLibraryItems); mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mLibraryView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mPlayListView = (ListView) findViewById(R.id.playlist); mPlayListView.setAdapter(mPlayListItems); mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mPlayListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mInfoTextView = (TextView) findViewById(R.id.info); mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button); mPauseResumeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = !mPaused; if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } } }); mStopButton = (ImageButton) findViewById(R.id.stop_button); mStopButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = false; mSessionManager.stop(); } }); mSeekBar = (SeekBar) findViewById(R.id.seekbar); mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { PlaylistItem item = getCheckedPlaylistItem(); if (fromUser && item != null && item.getDuration() > 0) { long pos = progress * item.getDuration() / 100; mSessionManager.seek(item.getItemId(), pos); item.setPosition(pos); item.setTimestamp(SystemClock.elapsedRealtime()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { mSeeking = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { mSeeking = false; updateUi(); } }); // Schedule Ui update mHandler.postDelayed(mUpdateSeekRunnable, 1000); // Build the PendingIntent for the remote control client mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mEventReceiver); mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // Create and register the remote control client registerRemoteControlClient(); // Set up playback manager and player mPlayer = Player.create(MainActivity.this, mMediaRouter.getSelectedRoute()); mSessionManager.setPlayer(mPlayer); mSessionManager.setCallback(new SessionManager.Callback() { @Override public void onStatusChanged() { updateUi(); } @Override public void onItemChanged(PlaylistItem item) { } }); updateUi(); }
From source file:com.example.android.mediarouter.player.RadioActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); if (savedInstanceState != null) { mPlayer = (RadioPlayer) savedInstanceState.getSerializable("mPlayer"); }//w ww . j av a2 s . com // Get the media router service. mMediaRouter = MediaRouter.getInstance(this); // Create a route selector for the type of routes that we care about. mSelector = new MediaRouteSelector.Builder().addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO) .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .addControlCategory(SampleMediaRouteProvider.CATEGORY_SAMPLE_ROUTE).build(); // Add a fragment to take care of media route discovery. // This fragment automatically adds or removes a callback whenever the activity // is started or stopped. FragmentManager fm = getSupportFragmentManager(); DiscoveryFragment fragment = (DiscoveryFragment) fm.findFragmentByTag(DISCOVERY_FRAGMENT_TAG); if (fragment == null) { fragment = new DiscoveryFragment(mMediaRouterCB); fragment.setRouteSelector(mSelector); fm.beginTransaction().add(fragment, DISCOVERY_FRAGMENT_TAG).commit(); } else { fragment.setCallback(mMediaRouterCB); fragment.setRouteSelector(mSelector); } // Populate an array adapter with streaming media items. String[] mediaNames = getResources().getStringArray(R.array.media_names); String[] mediaUris = getResources().getStringArray(R.array.media_uris); mLibraryItems = new LibraryAdapter(); for (int i = 0; i < mediaNames.length; i++) { mLibraryItems.add(new MediaItem("[streaming] " + mediaNames[i], Uri.parse(mediaUris[i]), "video/mp4")); } // Scan local external storage directory for media files. File externalDir = Environment.getExternalStorageDirectory(); if (externalDir != null) { File list[] = externalDir.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { String filename = list[i].getName(); if (filename.matches(".*\\.(m4v|mp4)")) { mLibraryItems.add(new MediaItem("[local] " + filename, Uri.fromFile(list[i]), "video/mp4")); } } } } mPlayListItems = new PlaylistAdapter(); // Initialize the layout. setContentView(R.layout.sample_radio_router); TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); String tabName = getResources().getString(R.string.library_tab_text); TabSpec spec1 = tabHost.newTabSpec(tabName); spec1.setContent(R.id.tab1); spec1.setIndicator(tabName); tabName = getResources().getString(R.string.playlist_tab_text); TabSpec spec2 = tabHost.newTabSpec(tabName); spec2.setIndicator(tabName); spec2.setContent(R.id.tab2); tabName = getResources().getString(R.string.statistics_tab_text); TabSpec spec3 = tabHost.newTabSpec(tabName); spec3.setIndicator(tabName); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { updateUi(); } }); mLibraryView = (ListView) findViewById(R.id.media); mLibraryView.setAdapter(mLibraryItems); mLibraryView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mLibraryView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mPlayListView = (ListView) findViewById(R.id.playlist); mPlayListView.setAdapter(mPlayListItems); mPlayListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mPlayListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateButtons(); } }); mInfoTextView = (TextView) findViewById(R.id.info); mPauseResumeButton = (ImageButton) findViewById(R.id.pause_resume_button); mPauseResumeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = !mPaused; if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } } }); mStopButton = (ImageButton) findViewById(R.id.stop_button); mStopButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPaused = false; mSessionManager.stop(); } }); mSeekBar = (SeekBar) findViewById(R.id.seekbar); mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { PlaylistItem item = getCheckedPlaylistItem(); if (fromUser && item != null && item.getDuration() > 0) { long pos = progress * item.getDuration() / 100; mSessionManager.seek(item.getItemId(), pos); item.setPosition(pos); item.setTimestamp(SystemClock.elapsedRealtime()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { mSeeking = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { mSeeking = false; updateUi(); } }); // Schedule Ui update mHandler.postDelayed(mUpdateSeekRunnable, 1000); // Build the PendingIntent for the remote control client mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mEventReceiver = new ComponentName(getPackageName(), SampleMediaButtonReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mEventReceiver); mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // Create and register the remote control client registerRemoteControlClient(); // Set up playback manager and player mPlayer = RadioPlayer.create(RadioActivity.this, mMediaRouter.getSelectedRoute()); mSessionManager.setPlayer(mPlayer); mSessionManager.setCallback(new RadioSessionManager.Callback() { @Override public void onStatusChanged() { updateUi(); } @Override public void onItemChanged(PlaylistItem item) { } }); updateUi(); }