Android Development gets various intent (images, apk files, Excel, PDFs, etc.)

Source: Internet
Author: User

 Public StaticIntent openFile (String filePath) {File file=NewFile (FilePath); if(!file.exists ())return NULL; /*Get extension*/String End=file.getname (). substring (File.getname (). LastIndexOf (".") + 1, File.getname (). Length ()). toLowerCase (); /*Depends on the type of extension mimetype*/        if(End.equals ("m4a") | | End.equals ("MP3") | | End.equals ("mid") | |End.equals ("XMF") | | End.equals ("ogg") | | End.equals ("WAV")){            returngetaudiofileintent (FilePath); }Else if(End.equals ("3gp") | | End.equals ("MP4")){            returngetaudiofileintent (FilePath); }Else if(End.equals ("jpg") | | End.equals ("gif") | | End.equals ("png") | |End.equals ("JPEG") | | End.equals ("BMP")){            returngetimagefileintent (FilePath); }Else if(End.equals ("apk")){            returngetapkfileintent (FilePath); }Else if(End.equals ("ppt")){            returngetpptfileintent (FilePath); }Else if(End.equals ("xls")){            returngetexcelfileintent (FilePath); }Else if(End.equals ("Doc")){            returngetwordfileintent (FilePath); }Else if(End.equals ("PDF")){            returngetpdffileintent (FilePath); }Else if(End.equals ("CHM")){            returngetchmfileintent (FilePath); }Else if(End.equals ("TXT")){            returnGettextfileintent (FilePath,false); }Else{            returngetallintent (FilePath); }    }        //Android Gets a intent to open the APK file     Public StaticIntent getallintent (String param) {Intent Intent=NewIntent ();          Intent.addflags (Intent.flag_activity_new_task);          Intent.setaction (Android.content.Intent.ACTION_VIEW); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"*/*"); returnIntent; }    //Android Gets a intent to open the APK file     Public StaticIntent getapkfileintent (String param) {Intent Intent=NewIntent ();          Intent.addflags (Intent.flag_activity_new_task);          Intent.setaction (Android.content.Intent.ACTION_VIEW); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/vnd.android.package-archive"); returnIntent; }    //Android Gets a intent to open the video file     Public StaticIntent getvideofileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW");        Intent.addflags (Intent.flag_activity_clear_top); Intent.putextra ("OneShot", 0); Intent.putextra ("Configchange", 0); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"video/*"); returnIntent; }    //Android Gets a intent to open the audio file     Public StaticIntent getaudiofileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW");        Intent.addflags (Intent.flag_activity_clear_top); Intent.putextra ("OneShot", 0); Intent.putextra ("Configchange", 0); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"audio/*"); returnIntent; }    //Android Gets a intent to open the HTML file     Public StaticIntent gethtmlfileintent (String param) {URI uri= Uri.parse (param). Buildupon (). Encodedauthority ("Com.android.htmlfileprovider"). Scheme ("Content"). Encodedpath (param). build (); Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.setdataandtype (URI,"Text/html"); returnIntent; }    //Android Gets a intent to open the picture file     Public StaticIntent getimagefileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");        Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Image/*"); returnIntent; }    //Android Gets a intent for opening PPT files     Public StaticIntent getpptfileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/vnd.ms-powerpoint"); returnIntent; }       //Android Gets a intent that opens an Excel file     Public StaticIntent getexcelfileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/vnd.ms-excel"); returnIntent; }       //Android Gets a intent for opening Word files     Public StaticIntent getwordfileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/msword"); returnIntent; }       //Android Gets a intent to open the CHM file     Public StaticIntent getchmfileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/x-chm"); returnIntent; }       //Android Gets a intent to open the text file     Public StaticIntent gettextfileintent (String param,BooleanParamboolean) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); if(Paramboolean) {Uri Uri1=uri.parse (param); Intent.setdataandtype (Uri1,"Text/plain"); }Else{Uri Uri2= Uri.fromfile (NewFile (param)); Intent.setdataandtype (Uri2,"Text/plain"); }           returnIntent; }      //Android Gets a intent to open the PDF file     Public StaticIntent getpdffileintent (String param) {Intent Intent=NewIntent ("Android.intent.action.VIEW"); Intent.addcategory ("Android.intent.category.DEFAULT");           Intent.addflags (Intent.flag_activity_new_task); Uri URI= Uri.fromfile (NewFile (param)); Intent.setdataandtype (URI,"Application/pdf"); returnIntent; }

Android Development gets various intent (images, apk files, Excel, PDFs, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.