The Android system determines which program to open according to the file extension

From , 4 Years ago, written in Java, viewed 55 times.
URL https://pastebin.vip/view/ecf56315
  1. private void openFile(File f)  
  2.  {  
  3.    Intent intent = new Intent();  
  4.    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  5.    intent.setAction(android.content.Intent.ACTION_VIEW);  
  6.    String type = getMIMEType(f);  
  7.    intent.setDataAndType(Uri.fromFile(f), type);  
  8.    startActivity(intent);  
  9.  }  
  10.  
  11.  private String getMIMEType(File f){  
  12.    String end = f  
  13.        .getName()  
  14.        .substring(f.getName().lastIndexOf(".") + 1,  
  15.            f.getName().length()).toLowerCase();  
  16.    String type = "";  
  17.    if (end.equals("mp3") || end.equals("aac") || end.equals("aac")  
  18.        || end.equals("amr") || end.equals("mpeg")  
  19.        || end.equals("mp4"))  
  20.    {  
  21.      type = "audio";  
  22.    } else if (end.equals("jpg") || end.equals("gif")  
  23.        || end.equals("png") || end.equals("jpeg"))  
  24.    {  
  25.      type = "image";  
  26.    } else
  27.    {  
  28.      type = "*";  
  29.    }  
  30.    type += "/*";  
  31.    return type;  
  32.  }
  33. //java/6859

Reply to "The Android system determines which program to open according to the file extension"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website