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;
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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());   
		} 
	} 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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) //
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

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: