本文整理汇总了Java中android.content.Context.createPackageContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.createPackageContext方法的具体用法?Java Context.createPackageContext怎么用?Java Context.createPackageContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.createPackageContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPackageContext
import android.content.Context; //导入方法依赖的package包/类
public static Context getPackageContext(Context context, String packageName) {
Context pkgContext = null;
if (context.getPackageName().equals(packageName)) {
pkgContext = context;
} else {
// 创建第三方应用的上下文环境
try {
pkgContext = context.createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY
| Context.CONTEXT_INCLUDE_CODE);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return pkgContext;
}
示例2: getThemeColor
import android.content.Context; //导入方法依赖的package包/类
/** [这个好像好用些] */
public static int getThemeColor(Context context, int themeRes, int attribute, int defaultColor) {
int themeColor = 0;
String packageName = context.getPackageName();
try {
Context packageContext = context.createPackageContext(packageName, 0);
packageContext.setTheme(themeRes);
Resources.Theme theme = packageContext.getTheme();
TypedArray ta = theme.obtainStyledAttributes(new int[] {attribute});
themeColor = ta.getColor(0, defaultColor);
ta.recycle();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return themeColor;
}
示例3: getString
import android.content.Context; //导入方法依赖的package包/类
private static String getString(int resId, Context context) throws PackageManager.NameNotFoundException {
try {
Context appContext = context.createPackageContext("ml.qingsu.fuckview", Context.CONTEXT_IGNORE_SECURITY);
return appContext.getResources().getString(resId);
} catch (NullPointerException e) {
return null;
}
}
示例4: createPackageContext
import android.content.Context; //导入方法依赖的package包/类
private Context createPackageContext(String packageName) {
try {
Context hostContext = VirtualCore.get().getContext();
return hostContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
VirtualRuntime.crash(new RemoteException());
}
throw new RuntimeException();
}
示例5: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context) {
if (init) return;
init = true;
if (notification_panel_width == 0) {
Context systemUi = null;
try {
systemUi = context.createPackageContext(NotificationCompat.SYSTEM_UI_PKG, Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
}
if (Build.VERSION.SDK_INT <= 19) {
notification_side_padding = 0;
} else {
notification_side_padding = getDimem(context, systemUi, "notification_side_padding",
R.dimen.notification_side_padding);
}
notification_panel_width = getDimem(context, systemUi, "notification_panel_width",
R.dimen.notification_panel_width);
if (notification_panel_width <= 0) {
notification_panel_width = context.getResources().getDisplayMetrics().widthPixels;
}
notification_min_height = getDimem(context, systemUi, "notification_min_height",
R.dimen.notification_min_height);
// getDimem(context, systemUi, "notification_row_min_height", 0);
// if (notification_min_height == 0) {
// notification_min_height =
// }
notification_max_height = getDimem(context, systemUi, "notification_max_height",
R.dimen.notification_max_height);
notification_mid_height = getDimem(context, systemUi, "notification_mid_height",
R.dimen.notification_mid_height);
notification_padding = getDimem(context, systemUi, "notification_padding", R.dimen.notification_padding);
// notification_collapse_second_card_padding
}
}
示例6: createPackageContext
import android.content.Context; //导入方法依赖的package包/类
private Context createPackageContext(String packageName) {
try {
Context hostContext = VirtualCore.get().getContext();
return hostContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
VirtualRuntime.crash(new RemoteException());
}
throw new RuntimeException();
}
示例7: getGbContext
import android.content.Context; //导入方法依赖的package包/类
public static synchronized Context getGbContext(Context context) throws Throwable {
if (mGbContext == null) {
mGbContext = context.createPackageContext(GravityBox.PACKAGE_NAME,
Context.CONTEXT_IGNORE_SECURITY);
}
return mGbContext;
}
示例8: getPluginDefaultSharedPreferences
import android.content.Context; //导入方法依赖的package包/类
/**
* Get plugin default shared preferences
*
* @param context current locatorContext
* @param pkg package name
* @return default shared preferences
*/
static SharedPreferences getPluginDefaultSharedPreferences(@NonNull final Context context, final String pkg)
{
try
{
final Context pluginContext = context.createPackageContext(pkg, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
return PreferenceManager.getDefaultSharedPreferences(pluginContext);
}
catch (@NonNull final NameNotFoundException ignored)
{
//
}
return null;
}
示例9: createPackageContext
import android.content.Context; //导入方法依赖的package包/类
private Context createPackageContext(String packageName) {
try {
Context hostContext = VirtualCore.get().getContext();
return hostContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
}
示例10: getAppContext
import android.content.Context; //导入方法依赖的package包/类
private Context getAppContext(Context base, String packageName) {
try {
return base.createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例11: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context) {
if (notification_panel_width == 0) {
Context systemUi = null;
try {
systemUi = context.createPackageContext("com.android.systemui", Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
}
if (Build.VERSION.SDK_INT <= 19) {
notification_side_padding = 0;
} else {
notification_side_padding = getDimem(context, systemUi, "notification_side_padding",
R.dimen.notification_side_padding);
}
notification_panel_width = getDimem(context, systemUi, "notification_panel_width",
R.dimen.notification_panel_width);
if (notification_panel_width <= 0) {
notification_panel_width = context.getResources().getDisplayMetrics().widthPixels;
}
notification_min_height = getDimem(context, systemUi, "notification_min_height",
R.dimen.notification_min_height);
// getDimem(context, systemUi, "notification_row_min_height", 0);
// if (notification_min_height == 0) {
// notification_min_height =
// }
notification_max_height = getDimem(context, systemUi, "notification_max_height",
R.dimen.notification_max_height);
notification_mid_height = getDimem(context, systemUi, "notification_mid_height",
R.dimen.notification_mid_height);
notification_padding = getDimem(context, systemUi, "notification_padding", R.dimen.notification_padding);
// notification_collapse_second_card_padding
}
}
示例12: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context) {
if (init) return;
init = true;
if (notification_panel_width == 0) {
Context systemUi = null;
try {
systemUi = context.createPackageContext(NotificationCompat.SYSTEM_UI_PKG, Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException e) {
}
if (Build.VERSION.SDK_INT <= 19) {
notification_side_padding = 0;
} else {
notification_side_padding = getDimem(context, systemUi, "notification_side_padding",
R.dimen.notification_side_padding);
}
notification_panel_width = getDimem(context, systemUi, "notification_panel_width",
R.dimen.notification_panel_width);
if (notification_panel_width <= 0) {
notification_panel_width = context.getResources().getDisplayMetrics().widthPixels;
}
notification_min_height = getDimem(context, systemUi, "notification_min_height",
R.dimen.notification_min_height);
// getDimem(context, systemUi, "notification_row_min_height", 0);
// if (notification_min_height == 0) {
// notification_min_height =
// }
notification_max_height = getDimem(context, systemUi, "notification_max_height",
R.dimen.notification_max_height);
notification_mid_height = getDimem(context, systemUi, "notification_mid_height",
R.dimen.notification_mid_height);
notification_padding = getDimem(context, systemUi, "notification_padding", R.dimen.notification_padding);
// notification_collapse_second_card_padding
}
}
示例13: getClassLoader
import android.content.Context; //导入方法依赖的package包/类
/**
* Get package class loader
*
* @param context current locatorContext
* @param pkgName package name
* @return package class loader
* @throws NameNotFoundException name not found exception
*/
static ClassLoader getClassLoader(@NonNull final Context context, final String pkgName) throws NameNotFoundException
{
final Context providerContext = context.createPackageContext(pkgName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
return providerContext.getClassLoader();
}
示例14: getResources
import android.content.Context; //导入方法依赖的package包/类
/**
* Get package resources
*
* @param context current locatorContext
* @param pkgName package name
* @return package resources
* @throws NameNotFoundException name not found exception
*/
static Resources getResources(@NonNull final Context context, final String pkgName) throws NameNotFoundException
{
final Context providerContext = context.createPackageContext(pkgName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
return providerContext.getResources();
}