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

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

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

Activity.getBaseContext介绍

暂无

代码示例

代码示例来源:origin: RobotiumTech/robotium

/**
 * Checks that the specified DecorView and the Activity DecorView are not equal.
 * 
 * @param activity the activity which DecorView is to be compared
 * @param decorView the DecorView to compare
 * @return true if not equal
 */

private boolean isDialog(Activity activity, View decorView){
  if(decorView == null || !decorView.isShown() || activity == null){
    return false;
  }
  Context viewContext = null;
  if(decorView != null){
    viewContext = decorView.getContext();
  }
  
  if (viewContext instanceof ContextThemeWrapper) {
    ContextThemeWrapper ctw = (ContextThemeWrapper) viewContext;
    viewContext = ctw.getBaseContext();
  }
  Context activityContext = activity;
  Context activityBaseContext = activity.getBaseContext();
  return (activityContext.equals(viewContext) || activityBaseContext.equals(viewContext)) && (decorView != activity.getWindow().getDecorView());
}

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

/**
 * This method can be called to set the version code of the APK expansion
 * file(s) used by the application
 * 
 * @param mainVersion
 *            - version code of the main expansion file
 * @param patchVersion
 *            - version code of the patch expansion file
 * 
 * @return true if the APK expansion file could be opened, false otherwise
 */
public boolean setAPKExpansion(int mainVersion, int patchVersion) {
  try {
    Context context;
    if (Gdx.app instanceof Activity) {
      context = ((Activity) Gdx.app).getBaseContext();
    } else if (Gdx.app instanceof Fragment) {
      context = ((Fragment) Gdx.app).getActivity().getBaseContext();
    } else {
      throw new GdxRuntimeException("APK expansion not supported for application type");
    }
    expansionFile = APKExpansionSupport.getAPKExpansionZipFile(
        context,
        mainVersion, patchVersion);
  } catch (IOException ex) {
    throw new GdxRuntimeException("APK expansion main version " + mainVersion + " or patch version " + patchVersion + " couldn't be opened!");
  }
  return expansionFile != null;
}

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

/**
 * This method can be called to set the version code of the APK expansion
 * file(s) used by the application
 * 
 * @param mainVersion
 *            - version code of the main expansion file
 * @param patchVersion
 *            - version code of the patch expansion file
 * 
 * @return true if the APK expansion file could be opened, false otherwise
 */
public boolean setAPKExpansion(int mainVersion, int patchVersion) {
  try {
    Context context;
    if (Gdx.app instanceof Activity) {
      context = ((Activity) Gdx.app).getBaseContext();
    } else if (Gdx.app instanceof Fragment) {
      context = ((Fragment) Gdx.app).getActivity().getBaseContext();
    } else {
      throw new GdxRuntimeException("APK expansion not supported for application type");
    }
    expansionFile = APKExpansionSupport.getAPKExpansionZipFile(
        context,
        mainVersion, patchVersion);
  } catch (IOException ex) {
    throw new GdxRuntimeException("APK expansion main version " + mainVersion + " or patch version " + patchVersion + " couldn't be opened!");
  }
  return expansionFile != null;
}

代码示例来源:origin: rmtheis/android-ocr

static String translate(Activity activity, String sourceLanguageCode, String targetLanguageCode, String sourceText) {   
  
  // Check preferences to determine which translation API to use--Google, or Bing.
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  String api = prefs.getString(PreferencesActivity.KEY_TRANSLATOR, CaptureActivity.DEFAULT_TRANSLATOR);
  
  // Delegate the translation based on the user's preference.
  if (api.equals(PreferencesActivity.TRANSLATOR_BING)) {
   
   // Get the correct code for the source language for this translation service.
   sourceLanguageCode = TranslatorBing.toLanguage(
     LanguageCodeHelper.getTranslationLanguageName(activity.getBaseContext(), sourceLanguageCode));
   
   return TranslatorBing.translate(sourceLanguageCode, targetLanguageCode, sourceText);
  } else if (api.equals(PreferencesActivity.TRANSLATOR_GOOGLE)) {
   
   // Get the correct code for the source language for this translation service.
   sourceLanguageCode = TranslatorGoogle.toLanguage(
     LanguageCodeHelper.getTranslationLanguageName(activity.getBaseContext(), sourceLanguageCode));      
   
   return TranslatorGoogle.translate(sourceLanguageCode, targetLanguageCode, sourceText);
  }
  return BAD_TRANSLATION_MSG;
 }
}

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

