标签:
/** * 安装应用 */ public static void update(File apkFile, Context context) { Intent intent = new Intent(Intent.ACTION_VIEW); if (apkFile != null && apkFile.exists()) { chmod(apkFile.getAbsolutePath());//授权 intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { MLog.makeText("安装失败,安装文件未找到"); } } public static void chmod(String pathc) { String chmodCmd = "chmod 666 " + pathc; try { Runtime.getRuntime().exec(chmodCmd); } catch (Exception e) { e.printStackTrace(); } } public static boolean isMounted() { return Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED); } /** * 初始文件可以存储的位置 * @param context */ public static void init(Context context) { FileUtil.context = context; StringBuffer buffer = new StringBuffer(); String pName = context.getPackageName(); if (Tools.isMounted()) { buffer.append(Environment.getExternalStorageDirectory() .getAbsolutePath()); buffer.append(File.separator); buffer.append(pName); fileDir = buffer.toString(); } else { buffer.append(context.getFilesDir().getAbsolutePath()); buffer.append(File.separator); buffer.append(pName); fileDir = buffer.toString(); } File file = new File(fileDir); if (!file.exists()) file.mkdir(); }
标签:
原文地址:http://www.cnblogs.com/spring87/p/4525458.html