而新版的文件选择返回的类似下面:
content://com.android.providers.downloads.documents/document/152
这种无法通过uri.getPath()获取文件路径。
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private boolean hasNavBar(Context context) {
Resources res = context.getResources();
int resourceId = res.getIdentifier("config_showNavigationBar",
"bool","android");
if (resourceId != 0) {
boolean hasNav = res.getBoolean(resourceId);
String sNavBarOverride = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
Class c = Class.forName("android.os.SystemProperties");
Method m = c.getDeclaredMethod("get", String.class);
m.setAccessible(true);
sNavBarOverride = (String) m.invoke(null,"qemu.hw.mainkeys");
} catch (Throwable e) {
sNavBarOverride = null;
}
}
// check override flag (see static block)
if ("1".equals(sNavBarOverride)) {
hasNav = false;
} else if ("0".equals(sNavBarOverride)) {
hasNav = true;
}
return hasNav;
} else { // fallback
return !ViewConfiguration.get(context).hasPermanentMenuKey();
}
}
super.onCreate(savedInstanceState);会报错,这个Activity没有被正常的初始化,Activity的父父类ContextWrapper的构造函数需要Context。只能修改要被调用的Activity了,注释掉上面出错的那行,然后提供一个有参构造函数,传一个Context过去,以后被调用的Activity里面只能使用这个Context了.
String dexPath = Environment.getExternalStorageDirectory()
+ "/Test/AAA.apk";
PackageInfo packageInfo = getPackageManager().getPackageArchiveInfo(
dexPath, PackageManager.GET_ACTIVITIES);
String activityName = packageInfo.activities[0].name;
File dirFile = getDir("whocares", 0);
DexClassLoader loader = new DexClassLoader(dexPath,
dirFile.getAbsolutePath(), null,
ClassLoader.getSystemClassLoader());
try {
Class clz = loader.loadClass(activityName);
Constructor constructor = clz
.getConstructor(new Class[] { Context.class });
Activity activity = (Activity) constructor
.newInstance(new Object[] { this });
Method create = clz.getDeclaredMethod("onCreate",
new Class[] { Bundle.class });
create.setAccessible(true);
create.invoke(activity, new Object[] { null });
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
android.resource://[package]/[res id]
android.resource://[package]/[res type]/[res name]
Uri.parse("android.resource://com.example.test/“ + R.drawable.ic_launcher)
Uri.parse("android.resource://com.example.test/drawable/ic_launcher")
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="com.android.systemui.action_assist_icon"
android:resource="@android:drawable/sym_def_app_icon" />
203.208.46.146 dl.google.com 203.208.46.146 dl-ssl.google.com
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
-keep class android.support.v7.widget.SearchView { *; }
private boolean checkStatusbar(){
Rect rect=new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
//屏幕高度还有别的办法得到,不赘述
return (rect.bottom-rect.top)
==getResources().getDisplayMetrics().heightPixels;
}
private int getStatusBarHeight() {
int result = 0;
int resourceId = getResources()
.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public static void showDetailsOfApp(Context context,
String packageName) {
Intent intent = new Intent();
final int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 9) {
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
// .setData(Uri.fromParts("package", packageName, null));
.setData(Uri.parse("package:"+packageName));
} else {
final String appPkgName = (apiLevel == 8 ? "pkg"
: "com.android.settings.ApplicationPkgName");
intent.setAction(Intent.ACTION_VIEW)
.setClassName("com.android.settings",
"com.android.settings.InstalledAppDetails")
.putExtra(appPkgName, packageName);
}
context.startActivity(intent);
}
listView.post(new Runnable() {
@Override
public void run() {
listView.setSelection(position);
}
});
# # An unexpected error has been detected by Java Runtime Environment: # # SIGBUS (0x7) at pc=0x00007f99ab324031, pid=14598, tid=140296281274112 # # Java VM: Java HotSpot(TM) 64-Bit Server VM (10.0-b22 mixed mode linux-amd64) # Problematic frame: # C [libzip.so+0xb031] # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. #
暂时解决方法:取消自动编译