Import android. app. Activity;
Import android. content. Intent;
Import android.net. Uri;
Import android.net. Uri. Builder;
Import java. io. File;
Import android. content. Intent;
// Customize the android Intent class,
// You can obtain the intent used to open the following files.
// PDF, PPT, WORD, EXCEL, CHM, HTML, TEXT, AUDIO, and VIDEO
Example:
// Can this token be because the. APK program does not have the permission to access the asset resource file in other APK files or the path is wrong?
// Intent it = getPdfFileIntent ("file: // android_asset/helphelp ");
// The following are all OK
// Intent it = getHtmlFileIntent ("/mnt/sdcard/tutorial.html"); // SD card home directory
// Intent it = getHtmlFileIntent ("/sdcard/tutorial.html"); // SD card Home Directory, which can also be
Intent it = getHtmlFileIntent ("/system/etc/tutorial.html"); // etc directory in the system
// Intent it = getPdfFileIntent ("/system/etc/helphelp ");
// Intent it = getWordFileIntent ("/system/etc/help.doc ");
// Intent it = getExcelFileIntent ("/mnt/sdcard/Book1.xls ")
// Intent it = getPptFileIntent ("/mnt/sdcard/download/Android_PPT.ppt"); // download directory of the SD card
// Intent it = getVideoFileIntent ("/mnt/sdcard/ice. avi ");
// Intent it = getAudioFileIntent ("/mnt/sdcard/rename ");
// Intent it = getImageFileIntent ("/mnt/sdcard/images/001020.80.jpg ");
// Intent it = getTextFileIntent ("/mnt/sdcard/hello.txt", false );
StartActivity (it );
Public class MyIntent
{
// Android obtains an intent used to open an HTML file.
Public static Intent getHtmlFileIntent (String param)
{
Uri uri = Uri. parse (param). buildUpon (). encodedAuthority ("com.android.html fileprovider"). scheme ("content"). encodedPath (param). build ();
Intent intent = new Intent ("android. intent. action. VIEW ");
Intent. setDataAndType (uri, "text/html ");
Return intent;
}
// Android obtains an intent used to open an image 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 obtains an intent used to open a 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 obtains an intent used to open a 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 obtains an intent used 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 obtains an intent used to open a 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 obtains an intent used 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 obtains an intent used to open a Word file.
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 obtains an intent used to open 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 obtains an intent used to open the pptfile.
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;
}
}
Heartbroken by you