好记性不如烂笔头,仅以记之
一:摩托罗拉Android 7.0系统剪切图片后崩溃。日志如下:
FATAL EXCEPTION: main
Process: com.google.android.apps.photos, PID: 8332
java.lang.RuntimeException: Unable to resume activity {com.google.android.apps.photos/com.google.android.apps.photos.photoeditor.intents.EditActivity}: java.lang.UnsupportedOperationException: No 'output' extra specified and can not save to specified inputUri: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F2236/ACTUAL/1186776521
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3017) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3048)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1365)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.UnsupportedOperationException: No 'output' extra specified and can not save to specified inputUri: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F2236/ACTUAL/1186776521
at com.google.android.apps.photos.photoeditor.intents.EditActivity.a(PG:13312)
at gpy.a(PG:88)
at mgf.a(PG:5197)
at mgg.a(PG:169)
at mgf.W_(PG:4114)
at ofw.a(PG:213)
at oft.a(PG:98)
at oft.l(PG:209)
at ogs.onResume(PG:68)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
at android.app.Activity.performResume(Activity.java:6076)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3006)
解决:这个是没有指定图片保存路径,导致使用默认路径时无法写入,目前只发现这一款手机存在这个问题,这个解决也简单,就是手动指定输出路径即可。
Intent intent = new Intent();
intent.setAction("com.android.camera.action.CROP");
intent.setDataAndType(mUri, "image/*");// mUri是已经选择的图片Uri
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);// 裁剪框比例
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 150);// 输出图片大小
intent.putExtra("outputY", 150);
intent.putExtra("return-data", true);
// 注意sdcard读写权限,也可以使用其他目录
cutFile = new File(Environment.getExternalStorageDirectory() + File.separator + "test11.jpg");
if (cutFile.exists() == false) {
try {
cutFile.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 解决方法
intent.putExtra("output", Uri.fromFile(cutFile)); // 指定目标文件
intent.putExtra("outputFormat", "JPEG"); //输出文件格式
MainActivity.this.startActivityForResult(intent, 200);
cutFile是全局变量,在onActivityResult里面直接使用即可。
二:同一个APP,在genymotion模拟器上面运行都没问题,但是真机上一直崩溃。
可能是so库造成的,我的主工程中jni支持armeabi、armeabi-v7a和x86,但是我的引用的库里面只支持armeabi和x86,这样在模拟器上面是好的,但是一到真机上就崩溃了。这个必须保持一致,而且每个架构都要包含全部的so库,不能有的有,有的没有。
参考Android jniLibs下目录详解(.so文件)
三:加载https的H5页面,http的图片无法正确加载。
Android webview 从Lollipop(5.0)开始webview默认不允许混合模式,https当中不能加载http资源,需要设置开启。
解决方案:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
四:沉浸式状态栏显示黑条
红米5,三星s8等全面屏手机,状态栏显示黑条。
在AndroidManifest.xml中做如下配置:
<meta-data android:name="android.max_aspect"
android:value="2.1"/>
参考:Android全面屏适配