这是最近在项目中遇到的问题,测试给提Bug时描述如下:录音后进入文件管理器中查看录音文件时,文件管理器停止运行,抓取log后发现是权限异常,刚开始以为在AndroidManifest.xml中加入相应的权限后就可以解决,但实际添加后依然没有起到效果,后来对比手头的另一个样机,是MT6750的就可以正常进入,然后对比两者的文件管理器代码后发现了区别,做如下修改后可解决此问题。
需要修改的文件路径如下:alps/vendor/mediatek/proprietary/packages/apps/FileManager 下的两支文件
1. alps/vendor/mediatek/proprietary/packages/apps/FileManager/src/com/mediatek/filemanager/FileInfo.java
注释到如下3部分的代码:
(1)
+// private static HashMap<String, String> sMimeType3GPPMap = new HashMap<String, String>();
(2)
+// if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_UNKONW)) {
+// mimeType = service.update3gppMimetype(this);
+// }
+//
+// if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_AUDIO)
+// || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_VIDEO)
+// || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP2_VIDEO)) {
+// String name = null;
+// int sepIndex = mName.lastIndexOf("(");
+// if (sepIndex > 0) {
+// name = mName.substring(0, sepIndex);
+// } else {
+// name = mName.substring(0, mName.indexOf("."));
+// }
+// LogUtils.d(TAG, "getFileMimeType ,record the mimetype: " + mimeType + ",name = "
+// + name + ",mName = " + mName);
+//
+// sMimeType3GPPMap.put(name, mimeType);
+// }(3)
+// if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_VIDEO)
+// || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP2_VIDEO)) {
+// LogUtils.d(TAG, "getMimeType, a 3gpp or 3g2 file,mimeType=" + mimeType);
+// return FileInfo.MIMETYPE_3GPP_UNKONW;
+// }
2. alps/vendor/mediatek/proprietary/packages/apps/FileManager/src/com/mediatek/filemanager/service/FileManagerService.java
注释掉如下代码:
+// public String update3gppMimetype(FileInfo fileInfo) {
+// LogUtils.d(TAG, "update3gppMimetype...");
+// String mimeType = FileInfo.MIMETYPE_3GPP_VIDEO;
+// ContentResolver resolver = getContentResolver();
+// if (resolver != null && fileInfo != null) {
+// // fileInfo.setFileMimeType(FileInfo.MIMETYPE_3GPP_VIDEO);
+// final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
+// final String[] projection = new String[] { MediaStore.MediaColumns.MIME_TYPE };
+// final String selection = MediaStore.MediaColumns.DATA + "=?";
+// final String[] selectionArgs = new String[] { fileInfo
+// .getFileAbsolutePath() };
+// Cursor cursor = null;
+// try {
+// cursor = resolver.query(uri, projection, selection,
+// selectionArgs, null);
+// LogUtils.d(TAG, "update3gppMimetype,file:" + fileInfo.getFileAbsolutePath());
+// if (cursor != null && cursor.moveToFirst()) {
+// mimeType = cursor.getString(cursor
+// .getColumnIndex(MediaStore.MediaColumns.MIME_TYPE));
+// LogUtils.d(TAG, "update3gppMimetype mimeType: " + mimeType);
+// } else {
+// mimeType = fileInfo.getFileOriginMimeType();
+// LogUtils.d(TAG, "update3gppMimetype, not find from media,origin mimeType: " + mimeType);
+// if (mimeType == null) {
+// mimeType = FileInfo.MIMETYPE_3GPP_VIDEO;
+// }
+// }
+// } finally {
+// if (cursor != null) {
+// cursor.close();
+// }
+// }
+// }
+//
+// return mimeType;
+// }
以上两只文件中的代码注释掉以后,单编push之后就可以直接访问文件管理器中的录音文件,不会在有权限异常了。