节选自:Eclipse中文字体大小修改
解决方法如下:Window –> Preferences –> General –> Appearance –> Colors and Fonts,展开”Basic” 选择”Text Font”,然后点”Edit”,把大小里的值改为”五号”即可。
节选自:Eclipse中文字体大小修改
解决方法如下:Window –> Preferences –> General –> Appearance –> Colors and Fonts,展开”Basic” 选择”Text Font”,然后点”Edit”,把大小里的值改为”五号”即可。
节选自:android 版本号大小比较
/**
* 版本号比较
*
* @param version1
* @param version2
* @return
*/
public static int compareVersion(String version1, String version2) {
if (version1.equals(version2)) {
return 0;
}
String[] version1Array = version1.split("\\.");
String[] version2Array = version2.split("\\.");
int index = 0;
// 获取最小长度值
int minLen = Math.min(version1Array.length, version2Array.length);
int diff = 0;
// 循环判断每位的大小
while (index < minLen
&& (diff = Integer.parseInt(version1Array[index])
- Integer.parseInt(version2Array[index])) == 0) {
index++;
}
if (diff == 0) {
// 如果位数不一致,比较多余位数
for (int i = index; i < version1Array.length; i++) {
if (Integer.parseInt(version1Array[i]) > 0) {
return 1;
}
}
for (int i = index; i < version2Array.length; i++) {
if (Integer.parseInt(version2Array[i]) > 0) {
return -1;
}
}
return 0;
} else {
return diff > 0 ? 1 : -1;
}
}
节选自:Android 通过apk文件获取相应的包名和版本号
通过下面方法可以直接获取到apk的包名和版本号:apkPath是apk存放的路径
public static Drawable GetApkInfo(Context context, String apkPath) {
PackageManager pm = context.getPackageManager();
PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
if (info != null) {
ApplicationInfo appInfo = info.applicationInfo;
String packageName = appInfo.packageName; //得到安装包名称
String version = info.versionName;//获取安装包的版本号
Log.i(TAG, "getApkIcon: " + packageName + "-------" + version);
try {
return appInfo.loadIcon(pm);
} catch (OutOfMemoryError e) {
Log.i(TAG, "GetApkInfo: " + e);
}
}
return null;
}
节选自:Android获取文件的MD5
private void getFile(){ String path = Environment.getExternalStorageDirectory().getAbsolutePath(); Log.d("ATG", path); File file = new File(path+"/e8706cf83a2cda33dae5c40025922d75.apk"); String md5 = getFileMD5(file); Log.d("ATG", md5); } public static String getFileMD5(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte buffer[] = new byte[1024]; int len; try { digest = MessageDigest.getInstance("MD5"); in = new FileInputStream(file); while ((len = in.read(buffer, 0, 1024)) != -1) { digest.update(buffer, 0, len); } in.close(); } catch (Exception e) { e.printStackTrace(); return null; } return bytesToHexString(digest.digest()); } public static String bytesToHexString(byte[] src) { StringBuilder stringBuilder = new StringBuilder(""); if (src == null || src.length <= 0) { return null; } for (int i = 0; i < src.length; i++) { int v = src[i] & 0xFF; String hv = Integer.toHexString(v); if (hv.length() < 2) { stringBuilder.append(0); } stringBuilder.append(hv); } return stringBuilder.toString(); }
节选自:Retrofit2文件上传与下载
public interface Api {
/**
* 上传
* Multipart 这个注解代表多表单上传
*
* @param partList 表单信息
* @return .
*/
@Multipart
@POST("服务器地址(就创建retrofit设置的基站地址后面的具体地址)")
Call<BaseBean> upLoading(@Part List<MultipartBody.Part> partList);
}
节选自:Android 本应用数据清除管理器DataCleanManager
/**
* * 清除本应用内部缓存(/data/data/com.xxx.xxx/cache) * *
*
* @param context
*/
public static void cleanInternalCache(Context context) {
deleteFilesByDirectory(context.getCacheDir());
}
import android.content.Context;
import android.content.pm.PackageManager;
public class AppVersionUtils {
/**
* 获取当前app version code
*
* @param context
* @return
*/
public static int getVersionCode(Context context) {
int versionCode = 0;
try {
versionCode = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionCode;
}
/**
* 获取当前app version name
*
* @param context 上下文
* @return
*/
public static String getVersionName(Context context) {
String versionName = "";
try {
versionName = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}
}
Android开发过程中,在 Activity的生命周期里协调耗时任务可能会很困难,你一不小心就会导致内存泄漏问题。下面是一些小提示,能帮助你预防内存泄漏问题的发生: 继续阅读Android中内存泄露与如何有效避免OOM总结
/data/logs