List of usage examples for android.content ComponentName getClassName
public @NonNull String getClassName()
From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java
private String debugIntent(final Intent intent) { final ComponentName callingActivity = getCallingActivity(); final StringBuilder stringBuilder = new StringBuilder(); final Bundle extras = intent.getExtras(); stringBuilder.append("SimpleLibraryActivity started with invalid extra"); if (callingActivity != null) { stringBuilder.append(", calling activity: "); stringBuilder.append(callingActivity.getClassName()); }/*from w w w. ja va2 s .c o m*/ if (extras != null) { for (final String what : extras.keySet()) { stringBuilder.append(", intent extra: "); stringBuilder.append(what); } } stringBuilder.append('.'); return stringBuilder.toString(); }
From source file:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java
/** * @param packageName//from ww w.j av a 2s .c o m * @return checks if a particular application is in the foreground */ public boolean isForeground(final String packageName) { // Get the Activity Manager ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); // Get a list of running tasks, we are only interested in the last one, // the top most so we give a 1 as parameter so we only get the topmost. final List<ActivityManager.RunningTaskInfo> task = manager.getRunningTasks(1); // Get the info we need for comparison. final ComponentName componentInfo = task.get(0).topActivity; // Check if it matches our package name. if (componentInfo.getPackageName().equals(packageName) && componentInfo.getClassName().contains("SecondActivity")) return true; // If not then our app is not on the foreground. return false; }
From source file:com.launcher.silverfish.HomeScreenFragment.java
private void loadWidget() { ComponentName cn = sqlHelper.getWidgetContentName(); Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName()); // Check that there actually is a widget in the database if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) { Log.d("Widget creation", "DB was empty"); return;/* w w w. jav a 2s. com*/ } Log.d("Widget creation", "DB was not empty"); final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders(); // Get AppWidgetProviderInfo AppWidgetProviderInfo appWidgetInfo = null; // Just in case you want to see all package and class names of installed widget providers, // this code is useful for (final AppWidgetProviderInfo info : infos) { Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName()); } // Iterate through all infos, trying to find the desired one for (final AppWidgetProviderInfo info : infos) { if (info.provider.getClassName().equals(cn.getClassName()) && info.provider.getPackageName().equals(cn.getPackageName())) { // We found it! appWidgetInfo = info; break; } } if (appWidgetInfo == null) { Log.d("Widget creation", "app info was null"); return; // Stop here } // Allocate the hosted widget id int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn); // Ask the user to allow this app to have access to their widgets if (!allowed_to_bind) { Log.d("Widget creation", "asking for permission"); Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); Bundle args = new Bundle(); args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn); if (Build.VERSION.SDK_INT >= 21) { args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null); } i.putExtras(args); startActivityForResult(i, REQUEST_BIND_APPWIDGET); return; } else { Log.d("Widget creation", "Allowed to bind"); Log.d("Widget creation", "creating widget"); //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); //createWidgetFromId(appWidgetId); } // Create the host view AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId, appWidgetInfo); // Set the desired widget hostView.setAppWidget(appWidgetId, appWidgetInfo); placeWidget(hostView); }
From source file:com.achep.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();// w w w.j a va 2s . c o m final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(android.R.id.content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:com.bullmobi.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();// w ww. j a va 2 s .c o m final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(R.id.main_content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java
private void loadWidget() { ComponentName cn = settings.getWidget(); Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName()); // Check that there actually is a widget in the database if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) { Log.d("Widget creation", "DB was empty"); return;// w w w . j a v a2 s . co m } Log.d("Widget creation", "DB was not empty"); final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders(); // Get AppWidgetProviderInfo AppWidgetProviderInfo appWidgetInfo = null; // Just in case you want to see all package and class names of installed widget providers, // this code is useful for (final AppWidgetProviderInfo info : infos) { Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName()); } // Iterate through all infos, trying to find the desired one for (final AppWidgetProviderInfo info : infos) { if (info.provider.getClassName().equals(cn.getClassName()) && info.provider.getPackageName().equals(cn.getPackageName())) { // We found it! appWidgetInfo = info; break; } } if (appWidgetInfo == null) { Log.d("Widget creation", "app info was null"); return; // Stop here } // Allocate the hosted widget id int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn); // Ask the user to allow this app to have access to their widgets if (!allowed_to_bind) { Log.d("Widget creation", "asking for permission"); Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); Bundle args = new Bundle(); args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn); if (Build.VERSION.SDK_INT >= 21) { args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null); } i.putExtras(args); startActivityForResult(i, REQUEST_BIND_APPWIDGET); return; } else { Log.d("Widget creation", "Allowed to bind"); Log.d("Widget creation", "creating widget"); //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); //createWidgetFromId(appWidgetId); } // Create the host view AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId, appWidgetInfo); // Set the desired widget hostView.setAppWidget(appWidgetId, appWidgetInfo); placeWidget(hostView); }
From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java
private boolean isTopLevelTile(Intent intent) { final ComponentName componentName = intent.getComponent(); if (componentName == null) { return false; }//from w w w .j a v a 2s.c o m // Look for a tile that has the same component as incoming intent final List<DashboardCategory> categories = getDashboardCategories(); for (DashboardCategory category : categories) { for (Tile tile : category.tiles) { if (TextUtils.equals(tile.intent.getComponent().getClassName(), componentName.getClassName())) { if (DEBUG) { Log.d(TAG, "intent is for top level tile: " + tile.title); } return true; } } } if (DEBUG) { Log.d(TAG, "Intent is not for top level settings " + intent); } return false; }
From source file:com.android.leanlauncher.IconCache.java
private String findDrawableFromIconPack(String packageName, String className) { if (mIconPackDrawables == null || mIconPackDrawables.size() == 0) { return null; }/*from w w w. j a va 2 s. co m*/ String drawableName = null; for (ComponentName key : mIconPackDrawables.keySet()) { if (key.getPackageName().equalsIgnoreCase(packageName)) { drawableName = mIconPackDrawables.get(key); if (!TextUtils.isEmpty(drawableName)) { Log.d(TAG, drawableName + " -- found for -- " + packageName); if (className == null || className.equalsIgnoreCase(key.getClassName())) { // we've found it break; } } } } return drawableName; }
From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java
/** * <p>Only for developers, i.e. we are not going to localize these strings.</p> *//*from www . ja va 2 s .c om*/ private String[] getDetails() { String callingActivityClassName = null; String callingActivityPackageName = null; String pendingIntentTargetPackage = null; ComponentName callingActivity = getCallingActivity(); if (callingActivity != null) { callingActivityClassName = callingActivity.getClassName(); callingActivityPackageName = callingActivity.getPackageName(); } if (mExtraResultsPendingIntent != null) { pendingIntentTargetPackage = mExtraResultsPendingIntent.getTargetPackage(); } List<String> info = new ArrayList<String>(); info.add("ID: " + Utils.getUniqueId(PreferenceManager.getDefaultSharedPreferences(this))); info.add("User-Agent comment: " + mRecSessionBuilder.getUserAgentComment()); info.add("Calling activity class name: " + callingActivityClassName); info.add("Calling activity package name: " + callingActivityPackageName); info.add("Pending intent target package: " + pendingIntentTargetPackage); info.add("Selected grammar: " + mRecSessionBuilder.getGrammarUrl()); info.add("Selected target lang: " + mRecSessionBuilder.getGrammarTargetLang()); info.add("Selected server: " + mRecSessionBuilder.getServerUrl()); info.add("Intent action: " + getIntent().getAction()); info.addAll(Utils.ppBundle(mExtras)); return info.toArray(new String[info.size()]); }
From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.menu_run_intent: runIntent();//w w w. ja va 2 s . c o m return true; case R.id.set_editor_result: updateIntent(); setResult(0, new Intent().putExtra(Editor.EXTRA_VALUE, mEditedIntent)); finish(); return true; case R.id.attach_intent_filter: { // We have specified component, just find IntentFilters for it final ComponentName componentName = mEditedIntent.getComponent(); ExtendedPackageInfo.getExtendedPackageInfo(this, componentName.getPackageName(), new ExtendedPackageInfo.Callback() { @Override public void onPackageInfoAvailable(ExtendedPackageInfo extendedPackageInfo) { try { setAttachedIntentFilters(extendedPackageInfo .getComponentInfo(componentName.getClassName()).intentFilters); Toast.makeText(IntentEditorActivity.this, R.string.intent_filter_attached, Toast.LENGTH_SHORT).show(); } catch (NullPointerException e) { Toast.makeText(IntentEditorActivity.this, R.string.no_intent_filters_found, Toast.LENGTH_SHORT).show(); } } }); } return true; case R.id.detach_intent_filter: clearAttachedIntentFilters(); return true; case R.id.component_info: { ComponentName component = mEditedIntent.getComponent(); startActivity(new Intent(this, SingleFragmentActivity.class) .putExtra(SingleFragmentActivity.EXTRA_FRAGMENT, ComponentInfoFragment.class.getName()) .putExtra(ComponentInfoFragment.ARG_PACKAGE_NAME, component.getPackageName()) .putExtra(ComponentInfoFragment.ARG_COMPONENT_NAME, component.getClassName()) .putExtra(ComponentInfoFragment.ARG_LAUNCHED_FROM_INTENT_EDITOR, true)); } return true; case R.id.save: { updateIntent(); SavedItemsDatabase.getInstance(this).saveIntent(this, mEditedIntent, mComponentType, mMethodId); } return true; case R.id.track_intent: { if (!item.isChecked()) { XIntentsLab xIntentsLab = XIntentsLabStatic.getInstance(); if (xIntentsLab.havePermission()) { createIntentTracker(); } else { try { startIntentSenderForResult( xIntentsLab.getRequestPermissionIntent(getPackageName()).getIntentSender(), REQUEST_CODE_REQUEST_INTENT_TRACKER_PERMISSION, null, 0, 0, 0); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); // TODO: can we handle this? } } } else { removeIntentTracker(); } return true; } case R.id.disable_interception: getPackageManager().setComponentEnabledSetting( new ComponentName(this, IntentEditorInterceptedActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); Toast.makeText(this, R.string.interception_disabled, Toast.LENGTH_SHORT).show(); return true; default: return super.onOptionsItemSelected(item); } }