Android parsing standard click the video intent and androidintent in the third-party File Manager

Source: Internet
Author: User

Android parsing standard click the video intent and androidintent in the third-party File Manager

Parse standard third-party video intent

Private List <String> mCurPlayList = new ArrayList <String> (); private int mCurPosition = 0; // current location information

 

If (intent! = Null & TextUtils. equals (intent. getAction (), Intent. ACTION_VIEW )&&! TextUtils. isEmpty (intent. getType () & intent. getType (). contains ("video") {// used to parse standard third-party video intent String data = intent. getDataString (); // The garbled characters obtained here need to be parsed file: // mnt/udisk2/character String folder = data; if (! TextUtils. isEmpty (data) {if (data. startsWith ("file: //") {data = Uri. decode (data ). substring (7); Logcat. d ("initData replaceFirst data" + data);} if (data. lastIndexOf ("/")> 0) {folder = data. substring (0, data. lastIndexOf ("/"); Logcat. d ("initData substring folder" + folder);} File file = new File (folder); VideoUtils. getVideoFile (mCurPlayList, file); if (mCurPlayList! = Null & mCurPlayList. size ()> 0) {mCurPosition = mCurPlayList. indexOf (data) ;}} Logcat. d ("initData" + data + "; mCurPosition" + mCurPosition );}

 

 

    
// Traverse the video files in the specified directory
Public static void GetVideoFile (final List <String> mList, File file) {if (mList = null) {Logcat. w ("mList is null"); return;} if (file = null) {Logcat. w ("file is null"); return;} mList. clear (); file. listFiles (new FileFilter () {@ Override public boolean accept (File file) {if (FileUtils. isVideo (file) {mList. add (file. getAbsolutePath (); Logcat. d ("initData AbsolutePath" + file. getAbsolutePath (); return true;} return false ;}});}

 

    /** whether the file is video */    public static boolean isVideo(File file) {        String surfix = getFileSurfix(file);        return (surfix.equals("avi") || surfix.equals("mp4")                || surfix.equals("3gp") || surfix.equals("rmvb")                || surfix.equals("mov") || surfix.equals("wmv")                || surfix.equals("mpeg") || surfix.equals("mpg")                || surfix.equals("rm") || surfix.equals("vob")                || surfix.equals("mkv") || surfix.equals("flv")                || surfix.equals("asp") || surfix.equals("ASF")                || surfix.equals("m2ts") || surfix.equals("ts")                || surfix.equals("divx"));    }

 

 

    /** Get file suffix from file path */    public static String getFileSurfix(File file) {        String surfix = "";        if (file != null) {            String filePath = file.getAbsolutePath();            surfix = getFileSurfix(filePath);        }        return surfix.toLowerCase();    }

 

 

    /** Get file suffix from file path */    public static String getFileSurfix(String filePath) {        String surfix = "";        if (filePath != null) {            int surfixPos = filePath.lastIndexOf(".");            int surfixPosDivider = filePath.lastIndexOf("/");            // invalid : abcdefg.hijk/lmn            if (surfixPos > 0 && surfixPos > surfixPosDivider)                surfix = filePath.substring(surfixPos + 1, filePath.length());        }        return surfix.toLowerCase();    }

 

 

          <intent-filter>                <action android:name="android.intent.action.VIEW" />                <data                    android:mimeType="video/*"                    android:scheme="http" />                <data                    android:mimeType="video/*"                    android:scheme="file" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>

 

Printed logs:

11-02 09:34:03. 739 2469-2469 /? D/RRIVI: VideoPlayerActivity. java (318): initData replaceFirst data/mnt/udisk2/Lady. GaGa.-. Poker. Face. avi11-02 09:34:03. 740 2469-2469 /? D/RRIVI: VideoPlayerActivity. java (322): initData substring folder/mnt/udisk211-02 09:34:03. 744 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/Wildlife. wmv11-02 09:34:03. 744 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/Jiangnan silk dancing .mp4 11-02 09:34:03. 745 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/stars-Beijing stars you .mp4 11-02 09:34:03. 746 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/girlhood-My Oh My.mp4 11-02 09:34:03. 746 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/Lady. GaGa.-. Poker. Face. avi11-02 09:34:03. 747 2469-2469 /? D/RRIVI: VideoUtils. java (86): accept: initData AbsolutePath/mnt/udisk2/mv _ girlhood-Gee. rmvb11-02 09:34:03. 747 2469-2469 /? D/RRIVI: VideoPlayerActivity. java (330): initData/mnt/udisk2/Lady. GaGa.-. Poker. Face. avi; mCurPosition 4

 

Related Article

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.