/**
	 * 安装应用
	 */
	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();
	}

  

 

相关文章:

  • 2021-12-09
  • 2021-09-05
  • 2022-01-16
  • 2021-09-02
  • 2021-11-30
  • 2021-12-09
  • 2022-01-01
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2021-05-26
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案