|
|
@ -1,10 +1,12 @@
|
|
|
|
package com.xypower.common;
|
|
|
|
package com.xypower.common;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Environment;
|
|
|
|
|
|
|
|
import android.os.storage.StorageManager;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONArray;
|
|
|
@ -19,6 +21,7 @@ import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -116,6 +119,50 @@ public class MicroPhotoContext {
|
|
|
|
return stringBuilder == null ? null : stringBuilder.toString();
|
|
|
|
return stringBuilder == null ? null : stringBuilder.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取主存储卡路径
|
|
|
|
|
|
|
|
public static String getPrimaryStoragePath(Context context) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
|
|
|
|
|
|
|
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[])null);
|
|
|
|
|
|
|
|
Object[] args = null;
|
|
|
|
|
|
|
|
String[] paths = (String[]) getVolumePathsMethod.invoke(sm, args);
|
|
|
|
|
|
|
|
// first element in paths[] is primary storage path
|
|
|
|
|
|
|
|
return paths[0];
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
// Log.e(TAG, "getPrimaryStoragePath() failed", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取次存储卡路径,一般就是外置 TF 卡了. 不过也有可能是 USB OTG 设备...
|
|
|
|
|
|
|
|
// 其实只要判断第二章卡在挂载状态,就可以用了.
|
|
|
|
|
|
|
|
public static String getSecondaryStoragePath(Context context) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
|
|
|
|
|
|
|
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[])null);
|
|
|
|
|
|
|
|
Object[] args = null;
|
|
|
|
|
|
|
|
String[] paths = (String[]) getVolumePathsMethod.invoke(sm, args);
|
|
|
|
|
|
|
|
// second element in paths[] is secondary storage path
|
|
|
|
|
|
|
|
return paths.length <= 1 ? null : paths[1];
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
// Log.e(TAG, "getSecondaryStoragePath() failed", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取存储卡的挂载状态. path 参数传入上两个方法得到的路径
|
|
|
|
|
|
|
|
public String getStorageState(Context context, String path) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
|
|
|
|
|
|
|
Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", new Class[] {String.class});
|
|
|
|
|
|
|
|
String state = (String) getVolumeStateMethod.invoke(sm, path);
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
// Log.e(TAG, "getStorageState() failed", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isAppAlive(Context context, String packageName) {
|
|
|
|
public static boolean isAppAlive(Context context, String packageName) {
|
|
|
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
|
|
|
|
List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
|
|
|
|