public static void fixActivity(Activity activity) {
  Context baseContext = activity.getBaseContext();
  try {
    TypedArray typedArray = activity.obtainStyledAttributes((R_Hide.styleable.Window.get()));

代码示例来源:origin: limpoxe/Android-Plugin-Framework

/**
 * Used by host for skin
 * 宿主程序使用插件主题
 */
public static void applyPluginTheme(Activity activity, String pluginId, int themeResId) {
  LayoutInflater layoutInflater = LayoutInflater.from(activity);
  if (layoutInflater.getFactory() == null) {
    if (!(activity.getBaseContext() instanceof PluginContextTheme)) {
      PluginDescriptor pluginDescriptor = PluginManagerHelper.getPluginDescriptorByPluginId(pluginId);
      if (pluginDescriptor != null) {
        //插件可能尚未初始化,确保使用前已经初始化
        LoadedPlugin pluing = PluginLauncher.instance().startPlugin(pluginDescriptor);
        //注入插件上下文和主题
        Context defaultContext = pluing.pluginContext;
        Context pluginContext = PluginCreator.createNewPluginComponentContext(defaultContext,
            ((PluginBaseContextWrapper)activity.getBaseContext()).getBaseContext(), 0);
        PluginInjector.resetActivityContext(pluginContext, activity, themeResId);
      }
    }
  } else {
    LogUtil.e("启用了控件级插件的页面 不能使用换肤功能呢");
  }
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

pluginContext = PluginCreator.createNewPluginComponentContext(plugin.pluginContext, activity.getBaseContext(), 0);
    pluginContext = PluginCreator.createNewPluginComponentContext(plugin.pluginContext, activity.getBaseContext(), 0);
Context mainContext = new PluginBaseContextWrapper(activity.getBaseContext());
hackActivity.setBase(null);
hackActivity.attachBaseContext(mainContext);

代码示例来源:origin: nerzhul/ownCloud-SMS-App

public AndroidAccountAdapter(Activity activity, int resource,
    ArrayList<Account> objects, int itemLayout,
    int accountFieldId, Class<?> newActivityClass) {
  super(activity.getBaseContext(), resource, objects);
  _accounts = objects;
  AndroidAccountAdapter._itemLayout = itemLayout;
  AndroidAccountAdapter._accountFieldId = accountFieldId;
  _activity = activity;
  _newActivityClass = newActivityClass;
}

代码示例来源:origin: nerzhul/ncsms-android

public AndroidAccountAdapter(Activity activity, int resource,
    ArrayList<Account> objects, int itemLayout,
    int accountFieldId, Class<?> newActivityClass) {
  super(activity.getBaseContext(), resource, objects);
  _accounts = objects;
  AndroidAccountAdapter._itemLayout = itemLayout;
  AndroidAccountAdapter._accountFieldId = accountFieldId;
  _activity = activity;
  _newActivityClass = newActivityClass;
}

代码示例来源:origin: Fewlaps/flone-android

public void run() {
    Toast.makeText(myNewActivity.getBaseContext(), toast,
        length).show();
  }
});

代码示例来源:origin: Fewlaps/flone-android

public void run() {
    Toast.makeText(myNewActivity.getBaseContext(), toast,
        Toast.LENGTH_SHORT).show();
  }
});

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

public static void hideKeyboard(Activity act, EditText et){
  Context c = act.getBaseContext();
  View v = et.findFocus();
  if(v == null)
    return;
  InputMethodManager inputManager = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
  inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

代码示例来源:origin: wiglenet/wigle-wifi-wardriving

public static void setLocale(final Activity activity) {
  final Context context = activity.getBaseContext();
  final Configuration config = context.getResources().getConfiguration();
  setLocale(context, config);
}

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

@Override
public void onAttach(Activity activity) {
  super.onAttach(activity);
  this.mContext = activity.getBaseContext();
  Log.i(Constants.TAG,"WearInfoFragment onAttach context: " + mContext);
}

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

@Override
public void onAttach(Activity activity) {
  super.onAttach(activity);
  this.mContext = activity.getBaseContext();
  Log.i(Constants.TAG,"WearMenuFragment onAttach context: " + mContext);
}

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

@Override
public void onAttach(Activity activity) {
  super.onAttach(activity);
  this.mContext = activity.getBaseContext();
  sendNewRequest = false;
  requestSent = false;
}

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

@Override
public void onAttach(Activity activity) {
  super.onAttach(activity);
  this.mContext = activity.getBaseContext();
  Log.i(Constants.TAG,"RepliesFragment onAttach context: " + mContext);
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

Context base = activity.getBaseContext();
while(base instanceof ContextWrapper) {
  base = ((ContextWrapper)base).getBaseContext();

代码示例来源:origin: iqiyi/Neptune

public ActivityWrapper(Activity origin, String pkgName) {
  mPkgName = pkgName;
  mPluginContext = new PluginContextWrapper(origin.getBaseContext(), pkgName);
  mOriginActivity = origin;
  if (mOriginActivity instanceof FragmentActivity) {
    mOriginFragmentActivity = (FragmentActivity) mOriginActivity;
  }
  // 将ActivityWrapper的mBase设置为插件的Context
  attachBaseContext(mPluginContext);
}

代码示例来源:origin: VladThodo/behe-keyboard

@Override
public void onCreate(Bundle s){
  super.onCreate(s);
  addPreferencesFromResource(R.xml.ime_preferences);
  listTheme = (ListPreference) findPreference("theme");
  listStart = (ListPreference) findPreference("start");
  listLayout = (ListPreference) findPreference("layout");
  listTheme.setSummary(listTheme.getEntry());
  listStart.setSummary(listStart.getEntry());
  listLayout.setSummary(listLayout.getEntry());
  PreferenceManager.getDefaultSharedPreferences(getActivity().getBaseContext()).registerOnSharedPreferenceChangeListener(this);
}

相关文章

Activity类方法