Android开发打开文件的Intent及使用(3)

3、定义用于检查要打开的文件的后缀是否在遍历后缀数组中

private boolean checkEndsWithInStringArray(String checkItsEnd,
    String[] fileEndings){
    for(String aEnd : fileEndings){
    if(checkItsEnd.endsWith(aEnd))
    return true;
    }
    return false;
    }

4、通过调用OpenFiles类返回的Intent,打开相应的文件

if(currentPath!=null&¤tPath.isFile())
    {
    String fileName = currentPath.toString();
    Intent intent;
    if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingImage))){
    intent = OpenFiles.getImageFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingWebText))){
    intent = OpenFiles.getHtmlFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingPackage))){
    intent = OpenFiles.getApkFileIntent(currentPath);
    startActivity(intent);
   
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingAudio))){
    intent = OpenFiles.getAudioFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingVideo))){
    intent = OpenFiles.getVideoFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingText))){
    intent = OpenFiles.getTextFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingPdf))){
    intent = OpenFiles.getPdfFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingWord))){
    intent = OpenFiles.getWordFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingExcel))){
    intent = OpenFiles.getExcelFileIntent(currentPath);
    startActivity(intent);
    }else if(checkEndsWithInStringArray(fileName, getResources().
    getStringArray(R.array.fileEndingPPT))){
    intent = OpenFiles.getPPTFileIntent(currentPath);
    startActivity(intent);
    }else
    {
    showMessage("无法打开,请安装相应的软件!");
    }
    }else
    {
    showMessage("对不起,这不是文件!");
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/66130daacd8f7f74c5eb71b62d5bfff1.html