List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:android.support.v7.internal.widget.ActivityChooserModel.java
/** * Chooses a activity to handle the current intent. This will result in * adding a historical record for that action and construct intent with * its component name set such that it can be immediately started by the * client./*from ww w . j a va 2 s . c o m*/ * <p> * <strong>Note:</strong> By calling this method the client guarantees * that the returned intent will be started. This intent is returned to * the client solely to let additional customization before the start. * </p> * * @return An {@link Intent} for launching the activity or null if the * policy has consumed the intent or there is not current intent * set via {@link #setIntent(Intent)}. * * @see HistoricalRecord * @see OnChooseActivityListener */ public Intent chooseActivity(int index) { synchronized (mInstanceLock) { if (mIntent == null) { return null; } ensureConsistentState(); ActivityResolveInfo chosenActivity = mActivities.get(index); ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name); Intent choiceIntent = new Intent(mIntent); choiceIntent.setComponent(chosenName); if (mActivityChoserModelPolicy != null) { // Do not allow the policy to change the intent. Intent choiceIntentCopy = new Intent(choiceIntent); final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntentCopy); if (handled) { return null; } } HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT); addHisoricalRecord(historicalRecord); return choiceIntent; } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
/** * Create the component name for this class * * @param context The Context in which the widgets for this component are created * @return the ComponentName unique to DigitalAppWidgetProvider *//* ww w.j a va2 s .c om*/ private ComponentName getComponentName(Context context) { if (mComponentName == null) { mComponentName = new ComponentName(context, getClass()); } return mComponentName; }
From source file:com.google.appinventor.components.runtime.ProbeBase.java
@SimpleFunction(description = "Create a notication with message to wake up " + "another activity when tap on the notification") public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate, String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException { Intent activityToLaunch = new Intent(Intent.ACTION_MAIN); Log.i(TAG, "packageName: " + packageName); Log.i(TAG, "className: " + className); // for local AI instance, all classes are under the package // "appinventor.ai_test" // but for those runs on Google AppSpot(AppEngine), the package name will be // "appinventor.ai_GoogleAccountUserName" // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1 ComponentName component = new ComponentName(packageName, className); activityToLaunch.setComponent(component); activityToLaunch.putExtra(extraKey, extraVal); Log.i(TAG, "we found the class for intent to send into notificaiton"); activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0); Long currentTimeMillis = System.currentTimeMillis(); notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis); Log.i(TAG, "After creating notification"); notification.contentIntent = mContentIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; // reset the notification notification.defaults = 0;/* w ww .ja v a 2 s.c o m*/ if (enabledSound) notification.defaults |= Notification.DEFAULT_SOUND; if (enabledVibrate) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text, mContentIntent); Log.i(TAG, "after updated notification contents"); mNM.notify(PROBE_NOTIFICATION_ID, notification); Log.i(TAG, "notified"); }
From source file:com.actionbarsherlock.widget.ActivityChooserModel.java
/** * Chooses a activity to handle the current intent. This will result in * adding a historical record for that action and construct intent with * its component name set such that it can be immediately started by the * client./*from ww w. j a v a 2 s . c o m*/ * <p> * <strong>Note:</strong> By calling this method the client guarantees * that the returned intent will be started. This intent is returned to * the client solely to let additional customization before the start. * </p> * * @return An {@link Intent} for launching the activity or null if the * policy has consumed the intent. * * @see HistoricalRecord * @see OnChooseActivityListener */ public Intent chooseActivity(int index) { ActivityResolveInfo chosenActivity = mActivites.get(index); ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name); Intent choiceIntent = new Intent(mIntent); choiceIntent.setComponent(chosenName); if (mActivityChoserModelPolicy != null) { // Do not allow the policy to change the intent. Intent choiceIntentCopy = new Intent(choiceIntent); final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntentCopy); if (handled) { return null; } } HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT); addHisoricalRecord(historicalRecord); return choiceIntent; }
From source file:com.chummy.jezebel.material.dark.activities.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context = this; mPrefs = new Preferences(Main.this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from ww w . j ava 2 s . c om*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); thaApp = getResources().getString(R.string.app_name); thaHome = getResources().getString(R.string.section_one); thaPreviews = getResources().getString(R.string.section_two); thaApply = getResources().getString(R.string.section_three); thaWalls = getResources().getString(R.string.section_four); thaRequest = getResources().getString(R.string.section_five); thaCredits = getResources().getString(R.string.section_seven); thaTesters = getResources().getString(R.string.section_eight); thaWhatIsThemed = getResources().getString(R.string.section_nine); thaContactUs = getResources().getString(R.string.section_ten); thaLogcat = getResources().getString(R.string.section_eleven); thaFAQ = getResources().getString(R.string.section_twelve); thaHelp = getResources().getString(R.string.section_thirteen); thaAbout = getResources().getString(R.string.section_fourteen); thaIconPack = getResources().getString(R.string.section_fifteen); thaFullChangelog = getResources().getString(R.string.section_sixteen); thaRebuild = getResources().getString(R.string.section_seventeen); drawerVersion = getResources().getString(R.string.version_code); currentItem = 1; headerResult = new AccountHeader().withActivity(this).withHeaderBackground(R.drawable.header) .withSelectionFirstLine(getResources().getString(R.string.app_name)) .withSelectionSecondLine(drawerVersion).withSavedInstance(savedInstanceState).withHeightDp(120) .build(); enable_features = mPrefs.isFeaturesEnabled(); firstrun = mPrefs.isFirstRun(); result = new Drawer().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult) .withHeaderDivider(false).withDrawerWidthDp(400) .addDrawerItems(new SectionDrawerItem().withName("Main"), new PrimaryDrawerItem().withName(thaHome).withIcon(GoogleMaterial.Icon.gmd_home) .withIdentifier(1), new PrimaryDrawerItem().withName(thaIconPack) .withIcon(GoogleMaterial.Icon.gmd_picture_in_picture) .withDescription("This applies icon pack 'Whicons'.").withCheckable(false) .withIdentifier(11), new PrimaryDrawerItem().withName(thaFullChangelog) .withIcon(GoogleMaterial.Icon.gmd_wrap_text) .withDescription("Complete changelog of Dark Material.").withCheckable(false) .withIdentifier(12), new DividerDrawerItem(), new SectionDrawerItem().withName("Information"), new PrimaryDrawerItem().withName(thaAbout).withIcon(GoogleMaterial.Icon.gmd_info_outline) .withDescription("Basic information on the theme.").withIdentifier(10), new PrimaryDrawerItem().withName(thaWhatIsThemed).withIcon(GoogleMaterial.Icon.gmd_warning) .withDescription("List of overlaid applications.").withIdentifier(3), new PrimaryDrawerItem().withName(thaFAQ).withIcon(GoogleMaterial.Icon.gmd_question_answer) .withDescription("Common questions with answers.").withIdentifier(8), new DividerDrawerItem(), new SectionDrawerItem().withName("Tools & Utilities"), new PrimaryDrawerItem().withName(thaRebuild).withIcon(GoogleMaterial.Icon.gmd_sync) .withDescription("A rebuild a day keeps the RRs away!").withCheckable(false) .withBadge("ROOT ").withIdentifier(13), new PrimaryDrawerItem().withName(thaLogcat).withIcon(GoogleMaterial.Icon.gmd_bug_report) .withDescription("System level log recording.").withCheckable(false) .withBadge("ROOT ").withIdentifier(7), new DividerDrawerItem(), new SectionDrawerItem().withName("The Developers"), new PrimaryDrawerItem().withName(thaCredits).withIcon(GoogleMaterial.Icon.gmd_people) .withDescription("chummy development team").withIdentifier(5), new PrimaryDrawerItem().withName(thaTesters).withIcon(GoogleMaterial.Icon.gmd_star) .withDescription("The people who keep the team updated.").withIdentifier(4), new DividerDrawerItem(), new SectionDrawerItem().withName("Contact"), new SecondaryDrawerItem().withName(thaContactUs).withIcon(GoogleMaterial.Icon.gmd_mail) .withCheckable(false).withIdentifier(6), new SecondaryDrawerItem().withName(thaHelp).withIcon(GoogleMaterial.Icon.gmd_help) .withCheckable(true).withIdentifier(9)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { if (drawerItem != null) { switch (drawerItem.getIdentifier()) { case 1: switchFragment(1, thaApp, "Home"); break; case 2: ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (isConnected) { switchFragment(2, thaWalls, "Wallpapers"); } else { showNotConnectedDialog(); } break; case 3: switchFragment(3, thaWhatIsThemed, "WhatIsThemed"); break; case 4: switchFragment(4, thaTesters, "Testers"); break; case 5: switchFragment(5, thaCredits, "Credits"); break; case 6: StringBuilder emailBuilder = new StringBuilder(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:" + getResources().getString(R.string.email_id))); if (!isAppInstalled("org.cyanogenmod.theme.chooser")) { if (!isAppInstalled("com.cyngn.theme.chooser")) { if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject)); } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_rro)); } } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cos)); } } else { intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cm)); } emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "(" + Build.VERSION.INCREMENTAL + ")"); emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " (" + Build.VERSION.RELEASE + ") " + "[" + Build.ID + "]"); emailBuilder.append("\nDevice: " + Build.DEVICE); emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER); emailBuilder.append( "\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")"); if (!isAppInstalled("org.cyanogenmod.theme.chooser")) { if (!isAppInstalled("com.cyngn.theme.chooser")) { if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) { emailBuilder.append("\nTheme Engine: Not Available"); } else { emailBuilder.append("\nTheme Engine: Layers Manager (RRO)"); } } else { emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine"); } } else { emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine"); } PackageInfo appInfo = null; try { appInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } emailBuilder.append("\nApp Version Name: " + appInfo.versionName); emailBuilder.append("\nApp Version Code: " + appInfo.versionCode); intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()); startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title)))); break; case 7: if (Shell.SU.available()) { if (!isAppInstalled("com.tooleap.logcat")) { if (!isAppInstalled("com.nolanlawson.logcat")) { Intent logcat = new Intent(Intent.ACTION_VIEW, Uri.parse( getResources().getString(R.string.play_store_link_logcat))); startActivity(logcat); } else { Intent intent_logcat = getPackageManager() .getLaunchIntentForPackage("com.nolanlawson.logcat"); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.logcat_toast), Toast.LENGTH_LONG); toast.show(); startActivity(intent_logcat); } } else { Intent intent_tooleap = getPackageManager() .getLaunchIntentForPackage("com.tooleap.logcat"); Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.logcat_toast), Toast.LENGTH_LONG); toast.show(); startActivity(intent_tooleap); } } else { Toast toast = Toast.makeText(getApplicationContext(), "Unfortunately, this feature is only available for root users.", Toast.LENGTH_LONG); toast.show(); } break; case 8: switchFragment(8, thaFAQ, "FAQ"); break; case 9: switchFragment(9, thaHelp, "Help"); break; case 10: switchFragment(10, thaAbout, "About"); break; case 11: Intent launch_whicons = new Intent("android.intent.action.MAIN"); launch_whicons.setComponent(new ComponentName("org.cyanogenmod.theme.chooser", "org.cyanogenmod.theme.chooser.ChooserActivity")); launch_whicons.putExtra("pkgName", "com.whicons.iconpack"); Intent launch_whicons_cos = new Intent("android.intent.action.MAIN"); launch_whicons_cos.setComponent(new ComponentName("com.cyngn.theme.chooser", "com.cyngn.theme.chooser.ChooserActivity")); launch_whicons_cos.putExtra("pkgName", "com.whicons.iconpack"); Intent devPlay = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.play_store_whicons))); Intent intent_whicons = getPackageManager() .getLaunchIntentForPackage("com.whicons.iconpack"); if (intent_whicons == null) { startActivity(devPlay); } else { if (isAppInstalled("org.cyanogenmod.theme.chooser")) { startActivity(launch_whicons); } else { if (isAppInstalled("com.cyngn.theme.chooser")) { Toast toast = Toast.makeText(getApplicationContext(), "Select Dark Material, click Customize and locate Default Icons. Then select Whicons and click Apply.", Toast.LENGTH_LONG); toast.show(); startActivity(launch_whicons_cos); } else { startActivity(intent_whicons); } } } break; case 12: fullchangelog(); break; case 13: if (Shell.SU.available()) { rebuildThemeCache(); } else { Toast toast = Toast.makeText(getApplicationContext(), "Unfortunately, this feature is only available for root users.", Toast.LENGTH_LONG); toast.show(); } break; } } } }).withSavedInstance(savedInstanceState).build(); result.getListView().setVerticalScrollBarEnabled(false); // Check for permissions first so that we don't have any issues down the road int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { // permission already granted, allow the program to continue running runLicenseChecker(); } else { // permission not granted, request it from the user ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } if (savedInstanceState == null) { result.setSelectionByIdentifier(1); } }
From source file:com.av.remusic.service.MediaService.java
@Override public void onCreate() { if (D)//from ww w . j av a 2 s .c o m Log.d(TAG, "Creating service"); super.onCreate(); mGetUrlThread.start(); mLrcThread.start(); mProxy = new MediaPlayerProxy(this); mProxy.init(); mProxy.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // 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); filter.addAction(TRY_GET_TRACKINFO); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(LOCK_SCREEN); filter.addAction(SEND_PROGRESS); filter.addAction(SETQUEUE); // 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, MediaService.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.purenexussettings.TinkerActivity.java
public void launchcLock() { Intent link = new Intent(Intent.ACTION_MAIN); ComponentName cn = new ComponentName(KEY_LOCK_CLOCK_PACKAGE_NAME, KEY_LOCK_CLOCK_CLASS_NAME); link.setComponent(cn);//from w w w . j a va 2s . c om startActivity(link); }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
@Override public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller, Intent[] specifics, Intent intent, int flags, 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(group);//from ww w. j a va 2 s . co 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(group, id, categoryOrder, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)) .setIntent(rintent); if (outSpecificItems != null && ri.specificIndex >= 0) { outSpecificItems[ri.specificIndex] = item; } } return N; }
From source file:com.android.server.telecom.testapps.TestConnectionService.java
@Override public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount, 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(false); final Bundle extras = request.getExtras(); final Uri providedHandle = extras.getParcelable(EXTRA_HANDLE); Uri handle = providedHandle == null ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(false), null) : providedHandle;// w w w . ja va 2 s. co m connection.setAddress(handle, TelecomManager.PRESENTATION_ALLOWED); connection.setDialing(); addCall(connection); return connection; } else { return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR, "Invalid inputs: " + accountHandle + " " + componentName)); } }
From source file:com.android.contacts.DynamicShortcuts.java
@VisibleForTesting void scheduleUpdateJob() { final JobInfo job = new JobInfo.Builder(ContactsJobService.DYNAMIC_SHORTCUTS_JOB_ID, new ComponentName(mContext, ContactsJobService.class)) // We just observe all changes to contacts. It would be better to be more granular // but CP2 only notifies using this URI anyway so there isn't any point in adding // that complexity. .addTriggerContentUri(new JobInfo.TriggerContentUri(ContactsContract.AUTHORITY_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS)) .setTriggerContentUpdateDelay(mContentChangeMinUpdateDelay) .setTriggerContentMaxDelay(mContentChangeMaxUpdateDelay).build(); mJobScheduler.schedule(job);// w w w . j av a 2s.c om }