Android编程开发之打开文件的Intent及使用方法

2019-12-10 19:55:35丽君
  • }   //android获取一个用于打开PPT文件的intent  
  • public static Intent getPPTFileIntent(File file)   {  
  • Intent intent = new Intent("android.intent.action.VIEW");   intent.addCategory("android.intent.category.DEFAULT");  
  • intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   Uri uri = Uri.fromFile(file);  
  • intent.setDataAndType(uri, "application/vnd.ms-powerpoint");   return intent;  
  • }   //android获取一个用于打开apk文件的intent  
  • public static Intent getApkFileIntent(File file)   {  
  • Intent intent = new Intent();   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  • intent.setAction(android.content.Intent.ACTION_VIEW);   intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");  
  • return intent;   }  
  • 3、定义用于检查要打开的文件的后缀是否在遍历后缀数组中

     

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