点击文件,跳转到wps浏览

当文件下载完毕之后,需要进行浏览,有两种方式:

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;
    }

}

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