|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.core.utils;
|
|
|
+package com.modular.apputils.utils;
|
|
|
|
|
|
import android.app.DownloadManager;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
@@ -6,19 +6,13 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
-import android.os.Build;
|
|
|
-import android.os.Environment;
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.common.LogUtil;
|
|
|
import com.core.app.R;
|
|
|
import com.core.app.MyApplication;
|
|
|
-import com.core.net.http.HttpUtil;
|
|
|
-import com.lidroid.xutils.HttpUtils;
|
|
|
-import com.lidroid.xutils.exception.HttpException;
|
|
|
-import com.lidroid.xutils.http.ResponseInfo;
|
|
|
-import com.lidroid.xutils.http.callback.RequestCallBack;
|
|
|
+import com.modular.apputils.activity.PDFViewActivity;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
@@ -72,9 +66,16 @@ public class OpenFilesUtils {
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
Uri uri = Uri.fromFile(file);
|
|
|
intent.setDataAndType(uri, "application/pdf");
|
|
|
+
|
|
|
+
|
|
|
return intent;
|
|
|
}
|
|
|
|
|
|
+ private static Intent openFileByTBS(Context context, String filepath) {
|
|
|
+ return new Intent(context, PDFViewActivity.class)
|
|
|
+ .putExtra("filepath", filepath);
|
|
|
+ }
|
|
|
+
|
|
|
//android获取一个用于打开文本文件的intent
|
|
|
public static Intent getTextFileIntent(File file) {
|
|
|
Intent intent = new Intent("android.intent.action.VIEW");
|
|
|
@@ -198,7 +199,7 @@ public class OpenFilesUtils {
|
|
|
ct.startActivity(intent);
|
|
|
} else if (checkEndsWithInStringArray(fileName, ct.getResources().
|
|
|
getStringArray(R.array.fileEndingPdf))) {
|
|
|
- intent = getPdfFileIntent(currentPath);
|
|
|
+ intent = openFileByTBS(ct, currentPath.getPath());
|
|
|
ct.startActivity(intent);
|
|
|
} else if (checkEndsWithInStringArray(fileName, ct.getResources().
|
|
|
getStringArray(R.array.fileEndingWord))) {
|
|
|
@@ -304,111 +305,9 @@ public class OpenFilesUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// public static void downLoadFile(String url, String fileName, RequestCallBack<File> requestCallBack) {
|
|
|
-// // 判断是否有SD卡
|
|
|
-// if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
|
-// HttpUtils utils = new HttpUtils();
|
|
|
-// String target = Environment.getDataDirectory() + "/uu/download/" + fileName;
|
|
|
-// utils.download(url, target, requestCallBack);
|
|
|
-// } else {
|
|
|
-// Toast.makeText(MyApplication.getInstance(), "请先插入SD卡", Toast.LENGTH_SHORT).show();
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- public static void downLoadFile(final String url, String fileName, final OnFileLoadListener onFileLoadListener) {
|
|
|
- // 判断是否有SD卡
|
|
|
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
|
- final String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/uu/download";
|
|
|
-
|
|
|
- //如果存在文件,不在下载
|
|
|
- File file = new File(path + "/" + fileName);
|
|
|
- if (file != null && file.exists()) {
|
|
|
- if (onFileLoadListener != null) {
|
|
|
- onFileLoadListener.onSuccess(file);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (Build.VERSION.SDK_INT > 19) {
|
|
|
- HttpUtil.download(url, path, fileName, onFileLoadListener);
|
|
|
- } else {
|
|
|
- HttpUtils utils = new HttpUtils();
|
|
|
- utils.download(url, path + fileName, new RequestCallBack<File>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(ResponseInfo<File> responseInfo) {
|
|
|
- File file = responseInfo.result;
|
|
|
- onFileLoadListener.onSuccess(file);
|
|
|
- LogUtil.i("file=" + file.getPath());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFailure(HttpException e, String s) {
|
|
|
- LogUtil.i("e=" + e.getMessage());
|
|
|
- LogUtil.i("s=" + s);
|
|
|
- onFileLoadListener.onFailure(e.getMessage());
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- Toast.makeText(MyApplication.getInstance(), "请先插入SD卡", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public static void showFileToast(String word) {
|
|
|
Toast.makeText(MyApplication.getInstance(), word, Toast.LENGTH_LONG).show();
|
|
|
}
|
|
|
|
|
|
- // 生成文件
|
|
|
-// public File makeFilePath(String filePath, String fileName) {
|
|
|
-// File file = null;
|
|
|
-// makeRootDirectory(filePath);
|
|
|
-// try {
|
|
|
-// file = new File(filePath + fileName);
|
|
|
-// if (!file.exists()) {
|
|
|
-// file.createNewFile();
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// return file;
|
|
|
-// }
|
|
|
-
|
|
|
- // 生成文件夹
|
|
|
-// public static void makeRootDirectory(String filePath) {
|
|
|
-// File file = null;
|
|
|
-// try {
|
|
|
-// file = new File(filePath);
|
|
|
-// if (!file.exists()) {
|
|
|
-// file.mkdir();
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// }
|
|
|
-// } public static void makeRootDirectory(String filePath) {
|
|
|
-// File file = null;
|
|
|
-// try {
|
|
|
-// file = new File(filePath);
|
|
|
-// if (!file.exists()) {
|
|
|
-// file.mkdir();
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// }
|
|
|
-// } public static void makeRootDirectory(String filePath) {
|
|
|
-// File file = null;
|
|
|
-// try {
|
|
|
-// file = new File(filePath);
|
|
|
-// if (!file.exists()) {
|
|
|
-// file.mkdir();
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- public interface OnFileLoadListener {
|
|
|
- void onLoadIng(int progress, int allProgress);
|
|
|
-
|
|
|
- void onSuccess(File file);
|
|
|
-
|
|
|
- void onFailure(String exception);
|
|
|
- }
|
|
|
+
|
|
|
}
|