android.content.Intent.removeCategory()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中android.content.Intent.removeCategory()方法的一些代码示例,展示了Intent.removeCategory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.removeCategory()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:removeCategory

Intent.removeCategory介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Implementation
protected Intent getLaunchIntentForPackage(String packageName) {
 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
 intentToResolve.addCategory(Intent.CATEGORY_INFO);
 intentToResolve.setPackage(packageName);
 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
 if (ris == null || ris.isEmpty()) {
  intentToResolve.removeCategory(Intent.CATEGORY_INFO);
  intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
  intentToResolve.setPackage(packageName);
  ris = queryIntentActivities(intentToResolve, 0);
 }
 if (ris == null || ris.isEmpty()) {
  return null;
 }
 Intent intent = new Intent(intentToResolve);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 intent.setClassName(packageName, ris.get(0).activityInfo.name);
 return intent;
}

代码示例来源:origin: android-hacker/VirtualXposed

public Intent getLaunchIntent(String packageName, int userId) {
  VPackageManager pm = VPackageManager.get();
  Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
  intentToResolve.addCategory(Intent.CATEGORY_INFO);
  intentToResolve.setPackage(packageName);
  List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  // Otherwise, try to find a main launcher activity.
  if (ris == null || ris.size() <= 0) {
    // reuse the intent instance
    intentToResolve.removeCategory(Intent.CATEGORY_INFO);
    intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
    intentToResolve.setPackage(packageName);
    ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  }
  if (ris == null || ris.size() <= 0) {
    return null;
  }
  Intent intent = new Intent(intentToResolve);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(ris.get(0).activityInfo.packageName,
      ris.get(0).activityInfo.name);
  return intent;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldSupportCategories() throws Exception {
 Intent intent = new Intent();
 Intent self = intent.addCategory("category.name.1");
 intent.addCategory("category.name.2");
 assertTrue(intent.hasCategory("category.name.1"));
 assertTrue(intent.hasCategory("category.name.2"));
 Set<String> categories = intent.getCategories();
 assertTrue(categories.contains("category.name.1"));
 assertTrue(categories.contains("category.name.2"));
 intent.removeCategory("category.name.1");
 assertFalse(intent.hasCategory("category.name.1"));
 assertTrue(intent.hasCategory("category.name.2"));
 intent.removeCategory("category.name.2");
 assertFalse(intent.hasCategory("category.name.2"));
 assertThat(intent.getCategories()).isNull();
 assertSame(self, intent);
}

代码示例来源:origin: corcoran/Hangar

public static Map<String, IconPackInfo> getSupportedPackages(Context context) {
  Intent i = new Intent();
  Map<String, IconPackInfo> packages = new HashMap<String, IconPackInfo>();
  PackageManager packageManager = context.getPackageManager();
  for (String action : sSupportedActions) {
    i.setAction(action);
    for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
      IconPackInfo info = new IconPackInfo(r, packageManager);
      packages.put(r.activityInfo.packageName, info);
    }
  }
  i = new Intent(Intent.ACTION_MAIN);
  for (String category : sSupportedCategories) {
    i.addCategory(category);
    for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
      IconPackInfo info = new IconPackInfo(r, packageManager);
      packages.put(r.activityInfo.packageName, info);
    }
    i.removeCategory(category);
  }
  return packages;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

public static Map<String, IconPackInfo> getSupportedPackages(Context context) {
  Intent i = new Intent();
  Map<String, IconPackInfo> packages = new HashMap<String, IconPackInfo>();
  PackageManager packageManager = context.getPackageManager();
  for (String action : sSupportedActions) {
    i.setAction(action);
    for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
      IconPackInfo info = new IconPackInfo(r, packageManager);
      packages.put(r.activityInfo.packageName, info);
    }
  }
  i = new Intent(Intent.ACTION_MAIN);
  for (String category : sSupportedCategories) {
    i.addCategory(category);
    for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
      IconPackInfo info = new IconPackInfo(r, packageManager);
      packages.put(r.activityInfo.packageName, info);
    }
    i.removeCategory(category);
  }
  return packages;
}

代码示例来源:origin: org.robolectric/framework

