EasyClick 免Root脚本 发送Intent打开文件Activity源码

B站视频地址: https://www.bilibili.com/video/BV1W54y1Q7JG/

网站地址 : http://ieasyclick.com

技术交流QQ群 2557945562

新一代简单易学,开箱即用,可编程式自动化测试软件 免ROOT不限手机环境,

支持Android 5.0到10,全节点分析不限分辨率,OpenCV图色识别 JS编程简单易学,

IDEA智能开发工具支持,实时投屏预览运行 支持OpenApi,

不限调用者环境,跨语言调用。

以下代码是发送Intent让系统打开文件的Activity源码:

importClass(java.io.File)
importClass (android.content.Intent)
importClass (android.net.Uri)
importClass (android.os.Build)
importClass (android.os.StrictMode)


function openAndroidFile( filepath){
     
    var intent = new Intent();
    try {
     
        if (Build.VERSION.SDK_INT >= 25) {
     
            //安卓7.0以上
            var builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            var file = new File(filepath);
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//设置标记
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setAction(Intent.ACTION_VIEW);//动作,查看

            intent.setDataAndType(Uri.fromFile(file), getMIMEType(filepath))
        }else {
     
            intent = new Intent("android.intent.action.VIEW");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            //  uri1 = Uri.parse(filepath  );
            // intent.setDataAndType(uri1, "text/plain");
            //
             uri2 = Uri.fromFile(new File(filepath ));
            intent.setDataAndType(uri2, "text/plain");
        }
    }catch( az){
     
        logd("openAndroidFile:"+az)
    }


    return intent


}

function getMIMEType(file) {
     
    var MIME_MapTable=
            //{后缀名,    MIME类型}

            {
     ".3gp":    "video/3gpp",
                ".apk":    "application/vnd.android.package-archive",
                ".asf":    "video/x-ms-asf",
                ".avi":    "video/x-msvideo",
                ".bin":    "application/octet-stream",
                ".bmp":      "image/bmp",
                ".c":        "text/plain",
                ".class":    "application/octet-stream",
                ".conf":    "text/plain",
                ".cpp":    "text/plain",
                ".doc":    "application/msword",
                ".docx":    "application/msword",
                ".exe":    "application/octet-stream",
                ".gif":    "image/gif",
                ".gtar":    "application/x-gtar",
                ".gz":        "application/x-gzip",
                ".h":        "text/plain",
                ".htm":    "text/html",
                ".html":    "text/html",
                ".jar":    "application/java-archive",
                ".java":    "text/plain",
                ".jpeg":    "image/jpeg",
                ".JPEG":    "image/jpeg",
                ".jpg":    "image/jpeg",
                ".js":        "application/x-javascript",
                ".log":    "text/plain",
                ".m3u":    "audio/x-mpegurl",
                ".m4a":    "audio/mp4a-latm",
                ".m4b":    "audio/mp4a-latm",
                ".m4p":    "audio/mp4a-latm",
                ".m4u":    "video/vnd.mpegurl",
                ".m4v":    "video/x-m4v",
                ".mov":    "video/quicktime",
                ".mp2":    "audio/x-mpeg",
                ".mp3":    "audio/x-mpeg",
                ".mp4":    "video/mp4",
                ".mpc":    "application/vnd.mpohun.certificate",
                ".mpe":    "video/mpeg",
                ".mpeg":    "video/mpeg",
                ".mpg":    "video/mpeg",
                ".mpg4":    "video/mp4",
                ".mpga":    "audio/mpeg",
                ".msg":    "application/vnd.ms-outlook",
                ".ogg":    "audio/ogg",
                ".pdf":    "application/pdf",
                ".png":    "image/png",
                ".pps":    "application/vnd.ms-powerpoint",
                ".ppt":    "application/vnd.ms-powerpoint",
                ".pptx":    "application/vnd.ms-powerpoint",
                ".prop":    "text/plain",
                ".rar":    "application/x-rar-compressed",
                ".rc":        "text/plain",
                ".rmvb":    "audio/x-pn-realaudio",
                ".rtf":    "application/rtf",
                ".sh":        "text/plain",
                ".tar":    "application/x-tar",
                ".tgz":    "application/x-compressed",
                ".txt":    "text/plain",
                ".xls":    "text/plain",
                ".csv":     "text/plain",
                ".wav":    "audio/x-wav",
                ".wma":    "audio/x-ms-wma",
                ".wmv":    "audio/x-ms-wmv",
                ".wps":    "application/vnd.ms-works",
                //".xml",    "text/xml",
                ".xml":    "text/plain",
                ".z":        "application/x-compress",
                ".zip":    "application/zip",
                "":        "*/*"}

    var type="*/*";
    var fName = file
    //获取后缀名前的分隔符"."在fName中的位置。
    var dotIndex = fName.lastIndexOf(".");
    if(dotIndex < 0)
        return type;
    /* 获取文件的后缀名 */
   var fileType = fName.substr(dotIndex).toLowerCase();
    if(fileType == null || "".equals(fileType))
        return type;
    //在MIME和文件类型的匹配表中找到对应的MIME类型。
    for(var key in MIME_MapTable){
     
        if(fileType.equals(key )){
     
            type = MIME_MapTable[key];
        }
    }
    return type;
}

你可能感兴趣的:(EasyClick,安卓,jdk,xml)