分类:android
Retrofit2结果拦截器和判断异常类型
结果拦截器
Interceptor responseInterceptor = new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); if (response.body() != null) { String json = response.body().string().replace("\"data\":null", "\"data\":{}"); ResponseBody body = ResponseBody.create(response.body().contentType(), json); return response.newBuilder().body(body).build(); } return response; } };
判断异常类型
@Override public void accept(Throwable throwable) throws Exception { if (throwable instanceof HttpException) { String json = ((HttpException) throwable).response().errorBody().string(); } }
Android AlertDialog背景透明
1.定义AlertDialog透明样式
<style name="TransparentDialog" parent="Theme.AppCompat.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> </style>
2.创建AlertDialog
View view = LayoutInflater.from(context).inflate(R.layout.dialog_sure, null, false); AlertDialog sureDialog = new AlertDialog.Builder(context, R.style.TransparentDialog).setView(view).create();
参考链接:
安卓图像数据格式
Android NDK开发,使用ndk-build编译
节选自:Android NDK开发,使用ndk-build编译
手动编译.so文件
从步骤八开始的第二种方式,不指定AndroidStudio编译工具(Cmake或者ndk-build),直接手动生成.so库
a, cmd 或者Android studio的Terminal 中进入jni的上一级目录
b, 输入ndk-build命令,在jni同级的目录中生成了一个libs文件夹,里面生成了各个cup架构对应的.so文件,
『逆向资源区』
让老手机用上 Android 8.0:我的 Nexus 4 重生记
Factory Images for Nexus and Pixel Devices
安卓5.0 Xposed的手动卸载
重新挂载system分区
adb root adb remount
解压缩
gzip -d FileName
bin目录文件权限755
lib目录文件权限644
更改前文件
/system/bin/app_process32 /system/bin/dex2oat /system/bin/oatdump /system/bin/patchoat /system/lib/libart-compiler.so /system/lib/libart-disassembler.so /system/lib/libart.so /system/lib/libsigchain.so
更改后文件
/system/bin/app_process32.original /system/bin/dex2oat.orig.gz /system/bin/oatdump.orig.gz /system/bin/patchoat.orig.gz /system/lib/libart-compiler.so.orig.gz /system/lib/libart-disassembler.so.orig.gz /system/lib/libart.so.orig.gz /system/lib/libsigchain.so.orig.gz
使用VLC播放器问题记录
笔者在使用VLC播放器播放摄像头的RTSP视频时,遇到了一些问题,已经解决了,在这里记录一下解决的方案,虽然不是最好的方案,不过确实可以实现效果。
问题一:小窗播放视频时显示不全
视频的分辨率是1920*1080的,笔者的播放器界面大小是320*180,播放的时候只显示了整个视频的一部分,而不是把整个视频缩放到播放器界面大小。
解决方案,把播放器界面的宽高设置为match_parent,并且播放器界面的所有父容器都不能设置固定宽高,可以是match_parent或者wrap_content。然后使用scaleX和scaleY把播放器界面缩放到指定大小。最后通过设置translationX和translationY移动播放器位置到指定位置。
问题二:同屏存在多个VLC播放器时,全屏其中一个播放器,另外一个也显示
全屏方案使用的是在Activity中留一个全屏的ViewGroup来放置播放器。可以参考Android视频播放器实现小窗口和全屏状态切换。笔者放置的是FrameLayout。
解决方案,全屏其中一个播放器时,把另外一个播放器通过设置scaleX和scaleY为0来隐藏播放器。