In the various file manager under Android, we choose a file, click on share can see pop up some apps for us to choose, this is the Android system sharing function, we do the app can also appear in this list.
First step: Configure in Manifest.xml, add a intent filter more than normal activity
- <activity
- Android:name= "Com.example.share.MainActivity"
- Android:label= "@string/app_name" >
- <intent-filter>
- <action android:name= "Android.intent.action.MAIN"/>
- <category android:name= "Android.intent.category.LAUNCHER"/>
- </intent-filter>
- <intent-filter>
- <action android:name= "Android.intent.action.SEND"/>
- <category android:name= "Android.intent.category.DEFAULT"/>
- <!--Specify the type of sharing I can only share MP4--
- <data android:mimetype= "Video/mp4"/>
- </intent-filter>
- </activity>
The second step: when users share the choice of our app, will jump to the corresponding activity, in the avtivity to get the file path. And do what we want to do.
- public class Mainactivity extends Activity {
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- Super.oncreate (savedinstancestate);
- Setcontentview (R.layout.activity_main);
- TextView pathtextview= (TextView) Findviewbyid (R.id.path);
- Intent Intent = Getintent ();
- String action = Intent.getaction ();//action
- String type = Intent.gettype ();//Type
- Type is MP4 type
- if (Intent.ACTION_SEND.equals (ACTION) && type! = null && "Video/mp4". Equals (type)) {
- Uri uri = (URI) Intent.getparcelableextra (Intent.extra_stream);
- If the media type needs to get the path from the database
- String Filepath=getrealpathfromuri (URI);
- Pathtextview.settext ("Video File path:" +filepath);
- }
- }
- /**
- * Get the true path of the file stored locally by URI
- */
- Private String Getrealpathfromuri (Uri Contenturi) {
- String[] proj = {MediaStore.MediaColumns.DATA};
- Cursor cursor=getcontentresolver (). Query (Contenturi, proj, NULL, NULL, NULL);
- if (Cursor.movetonext ()) {
- Return cursor.getstring (Cursor.getcolumnindex (MediaStore.MediaColumns.DATA));
- }
- Cursor.close ();
- return null;
- }
- }
What if I need to share multiple files?
Answer: Modify the Manifest.xml Android:name property of action in intent in activity
- <span style= "FONT-SIZE:14PX;" > <intent-filter>
- <!--supports multiple file sharing-
- <action android:name= "Android.intent.action.SEND_MULTIPLE"/>
- <category android:name= "Android.intent.category.DEFAULT"/>
- <!--Specify the type of sharing I can only share MP4--
- <data android:mimetype= "Video/mp4"/>
- </intent-filter> </span>
As follows:
Click to download the source code
I refer to the blog: http://blog.csdn.net/xyz_lmn/article/details/16856843
Android Common MimeType Table
One, MIME type description
Multi-purpose Internet Mail Extensions (MIME,Multipurpose Internet Mail Extensions) is an Internet standard that expands e-mail standards, Enables it to support mail messages in a variety of formats, such as non-ASCII characters, binary format attachments, and so on.
The content type (Content-type), which is used to specify the type of message. Generally appear in the following form. [Type]/[subtype]
The type has the following form.
Text: Used to standardize the representation of textual information, text messages can be a variety of character sets and or multiple formats;
Multipart: Multiple parts used to connect the body of a message form a message, which can be different types of data;
Application: Used to transfer application data or binary data;
Message: Used to package an e-mail message;
Image: Used to transfer static picture data;
Audio: Used to transmit sound or sound data;
Video: Used to transmit dynamic image data, which can be a format for audio editing together.
The subtype is used to specify the detailed form of the type. The set of Content-type/subtype pairs and the associated parameters will grow over time. To ensure that these values are developed in an orderly and public state, MIME uses the internet Assigned Numbers Authority (IANA) as the central registration mechanism to manage these values. The common subtype values are as follows:
Text/plain (plain text)
text/html (HTML document)
Application/xhtml+xml (XHTML documentation)
Image/gif (GIF image)
Image/jpeg (JPEG image) "PHP: Image/pjpeg"
Image/png (PNG image) "PHP: Image/x-png"
Video/mpeg (MPEG animation)
Application/octet-stream (arbitrary binary data)
Application/pdf (PDF document)
Application/msword (Microsoft Word file)
message/rfc822 (RFC 822 form)
Multipart/alternative (HTML e-mail and plain text form, the same content is represented in different forms)
Application/x-www-form-urlencoded (Form submitted using the Post method of HTTP)
Multipart/form-data (IBID., but mainly used when the form submission is accompanied by file upload)
Second, commonly used MIME type table
Transferred from: http://www.littledai.com/20110408/112443/791
3GP VIDEO/3GPP
AaB Application/x-authoware-bin
AAM Application/x-authoware-map
AAS Application/x-authoware-seg
Ai Application/postscript
AIF Audio/x-aiff
AIFC Audio/x-aiff
AIFF Audio/x-aiff
ALS Audio/x-alpha5
AMC Application/x-mpeg
Ani Application/octet-stream
APK application/vnd.android.package-archive
ASC Text/plain
ASD Application/astound
ASF VIDEO/X-MS-ASF
ASN Application/astound
ASP Application/x-asap
ASX video/x-ms-asf
Au audio/basic
AVB Application/octet-stream
Avi Video/x-msvideo
AWB AUDIO/AMR-WB
Bcpio Application/x-bcpio
Bin Application/octet-stream
BLD Application/bld
Bld2 Application/bld2
BMP Image/bmp
BPK Application/octet-stream
BZ2 APPLICATION/X-BZIP2
Cal Image/x-cals
CCN APPLICATION/X-CNC
CCO Application/x-cocoa
CDF APPLICATION/X-NETCDF
CGI magnus-internal/cgi
Chat Application/x-chat
Class Application/octet-stream
CLP Application/x-msclip
CMX APPLICATION/X-CMX
Co application/x-cult3d-object
Cod image/cis-cod
Cpio Application/x-cpio
CPT Application/mac-compactpro
CRD Application/x-mscardfile
CSH application/x-csh
CSM CHEMICAL/X-CSML
CSML CHEMICAL/X-CSML
CSS Text/css
Cur Application/octet-stream
DCM X-LML/X-EVM
DCR Application/x-director
DCX IMAGE/X-DCX
DHTML text/html
Dir application/x-director
DLL Application/octet-stream
DMG Application/octet-stream
DMS Application/octet-stream
Doc Application/msword
Dot Application/x-dot
DVI Application/x-dvi
DWF DRAWING/X-DWF
DWG Application/x-autocad
DXF Application/x-autocad
DXR Application/x-director
EBK Application/x-expandedbook
EMB Chemical/x-embl-dl-nucleotide
EMBL Chemical/x-embl-dl-nucleotide
EPS Application/postscript
Eri Image/x-eri
Es Audio/echospeech
ESL Audio/echospeech
Etc Application/x-earthtime
ETX Text/x-setext
EVM X-LML/X-EVM
Evy Application/x-envoy
EXE Application/octet-stream
Fh4 Image/x-freehand
Fh5 Image/x-freehand
FHC Image/x-freehand
Fif Image/fif
FM Application/x-maker
FPX IMAGE/X-FPX
FVI Video/isivideo
Gau Chemical/x-gaussian-input
GCA application/x-gca-compressed
GDB X-lml/x-gdb
GIF image/gif
GPS Application/x-gps
Gtar Application/x-gtar
GZ Application/x-gzip
HDF APPLICATION/X-HDF
HDM TEXT/X-HDML
HDML TEXT/X-HDML
HLP Application/winhlp
HQX application/mac-binhex40
HTM text/html
HTML text/html
HTS text/html
Ice X-conference/x-cooltalk
ICO Application/octet-stream
Ief Image/ief
IFM Image/gif
IFS Image/ifs
Imy Audio/melody
INS Application/x-net-install
IPs Application/x-ipscript
IPX Application/x-ipix
It Audio/x-mod
Itz Audio/x-mod
IVR I-WORLD/I-VRML
J2K image/j2k
Jad Text/vnd.sun.j2me.app-descriptor
Jam Application/x-jam
Jar Application/java-archive
JNLP Application/x-java-jnlp-file
JPE Image/jpeg
JPEG Image/jpeg
JPG Image/jpeg
Jpz Image/jpeg
JS Application/x-javascript
JWC APPLICATION/JWC
KJX APPLICATION/X-KJX
Lak X-lml/x-lak
Latex Application/x-latex
LCC Application/fastman
LCL Application/x-digitalloca
LCR Application/x-digitalloca
Lgh Application/lgh
LHA Application/octet-stream
LML X-lml/x-lml
Lmlpack X-lml/x-lmlpack
LSF video/x-ms-asf
LSX video/x-ms-asf
LZH Application/x-lzh
M13 Application/x-msmediaview
M14 Application/x-msmediaview
M15 Audio/x-mod
M3U Audio/x-mpegurl
M3url Audio/x-mpegurl
MA1 AUDIO/MA1
Ma2 Audio/ma2
MA3 AUDIO/MA3
MA5 AUDIO/MA5
Mans Application/x-troff-man
Map Magnus-internal/imagemap
MBD Application/mbedlet
MCT Application/x-mascot
MDB application/x-msaccess
Mdz Audio/x-mod
Me Application/x-troff-me
Mel Text/x-vmel
Mi application/x-mif
Mid Audio/midi
MIDI Audio/midi
MIF APPLICATION/X-MIF
Mil Image/x-cals
Mio Audio/x-mio
MMF application/x-skt-lbs
MNG video/x-mng
Mny Application/x-msmoney
MoC Application/x-mocha
Mocha Application/x-mocha
MoD Audio/x-mod
MOF Application/x-yumekara
MOL Chemical/x-mdl-molfile
Mop Chemical/x-mopac-input
MOV video/quicktime
Movie Video/x-sgi-movie
MP2 Audio/x-mpeg
MP3 Audio/x-mpeg
MP4 Video/mp4
MPC Application/vnd.mpohun.certificate
MPE Video/mpeg
MPEG Video/mpeg
MPG video/mpeg
MPG4 Video/mp4
MPGA Audio/mpeg
MPN application/vnd.mophun.application
MPP Application/vnd.ms-project
MPs Application/x-mapserver
MRL TEXT/X-MRML
MRM APPLICATION/X-MRM
Ms Application/x-troff-ms
MTS Application/metastream
MTX Application/metastream
MTZ Application/metastream
Mzv Application/metastream
NAR Application/zip
Nbmp image/nbmp
NC application/x-netcdf
NDB x-lml/x-ndb
Ndwn Application/ndwn
NIF application/x-nif
Nmz Application/x-scream
Nokia-op-logo Image/vnd.nok-oplogo-color
NPX APPLICATION/X-NETFPX
Nsnd audio/nsnd
NVA APPLICATION/X-NEVA1
ODA Application/oda
Oom Application/x-atlasmate-plugin
PAC Audio/x-pac
PAE Audio/x-epac
Pan Application/x-pan
PBM Image/x-portable-bitmap
PCX image/x-pcx
PDA IMAGE/X-PDA
PDB chemical/x-pdb
PDF Application/pdf
PFR APPLICATION/FONT-TDPFR
PGM Image/x-portable-graymap
PICT image/x-pict
PM Application/x-perl
PMD APPLICATION/X-PMD
PNG image/png
PNM Image/x-portable-anymap
PNZ Image/png
Pot Application/vnd.ms-powerpoint
PPM Image/x-portable-pixmap
PPS Application/vnd.ms-powerpoint
PPT Application/vnd.ms-powerpoint
PQF Application/x-cprplayer
PQI Application/cprplayer
PRC APPLICATION/X-PRC
Proxy Application/x-ns-proxy-autoconfig
PS Application/postscript
Ptlk Application/listenup
Pub Application/x-mspublisher
PVX VIDEO/X-PV-PVX
QCP Audio/vnd.qcelp
QT Video/quicktime
Qti Image/x-quicktime
Qtif Image/x-quicktime
R3T Text/vnd.rn-realtext3d
RA Audio/x-pn-realaudio
Ram Audio/x-pn-realaudio
RAR application/x-rar-compressed
RAS Image/x-cmu-raster
RDF Application/rdf+xml
RF Image/vnd.rn-realflash
RGB Image/x-rgb
Rlf Application/x-richlink
RM Audio/x-pn-realaudio
RMF AUDIO/X-RMF
RMM Audio/x-pn-realaudio
RMVB Audio/x-pn-realaudio
RNX Application/vnd.rn-realplayer
Roff Application/x-troff
RP Image/vnd.rn-realpix
RPM Audio/x-pn-realaudio-plugin
RT Text/vnd.rn-realtext
RTE X-lml/x-gps
RTF Application/rtf
RTG Application/metastream
RTX Text/richtext
RV Video/vnd.rn-realvideo
RWC Application/x-rogerwilco
S3m Audio/x-mod
s3z Audio/x-mod
SCA Application/x-supercard
SCD Application/x-msschedule
SDF Application/e-score
Sea Application/x-stuffit
SGM TEXT/X-SGML
SGML TEXT/X-SGML
SH application/x-sh
Shar Application/x-shar
sHTML magnus-internal/parsed-html
SHW application/presentations
Si6 Image/si6
Si7 image/vnd.stiwap.sis
Si9 image/vnd.lgtwap.sis
SIS Application/vnd.symbian.install
Sit application/x-stuffit
SKD Application/x-koan
SKM Application/x-koan
SKP Application/x-koan
Skt Application/x-koan
SLC Application/x-salsa
SMD AUDIO/X-SMD
SMI Application/smil
SMIL Application/smil
SMP Application/studiom
SMZ AUDIO/X-SMD
SND Audio/basic
SPC Text/x-speech
SPL Application/futuresplash
SPR Application/x-sprite
Sprite Application/x-sprite
SPT APPLICATION/X-SPT
SRC Application/x-wais-source
STK Application/hyperstudio
STM Audio/x-mod
Sv4cpio Application/x-sv4cpio
SV4CRC APPLICATION/X-SV4CRC
SVF IMAGE/VND
SVG image/svg-xml
SVH IMAGE/SVH
SVR X-world/x-svr
SWF Application/x-shockwave-flash
SWFL Application/x-shockwave-flash
T Application/x-troff
Tad Application/octet-stream
Talk Text/x-speech
Tar Application/x-tar
Taz Application/x-tar
TBP application/x-timbuktu
TBT Application/x-timbuktu
Tcl APPLICATION/X-TCL
Tex Application/x-tex
Texi Application/x-texinfo
Texinfo Application/x-texinfo
Tgz Application/x-tar
tHM Application/vnd.eri.thm
TIF Image/tiff
TIFF Image/tiff
Tki application/x-tkined
tkined application/x-tkined
TOC Application/toc
Toy Image/toy
TR Application/x-troff
TRK X-lml/x-gps
TRM Application/x-msterminal
TSI Audio/tsplayer
TSP application/dsptype
TSV Text/tab-separated-values
TSV Text/tab-separated-values
TTF Application/octet-stream
Ttz Application/t-time
TXT Text/plain
Ult Audio/x-mod
Ustar Application/x-ustar
UU Application/x-uuencode
Uue Application/x-uuencode
VCD Application/x-cdlink
VCF Text/x-vcard
VDO VIDEO/VDO
Vib Audio/vib
Viv Video/vivo
Vivo Video/vivo
VMD Application/vocaltec-media-desc
VMF Application/vocaltec-media-file
VMI Application/x-dreamcast-vms-info
VMS Application/x-dreamcast-vms
Vox Audio/voxware
VQE Audio/x-twinvq-plugin
VQF AUDIO/X-TWINVQ
VQL AUDIO/X-TWINVQ
VRE X-world/x-vream
VRML X-WORLD/X-VRML
VRT X-WORLD/X-VRT
VRW X-world/x-vream
VTS Workbook/formulaone
WAV Audio/x-wav
Wax Audio/x-ms-wax
Wbmp image/vnd.wap.wbmp
Web Application/vnd.xara
WI image/wavelet
WIS Application/x-installshield
WM VIDEO/X-MS-WM
WMA audio/x-ms-wma
WMD APPLICATION/X-MS-WMD
WMF Application/x-msmetafile
WML TEXT/VND.WAP.WML
WMLC APPLICATION/VND.WAP.WMLC
WMLS Text/vnd.wap.wmlscript
WMLSC APPLICATION/VND.WAP.WMLSCRIPTC
WMLScript Text/vnd.wap.wmlscript
WMV audio/x-ms-wmv
WMX VIDEO/X-MS-WMX
WMZ APPLICATION/X-MS-WMZ
Wpng Image/x-up-wpng
WPT X-lml/x-gps
WRI Application/x-mswrite
WRL X-WORLD/X-VRML
Wrz X-WORLD/X-VRML
WS Text/vnd.wap.wmlscript
WSC APPLICATION/VND.WAP.WMLSCRIPTC
WV Video/wavelet
WVX VIDEO/X-MS-WVX
WXL APPLICATION/X-WXL
X-gzip Application/x-gzip
Xar Application/vnd.xara
XBM Image/x-xbitmap
XDm APPLICATION/X-XDMA
XDMA APPLICATION/X-XDMA
XDW Application/vnd.fujixerox.docuworks
Xht Application/xhtml+xml
Xhtm Application/xhtml+xml
XHTML Application/xhtml+xml
XLA application/vnd.ms-excel
XLC Application/vnd.ms-excel
XLL Application/x-excel
XLM application/vnd.ms-excel
XLS application/vnd.ms-excel
XLT Application/vnd.ms-excel
XLW Application/vnd.ms-excel
XM Audio/x-mod
XML Text/xml
Xmz Audio/x-mod
XPI Application/x-xpinstall
XPM Image/x-xpixmap
Xsit Text/xml
XSL Text/xml
XUL Text/xul
XWD Image/x-xwindowdump
XYZ chemical/x-pdb
YZ1 APPLICATION/X-YZ1
Z application/x-compress
Zac Application/x-zaurus-zac
Zip Application/zip
System "Share" interface for Android applications