Android ComponentName - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ComponentName class.

This code example shows how to use the following methods:
  @Test 
  public void bindAppWidgetIdIfAllowed_shouldReturnThePresetBoolean() throws Exception { 
    shadowAppWidgetManager.setAllowedToBindAppWidgets(false);
    assertEquals(shadowAppWidgetManager.bindAppWidgetIdIfAllowed(12345, new ComponentName("", "")), false);
    shadowAppWidgetManager.setAllowedToBindAppWidgets(true);
    assertEquals(shadowAppWidgetManager.bindAppWidgetIdIfAllowed(12345, new ComponentName("", "")), true);
  } 
 
  @Test 
  public void bindAppWidgetIdIfAllowed_shouldRecordTheBinding() throws Exception { 
    ComponentName provider = new ComponentName("A", "B");
    appWidgetManager.bindAppWidgetIdIfAllowed(789, provider);
    assertArrayEquals(new int[]{789}, appWidgetManager.getAppWidgetIds(provider));
  } 
 
  @Test 
  public void bindAppWidgetId_shouldRecordAppWidgetInfo() throws Exception { 
    ComponentName provider = new ComponentName("abc", "123");
    AppWidgetProviderInfo providerInfo = new AppWidgetProviderInfo();
    providerInfo.provider = provider;
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString, setComponent
	public void onReceive(Context context, Intent intent) {
		// just make sure we are getting the right intent (better safe than sorry) 
		//String itclass = intent.get("intentclass"); 
		if ( "android.intent.action.BOOT_COMPLETED".equals(intent.getAction()) ||
				intent.getBooleanExtra("ThisIntentIsTPStartUpClass",false) ) {
			ComponentName comp = new ComponentName(context.getPackageName(), PingService.class.getName());
			ComponentName service = context.startService(new Intent().setComponent(comp));
			if (null == service){
				// something really wrong here 
				Log.e(TAG, "Could not start service " + comp.toString());
			} 
		} else { 
			Log.e(TAG, "Received unexpected intent " + intent.getAction());   
		} 
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:flattenToString
 
  public IntentAssert hasComponent(ComponentName expected) {
    ComponentName componentName = actual.getComponent();
    assertThat(componentName)
        .overridingErrorMessage("Expected component name <%s> but was <%s>.", 
            expected.flattenToString(), componentName.flattenToString())
        .isEqualTo(expected);
    return this;
  } 
 
  public IntentAssert hasComponent(Context context, Class<?> cls) {
    return hasComponent(new ComponentName(context, cls.getName()));
  } 
 
  public IntentAssert hasComponent(String appPkg, Class<?> cls) {
    return hasComponent(new ComponentName(appPkg, cls.getName()));
  } 
 
  public static String flagsToString(int flags) {
    return new BitMaskStringBuilder(flags) //
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
  public void testGetPreferredActivities() throws Exception { 
    // Setup an intentfilter and add to packagemanager 
    IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);
    final String packageName = "com.example.dummy";
    ComponentName name = new ComponentName(packageName, "LauncherActivity");
    rpm.addPreferredActivity(filter, 0, null, name);
 
    // Test match 
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);
 
    List<ComponentName> activities = new ArrayList<ComponentName>();
    rpm.getPreferredActivities(filters, activities, null);
 
    assertThat(activities.size()).isEqualTo(1);
    assertThat(activities.get(0).getPackageName()).isEqualTo(packageName);
 
    // Test not match 
    IntentFilter filter1 = new IntentFilter(Intent.ACTION_VIEW);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    public void testGetPreferredActivities() throws Exception { 
        // Setup an intentfilter and add to packagemanager 
        IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
        filter.addCategory(Intent.CATEGORY_HOME);
        final String packageName = "com.example.dummy";
        ComponentName name = new ComponentName(packageName, "LauncherActivity");
        rpm.addPreferredActivity(filter, 0, null, name);
 
        // Test match 
        List<IntentFilter> filters = new ArrayList<IntentFilter>();
        filters.add(filter);
 
        List<ComponentName> activities = new ArrayList<ComponentName>();
        rpm.getPreferredActivities(filters, activities, null);
 
        assertThat(activities.size()).isEqualTo(1);
        assertThat(activities.get(0).getPackageName()).isEqualTo(packageName);
 
        // Test not match 
        IntentFilter filter1 = new IntentFilter(Intent.ACTION_VIEW);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    } 
 
    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
        ServiceInfo info = mList.getItem(position);
        final ComponentName cn = new ComponentName(info.packageName, info.name);
        if (mEnabledListeners.contains(cn)) {
            // the simple version: disabling 
            mEnabledListeners.remove(cn);
            saveEnabledListeners(); 
        } else { 
            // show a scary dialog 
            new ListenerWarningDialogFragment() 
                .setListenerInfo(cn, info.loadLabel(mPM).toString())
                .show(getFragmentManager(), "dialog");
        } 
    } 
 
    static class ViewHolder { 
        ImageView icon;
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) {
        ActivityInfo info = (ActivityInfo) l.getItemAtPosition(position);
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(this, info.name));
        startActivity(intent);
    } 
 
    private ListAdapter getSampleAdapter() {
        ArrayList<ActivityInfo> items = new ArrayList<ActivityInfo>();
        final String thisClazzName = getClass().getName();
 
        try { 
            PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(),
                    PackageManager.GET_ACTIVITIES);
            ActivityInfo[] aInfos = pInfo.activities;
 
            for (ActivityInfo aInfo : aInfos) {
                if (!thisClazzName.equals(aInfo.name)) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:getPackageName
    public static boolean isApplicationBroughtToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true; 
            } 
        } 
 
        return false; 
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setComponentEnabledSetting
	@Override 
	public void onReceive(Context context, Intent intent) {
		if(RadioPlayerService.radioAvailable(context)) {
			context.getPackageManager().setComponentEnabledSetting(new ComponentName("fm.last.android", "fm.last.android.activity.Player"), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
		} else { 
			context.getPackageManager().setComponentEnabledSetting(new ComponentName("fm.last.android", "fm.last.android.activity.Player"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
		} 
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android ComponentName Questions & Answers:

Other Android ComponentName Examples

17:	    Log.w(LOG, "onUpdate method called");
18:	    // Get all ids
19:	    ComponentName thisWidget = new ComponentName(context,
20:	        MyWidgetProvider.class);
21:	    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
-
17:	    Log.w(LOG, "onUpdate method called");
18:	    // Get all ids
19:	    ComponentName thisWidget = new ComponentName(context,
20:	        MyWidgetProvider.class);
21:	    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

Read More

17:	    Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
18:	    intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
19:	        new ComponentName(this, MyWallpaperService.class));
20:	    startActivity(intent);
21:	  }

Read More

1:	DevicePolicyManager mDPM = (DevicePolicyManager)
2:	        context.getSystemService(Context.DEVICE_POLICY_SERVICE);
3:	ComponentName mPolicyAdmin = new ComponentName(context, PolicyAdmin.class);
4:	...
5:	mDPM.setPasswordQuality(mPolicyAdmin, PASSWORD_QUALITY_VALUES[mPasswordQuality]);
-
1:	DevicePolicyManager mDPM = (DevicePolicyManager)
2:	        context.getSystemService(Context.DEVICE_POLICY_SERVICE);
3:	ComponentName mPolicyAdmin = new ComponentName(context, PolicyAdmin.class);
4:	...
5:	mDPM.setPasswordQuality(mPolicyAdmin, PASSWORD_QUALITY_VALUES[mPasswordQuality]);

Read More

See Code Examples for Android ComponentName Methods: