你好,游客 登录 注册 搜索
背景:
阅读新闻

Android开发打开文件的Intent及使用

[日期:2013-01-20] 来源:Linux社区  作者:loongggdroid [字体:大 中 小]

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("对不起,这不是文件!");
    }

linux
相关资讯       Android Intent 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款