目前国内市场的山寨机横行,安卓手机升级也是一天一个样,对于原来老手机可能没有SDCARD,导致我们的APP不能下载资源,无法更新APP,针对这种情况有以下解决方案。
通过以下函数判断是否有SD卡再判断下载到哪个目录下。

/** * 安装应用 */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.ithtw.com/910.html
  • 转载请注明:leehom2015年01月22日于IT十万为什么发表

更多相关文章

  1. 【原创】The Error in Android(安卓)developing
  2. Android(安卓)webview最简单小例子
  3. Android(安卓)Camera HAL浅析
  4. 在Android(安卓)Studio中使用Android-PullToRefresh Library
  5. android 简单试题系统
  6. Android(安卓)5.0 如何正确启用isLoggable(二)__原理分析
  7. 彻底解决 INSTALL_FAILED_TEST_ONLY安装失败的问题
  8. Mac 打 Android(安卓)包遇到 open too many files 解决办法
  9. 自定义Android日志输出工具类

随机推荐

  1. Android(安卓)actionbar在Material主题中
  2. Android系统开发之七:添加Android(安卓)Na
  3. Android(安卓)文件操作之openFileOutput
  4. Android(安卓)Studio快速添加Gson以及Gso
  5. Android开发学习之TypedArray类
  6. Android(安卓)全局沉浸式显示效果
  7. 翻译Android(安卓)API Guides: App Manif
  8. FFmpeg学习—android 编译libfaac 音频库
  9. 最近下载了ADT Version 22发现里面多了个
  10. android studio 新建class文件报错Unable