@Implementation
public Intent getLaunchIntentForPackage(String packageName) {
 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
 intentToResolve.addCategory(Intent.CATEGORY_INFO);
 intentToResolve.setPackage(packageName);
 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
 if (ris == null || ris.isEmpty()) {
  intentToResolve.removeCategory(Intent.CATEGORY_INFO);
  intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
  intentToResolve.setPackage(packageName);
  ris = queryIntentActivities(intentToResolve, 0);
 }
 if (ris == null || ris.isEmpty()) {
  return null;
 }
 Intent intent = new Intent(intentToResolve);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
 return intent;
}

代码示例来源:origin: org.robolectric/shadows-framework

@Implementation
protected Intent getLaunchIntentForPackage(String packageName) {
 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
 intentToResolve.addCategory(Intent.CATEGORY_INFO);
 intentToResolve.setPackage(packageName);
 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
 if (ris == null || ris.isEmpty()) {
  intentToResolve.removeCategory(Intent.CATEGORY_INFO);
  intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
  intentToResolve.setPackage(packageName);
  ris = queryIntentActivities(intentToResolve, 0);
 }
 if (ris == null || ris.isEmpty()) {
  return null;
 }
 Intent intent = new Intent(intentToResolve);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 intent.setClassName(packageName, ris.get(0).activityInfo.name);
 return intent;
}

代码示例来源:origin: baidu/GPT

/**
 * 把component info添加到intent
 *
 * @param intent 目标intent
 */
public void addSelf2Intent(Intent intent) {
  // 如果原来就包含了gpt的component信息,先去掉。因为发现支付插件会把intent透传给下一个activity,
  // 导致remap失效,还是上一次的component,出现循环启动同一个activity
  Set<String> cates = intent.getCategories();
  ArrayList<String> toRemove = new ArrayList<String>();
  if (cates != null && cates.size() > 0) {
    for (String cate : cates) {
      if (cate != null && cate.startsWith(ProxyEnvironment.TARGET_BEGIN_FLAG)) {
        toRemove.add(cate);
      }
    }
  }
  for (String cate : toRemove) {
    intent.removeCategory(cate);
  }
  intent.addCategory(this.toString());
}

代码示例来源:origin: bzsome/VirtualApp-x326

public Intent getLaunchIntent(String packageName, int userId) {
  VPackageManager pm = VPackageManager.get();
  Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
  intentToResolve.addCategory(Intent.CATEGORY_INFO);
  intentToResolve.setPackage(packageName);
  List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  // Otherwise, try to find a main launcher activity.
  if (ris == null || ris.size() <= 0) {
    // reuse the intent instance
    intentToResolve.removeCategory(Intent.CATEGORY_INFO);
    intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
    intentToResolve.setPackage(packageName);
    ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  }
  if (ris == null || ris.size() <= 0) {
    return null;
  }
  Intent intent = new Intent(intentToResolve);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(ris.get(0).activityInfo.packageName,
      ris.get(0).activityInfo.name);
  return intent;
}

代码示例来源:origin: darkskygit/VirtualApp

public Intent getLaunchIntent(String packageName, int userId) {
  VPackageManager pm = VPackageManager.get();
  Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
  intentToResolve.addCategory(Intent.CATEGORY_INFO);
  intentToResolve.setPackage(packageName);
  List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  // Otherwise, try to find a main launcher activity.
  if (ris == null || ris.size() <= 0) {
    // reuse the intent instance
    intentToResolve.removeCategory(Intent.CATEGORY_INFO);
    intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
    intentToResolve.setPackage(packageName);
    ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
  }
  if (ris == null || ris.size() <= 0) {
    return null;
  }
  Intent intent = new Intent(intentToResolve);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(ris.get(0).activityInfo.packageName,
      ris.get(0).activityInfo.name);
  return intent;
}

代码示例来源:origin: alexstyl/Theming-Android

private void restartActivity() {
  Intent intent = getIntent();
  intent.removeCategory(Intent.CATEGORY_LAUNCHER);
  startActivity(intent);
  finish();
}

代码示例来源:origin: baidu/GPT

shortCutIntent.removeCategory(info.toString());
shortCutIntent.putExtra(ShortcutActivityProxy.EXTRA_KEY_TARGET_INFO, info.toString());
    shortCutIntent.removeCategory(cate);

代码示例来源:origin: baidu/GPT

intent.removeCategory(info.toString());

相关文章

Intent类方法