下面是一些关键性代码,记录下来
/** 获取保存APK的路径 */
public static String getSaveApkFilePath()
{
String apkFilePath;
if (hasSDCard())
{
apkFilePath = getRootFilePath() + "com.roboo.template24/";
}
else
{
apkFilePath = getRootFilePath() + "com.roboo.template24/";
String[] command = { "chmod", "777", apkFilePath };
ProcessBuilder builder = new ProcessBuilder(command);
try
{
builder.start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return apkFilePath;
}
/** 是否有SD卡 */
public static boolean hasSDCard()
{
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED))
{
return false;
}
return true;
}
/** 获取下载存放文件的根目录 */
public static String getRootFilePath()
{
if (hasSDCard())
{
// =========================================================================
// =========================================================================
// /mnt/sdcard/android/data/
// =========================================================================
// =========================================================================
return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator+
"android"+File.separator+"data"+ File.separator;
}
else
{
// =========================================================================
// =========================================================================
// /data/data/
// =========================================================================
// =========================================================================
return Environment.getDataDirectory().getAbsolutePath() + File.separator + "data" + File.separator;
}
}