android downloadManager问题,求高手

sligner 2013-03-05 07:49:22
我现在是用2.3以后的downloadManager来下载apk文件,当SD卡存在的时候好说,可以用setDestinationInExternalPublicDir来设置,当没有SD卡的时候,我就不设置这个值,用系统默认的,这样问题出现了,没有SD卡的时候,我用COLUMN_LOCAL_URI得到的是content://downloads/my_downloads/125这样的uri,但这样的值我没法打开,我试过2个办法:
1、myIntent.setDataAndType(Uri.parse(filePath),"application/vnd.android.package-archive"); 这样不行,报解析包错误,我看了下载得到的column_type,确实是apk的type
2、Cursor c = managedQuery(Uri.parse(filePath), new String[]{"name","description"}, null, null, null); 查不出东西来,记录count为0

求解,我应该如何处理这样的uri或者如何处理没有SD卡时调用downloadManager下载的问题
...全文
366 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
iloveaman 2014-06-12
  • 打赏
  • 举报
回复
if(有sd卡){ request.setDestinationInExternalPublicDir(savePath, filename);//-->eg./storge/sdcard0/transuner/apks }else{ } 。。。。。 c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))是这样的类型:content://downloads/my_downloads/15,调用以下方法: public static String getFilePathFromUri(Context c, Uri uri) { String filePath = null; if ("content".equals(uri.getScheme())) { String[] filePathColumn = { MediaColumns.DATA }; ContentResolver contentResolver = c.getContentResolver(); Cursor cursor = contentResolver.query(uri, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); filePath = cursor.getString(columnIndex); cursor.close(); } else if ("file".equals(uri.getScheme())) { filePath = new File(uri.getPath()).getAbsolutePath(); } Log.i(TAG, "filePath="+filePath); return filePath; } getFilePathFromUri(Context c, Uri.parse(content://downloads/my_downloads/15))得到apk路径:String uriString = "dat=/data/data/com.android.providers.downloads/cache/xxx. apk" 打开的时候要用: intent.setDataAndType(Uri.fromFile(new File(uriString)), "application/vnd.android.package-archive"); 而不能用 intent.setDataAndType(Uri.parse(uriString), "application/vnd.android.package-archive");
sa_2011 2013-08-06
  • 打赏
  • 举报
回复
楼主怎么解决的啊???582127515@qq.com
lijian8552 2013-05-07
  • 打赏
  • 举报
回复
楼主,问题解决了吗?我也遇到这个问题了。如果你解决了麻烦告诉我下啊。我的QQ:393282035 谢谢哈
sligner 2013-03-06
  • 打赏
  • 举报
回复
顶上去,来个高手解决下啊
sligner 2013-03-06
  • 打赏
  • 举报
回复
没人吗,急,只要解决或思路加分

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