android.app.Activity.getComponentName()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(453)

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

Activity.getComponentName介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private static void killProcessesAround(Activity activity) throws NameNotFoundException {
  ActivityManager am = (ActivityManager)activity.getSystemService(Context.ACTIVITY_SERVICE);
  String myProcessPrefix = activity.getApplicationInfo().processName;
  String myProcessName = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).processName;
  for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
    if (proc.processName.startsWith(myProcessPrefix) && !proc.processName.equals(myProcessName)) {
      android.os.Process.killProcess(proc.pid);
    }
  }
}

代码示例来源:origin: novoda/android-demos

private void loadIcon(TypedArray a, PackageManager pm, ApplicationInfo appInfo) {
  if (mContext instanceof Activity) {
    try {
      mIcon = pm.getActivityIcon(((Activity) mContext).getComponentName());
    } catch (NameNotFoundException e) {
      Log.e(TAG, "Failed to load app icon.", e);
    }
  }
  if (mIcon == null) {
    mIcon = appInfo.loadIcon(pm);
  }
}

代码示例来源:origin: novoda/android-demos

private void loadLogo(TypedArray a, PackageManager pm, ApplicationInfo appInfo) {
  if (mContext instanceof Activity) {
    try {
      mLogo = pm.getActivityLogo(((Activity) mContext).getComponentName());
    } catch (NameNotFoundException e) {
      Log.e(TAG, "Failed to load app logo.", e);
    }
  }
  if (mLogo == null) {
    mLogo = appInfo.loadLogo(pm);
  }
}

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

/** MCC + MNC are always present in config changes since Oreo. */
@Test
@Config(minSdk = O)
public void getActivityMetaData_configChangesAlwaysIncludesMccAndMnc() throws Exception {
 Activity activity = setupActivity(ShadowPackageManagerTest.ActivityWithConfigChanges.class);
 ActivityInfo activityInfo =
   activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0);
 int configChanges = activityInfo.configChanges;
 assertThat(configChanges & ActivityInfo.CONFIG_MCC).isEqualTo(ActivityInfo.CONFIG_MCC);
 assertThat(configChanges & ActivityInfo.CONFIG_MNC).isEqualTo(ActivityInfo.CONFIG_MNC);
}

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

@Test
public void getActivityMetaData() throws Exception {
 Activity activity = setupActivity(ActivityWithMetadata.class);
 ActivityInfo activityInfo =
   packageManager.getActivityInfo(
     activity.getComponentName(),
     PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
 assertThat(activityInfo.metaData.get("someName")).isEqualTo("someValue");
}

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

@Test
public void getActivityMetaData_configChanges() throws Exception {
 Activity activity = setupActivity(ShadowPackageManagerTest.ActivityWithConfigChanges.class);
 ActivityInfo activityInfo =
   activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0);
 int configChanges = activityInfo.configChanges;
 assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_LAYOUT)
   .isEqualTo(ActivityInfo.CONFIG_SCREEN_LAYOUT);
 assertThat(configChanges & ActivityInfo.CONFIG_ORIENTATION)
   .isEqualTo(ActivityInfo.CONFIG_ORIENTATION);
 // Spot check a few other possible values that shouldn't be in the flags.
 assertThat(configChanges & ActivityInfo.CONFIG_FONT_SCALE).isEqualTo(0);
 assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_SIZE).isEqualTo(0);
}

代码示例来源:origin: 80945540/LCRapidDevelop

ComponentName getBaseActivity() {
  for (WeakReference<Activity> activityWeakReference : mRunningActivities) {
    if (activityWeakReference == null)
      continue;
    Activity tmpActivity = activityWeakReference.get();
    if (tmpActivity == null)
      continue;
    return tmpActivity.getComponentName();
  }
  return null;
}

代码示例来源:origin: 80945540/FreeBook

ComponentName getBaseActivity() {
  for (WeakReference<Activity> activityWeakReference : mRunningActivities) {
    if (activityWeakReference == null)
      continue;
    Activity tmpActivity = activityWeakReference.get();
    if (tmpActivity == null)
      continue;
    return tmpActivity.getComponentName();
  }
  return null;
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onMenuOpened(final Activity activity) {
  if (data.get(activity.getComponentName()).fullScreen) {
    activity.getWindow().clearFlags(FLAG_FULLSCREEN);
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onMenuClosed(final Activity activity) {
  if (data.get(activity.getComponentName()).fullScreen) {
    activity.getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN);
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void setFullScreenMode(final Activity activity, final View view, final boolean fullScreen) {
  data.get(activity.getComponentName()).fullScreen = fullScreen;
  final Window w = activity.getWindow();
  if (fullScreen) {
    w.setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN);
  } else {
    w.clearFlags(FLAG_FULLSCREEN);
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onPause(final Activity activity) {
  if (data.get(activity.getComponentName()).fullScreen
      && data.get(activity.getComponentName()).fullScreenState.get()) {
    startSystemUI(activity);
  }
}

代码示例来源:origin: com.google.android/support-v4

private IntentBuilder(Activity launchingActivity) {
  mActivity = launchingActivity;
  mIntent = new Intent().setAction(Intent.ACTION_SEND);
  mIntent.putExtra(EXTRA_CALLING_PACKAGE, launchingActivity.getPackageName());
  mIntent.putExtra(EXTRA_CALLING_ACTIVITY, launchingActivity.getComponentName());
  mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onMenuOpened(final Activity activity) {
  if (data.get(activity.getComponentName()).fullScreen
      && data.get(activity.getComponentName()).fullScreenState.get()) {
    startSystemUI(activity);
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onDestroy(final Activity activity) {
  if (data.get(activity.getComponentName()).fullScreen
      && data.get(activity.getComponentName()).fullScreenState.get()) {
    startSystemUI(activity);
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

@Override
  public void run() {
    try {
      final boolean result = execImpl(as);
      data.get(activity.getComponentName()).fullScreenState.set(result ? expected : !expected);
    } catch (final Throwable th) {
      LCTX.e("Changing full screen mode failed: " + th.getCause());
      data.get(activity.getComponentName()).fullScreenState.set(!expected);
    }
  }
})).start();

代码示例来源:origin: PrivacyApps/document-viewer

@Override
public void onMenuOpened(final Activity activity) {
  if (!isTabletUi(activity)) {
    if (data.get(activity.getComponentName()).statusBarHidden) {
      activity.getWindow().clearFlags(FLAG_FULLSCREEN);
    }
  }
}

代码示例来源:origin: PrivacyApps/document-viewer

protected void stopSystemUI(final Activity activity) {
  if (!isSystemUIRunning()) {
    data.get(activity.getComponentName()).fullScreenState.set(true);
    return;
  }
  final String su = getSuPath();
  if (su == null) {
    data.get(activity.getComponentName()).fullScreenState.set(false);
    return;
  }
  exec(true, activity, su, "-c", "service call activity 79 s16 " + SYS_UI_PKG);
}

代码示例来源:origin: PrivacyApps/document-viewer

protected void startSystemUI(final Activity activity) {
  if (isSystemUIRunning()) {
    data.get(activity.getComponentName()).fullScreenState.set(false);
    return;
  }
  exec(false, activity, AM_PATH, "startservice", "-n", SYS_UI.flattenToString());
}

代码示例来源:origin: AndBible/and-bible

public static void translateTitle(Activity activity) {
  if (isLocaleOverridden(activity)) {
    // http://stackoverflow.com/questions/22884068/troubles-with-activity-title-language
    try {
      int labelRes = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).labelRes;
      activity.setTitle(labelRes);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
  }
}

相关文章

Activity类方法