點選檔案,跳轉到wps瀏覽
阿新 • • 發佈:2018-11-08
當檔案下載完畢之後,需要進行瀏覽,有兩種方式:
1:使用TBS,即騰訊瀏覽服務,點選開啟連結
2:使用wps,由於專案受制於網路,故使用第二種方式實現,程式碼如下
public class WpsFileUtils { private static boolean isInstall = false; public static boolean openFileWithWps(Context context, String path) { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("OpenMode", "ReadMode");//wps的api引數 bundle.putBoolean("SendCloseBroad", true); bundle.putString("ThirdPackage", "com.android.settings"); bundle.putBoolean("ClearBuffer", true); bundle.putBoolean("ClearTrace", true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction("android.intent.action.VIEW"); intent.setAction("android.intent.action.EDIT"); intent.setType("application/pdf");//設定pdf能夠開啟 intent.setClassName("cn.wps.moffice_eng", "cn.wps.moffice.documentmanager.PreStartActivity");//啟動wps File file = new File(path); if (file == null || !file.exists()) { return false; } Uri uri = Uri.fromFile(file); System.out.println("uri----<" + uri); intent.setData(uri); intent.putExtras(bundle); try { context.startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } // 判斷是否安裝wps public static boolean isInstall(Context context) { List<PackageInfo> list = context.getPackageManager().getInstalledPackages( PackageManager.GET_PERMISSIONS); StringBuilder stringBuilder = new StringBuilder(); for (PackageInfo packageInfo : list) { stringBuilder.append("package name:" + packageInfo.packageName + "\n"); ApplicationInfo applicationInfo = packageInfo.applicationInfo; stringBuilder.append("應用名稱:" + applicationInfo.loadLabel(context.getPackageManager()) + "\n"); if (packageInfo.permissions != null) { for (PermissionInfo p : packageInfo.permissions) { stringBuilder.append("許可權包括:" + p.name + "\n"); } } stringBuilder.append("\n"); if ("cn.wps.moffice_eng".equals(packageInfo.packageName)) { Log.i("ivor_chan", packageInfo.packageName); isInstall = true; } } return isInstall; } }