注:本篇小知识点都是在实际项目中运用过的,比较可靠
##20170606
###1 解压tar包指令
tar –xvf file.tar //解压 tar包
2 判断图片格式
通过后缀名判断图片是什么格式其实并不准确,可以使用BitmapFactory的方法去判断:
String path = "图片路径";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
String type = options.outMimeType;
if (TextUtils.isEmpty(type)) {
type = "未能识别的图片";
} else {
type = type.substring(6, type.length());
}
返回的type是image/png、 image/jpeg 、image/gif这种,如果识别不了就返回null
###3 删除文件EBUSY异常处理
在Android中如果删除一个文件或者文件目录后,之后还想要使用同样名字的文件或目录,会报EBUSY异常,解决办法是删除之前先重命名
public static boolean deleteFile(String path) {
if (TextUtils.isEmpty(path)) return true;
File file = new File(path);
if (!file.exists()) return true;
if (file.isFile()) {
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
file.renameTo(to);
return to.delete();
}
return false;
}
##20170623
###使用AtomicLong实现rxjava interval暂停与恢复
private Subscription subTimer;
private AtomicLong tick = new AtomicLong(100L);
public void stopTimer() {
if (subTimer != null && !subTimer.isUnsubscribed()) {
subTimer.unsubscribe();
}
}
public void resumeTimer() {
subTimer = Observable.interval(1, TimeUnit.SECONDS, Schedulers.io())
.map(new Func1<Long, Long>() {
@Override
public Long call(Long aLong) {
return tick.getAndDecrement();
}
})
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
System.out.println("holatimer: " + aLong);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
});
}
##20170627
###不使用WebView执行js代码
可以使用square的开源项目duktape,地址是https://github.com/square/duktape-android
##20170807
###git一直追踪.idea目录解决
直接在.gitignore中添加.idea是忽略不了的,除非删除再添加
先执行git rm -rf --cached .idea 再add commit
##20180927
lipo指令合并.a静态库
目的是合并iOS真机静态库和模拟器静态库。
lipo -create [one absolute path] [the other absolute path] -output [output absolute path]
执行后会生成真机和模拟器合并后的.a文件。
查看.a文件信息:
lipo -info [absolute path]
gradle编译制定模块
gradle :子模块名:build