Open various types of files with intent

Source: Internet
Author: User

public class Myintent {
Android gets a intent to open the HTML file
public static Intent gethtmlfileintent (String param) {
Uri uri = uri.parse (param). Buildupon (). Encodedauthority ("Com.android.htmlfileprovider"). Scheme ("content"). Encodedpath (param). build ();
Intent Intent = new Intent ("Android.intent.action.VIEW");
Intent.setdataandtype (URI, "text/html");
return intent;
}
Android gets a intent to open the picture file
public static Intent getimagefileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "image/*");
return intent;
}
Android gets a intent to open the PDF file
public static Intent getpdffileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "application/pdf");
return intent;
}
Android gets a intent to open the text file
public static Intent gettextfileintent (String param, Boolean Paramboolean) {
Intent Intent = new Intent ("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 (new File (param));
Intent.setdataandtype (Uri2, "Text/plain");
}
return intent;
}
Android gets a intent to open the audio file
public static Intent getaudiofileintent (String param) {
Intent Intent = new Intent ("Android.intent.action.VIEW");
Intent.addflags (Intent.flag_activity_clear_top);
Intent.putextra ("OneShot", 0);
Intent.putextra ("Configchange", 0);
Uri uri = uri.fromfile (new File (param));
Intent.setdataandtype (URI, "audio/*");
return intent;
}
Android gets a intent to open the video file
public static Intent getvideofileintent (String param) {
Intent Intent = new Intent ("Android.intent.action.VIEW");
Intent.addflags (Intent.flag_activity_clear_top);
Intent.putextra ("OneShot", 0);
Intent.putextra ("Configchange", 0);
Uri uri = uri.fromfile (new File (param));
Intent.setdataandtype (URI, "video/*");
return intent;
}

Android gets a intent to open the CHM file
public static Intent getchmfileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "Application/x-chm");
return intent;
}

Android gets a intent for opening Word files
public static Intent getwordfileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "Application/msword");
return intent;
}
Android gets a intent that opens an Excel file
public static Intent getexcelfileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "application/vnd.ms-excel");
return intent;
}
Android gets a intent for opening PPT files
public static Intent getpptfileintent (String param) {
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 (new File (param));
Intent.setdataandtype (URI, "Application/vnd.ms-powerpoint");
return intent;
}
}

Open various types of files with intent

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.