本文整理匯總了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();
}