本文整理汇总了Java中android.widget.RemoteViews.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteViews.getPackage方法的具体用法?Java RemoteViews.getPackage怎么用?Java RemoteViews.getPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.RemoteViews
的用法示例。
在下文中一共展示了RemoteViews.getPackage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hackRemoteViews
import android.widget.RemoteViews; //导入方法依赖的package包/类
private void hackRemoteViews(RemoteViews remoteViews) throws IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
if (remoteViews != null && !TextUtils.equals(remoteViews.getPackage(), mHostContext.getPackageName())) {
if (sSystemLayoutResIds.containsKey(remoteViews.getLayoutId())) {
Object mActionsObj = FieldUtils.readField(remoteViews, "mActions");
if (mActionsObj instanceof Collection) {
Collection mActions = (Collection) mActionsObj;
String aPackage = remoteViews.getPackage();
Application pluginContent = PluginProcessManager.getPluginContext(aPackage);
if (pluginContent != null) {
Iterator iterable = mActions.iterator();
Class TextViewDrawableActionClass = null;
try {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
TextViewDrawableActionClass = Class.forName(RemoteViews.class.getName() + "$TextViewDrawableAction");
}
} catch (ClassNotFoundException e) {
}
Class ReflectionActionClass = Class.forName(RemoteViews.class.getName() + "$ReflectionAction");
while (iterable.hasNext()) {
Object action = iterable.next();
if (ReflectionActionClass.isInstance(action)) {//???这里这样是对的么?
String methodName = (String) FieldUtils.readField(action, "methodName");
//String methodName;,int type; Object value;
if ("setImageResource".equals(methodName)) { //setInt(viewId, "setImageResource", srcId);
Object BITMAP = FieldUtils.readStaticField(action.getClass(), "BITMAP");
int resId = (Integer) FieldUtils.readField(action, "value");
Bitmap bitmap = BitmapFactory.decodeResource(pluginContent.getResources(), resId);
FieldUtils.writeField(action, "type", BITMAP);
FieldUtils.writeField(action, "value", bitmap);
FieldUtils.writeField(action, "methodName", "setImageBitmap");
} else if ("setImageURI".equals(methodName)) {//setUri(viewId, "setImageURI", uri);
iterable.remove(); //TODO RemoteViews.setImageURI 其实应该适配的。
} else if ("setLabelFor".equals(methodName)) {
iterable.remove(); //TODO RemoteViews.setLabelFor 其实应该适配的。
}
} else if (TextViewDrawableActionClass != null && TextViewDrawableActionClass.isInstance(action)) {
iterable.remove();
// if ("setTextViewCompoundDrawables".equals(methodName)) {
// iterable.remove(); //TODO RemoteViews.setTextViewCompoundDrawables 其实应该适配的。
// } else if ("setTextViewCompoundDrawablesRelative".equals(methodName)) {
// iterable.remove(); //TODO RemoteViews.setTextViewCompoundDrawablesRelative 其实应该适配的。
// }
}
}
}
}
}
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
FieldUtils.writeField(remoteViews, "mApplication", mHostContext.getApplicationInfo());
} else {
FieldUtils.writeField(remoteViews, "mPackage", mHostContext.getPackageName());
}
}
}