import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Socket通讯工具类
*/
public class SocketUtil {
// 线程池
private static final ExecutorService ThreadPool = Executors.newCachedThreadPool();
/**
* 发送Socket消息
*
* @param targetIP 目标IP
* @param targetPort 目标端口
* @param msg 消息
* @param callback 回调
*/
public static void sendSocketMsg(final String targetIP, final int targetPort, final byte[] msg, final SocketUtilCallback callback) {
ThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
// 建立Socket连接
Socket socket = new Socket(targetIP, targetPort);
socket.setSoTimeout(1000 * 10);
// 写消息
OutputStream out = socket.getOutputStream();
out.write(msg);
out.flush();
// 读取消息返回
byte[] readBuffer = new byte[1024];
InputStream in = socket.getInputStream();
int size = in.read(readBuffer);
byte[] readBytes = null;
if (size != -1) {
readBytes = new byte[size];
System.arraycopy(readBuffer, 0, readBytes, 0, size);
}
// 关闭流和Socket连接
in.close();
out.close();
socket.close();
// 执行发送成功回调
if (callback != null && readBytes != null) {
callback.onSuccess(readBytes);
}
} catch (IOException e) {
// 执行发送失败回调
if (callback != null) {
callback.onError(e);
}
}
}
});
}
/**
* 回调
*/
public interface SocketUtilCallback {
void onSuccess(byte[] result);
void onError(Exception e);
}
}
作者:root
Android 自定义 MarqueeView 实现跑马灯效果 – 使用说明
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

