注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

通过Intent对象打开任意文件  

2016-12-31 20:23:19|  分类: B.基础 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |



Code:
'Open Any File
Sub Btn_Example_Click
        
    
If edt_file.Text = "" Then
        
ToastMessageShow("None Document"True)
    
Else
        
Dim allegato As String = "http://www.devil-app.eu/xxx/fotoutenti/" & edt_file.Text
        
Dim job As HttpJob
        job.Initialize(
"allegato", Me)
        job.Download(allegato)        
    
End If

End Sub

Code:
Sub JobDone(Job As HttpJob)
    
If Job.Success Then
    
Dim res As String
    res = Job.GetString
    
Log("Response from server: " & res)
  
        
Select Job.JobName
      


       
Case "allegato"
         
    
'Get extension File
    Dim splitta() As String = Regex.Split("\.", edt_file.Text)
    
Dim estensione As String = splitta(1)
  
                
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "document." & estensione, False)
            
File.Copy2(Job.GetInputStream, out)
            out.Close 
'<------ very important
            Dim apro As Int
            apro = 
Msgbox2("Do you want Open Document in attachment ?""Message""Yes","","No"Null)
            
If apro = DialogResponse.POSITIVE Then
                
Dim i As Intent
                i.Initialize(i.ACTION_VIEW, 
"file://" & File.Combine(File.DirRootExternal & "/""document."& estensione))
                i.SetComponent(
"android/com.android.internal.app.ResolverActivity")
                
Select estensione
                    
Case "pdf"
                        i.SetType(
"application/pdf")
                    
Case "docx"
                        i.SetType(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document")
                        
'i.SetType("application/msword")
                    Case "txt"
                        i.SetType(
"text/plain")
                    
Case "jpg"
                        i.SetType(
"image/jpg")
                    
Case "jpeg"
                    i.SetType(
"image/jpeg")  
                
End Select
              
                
StartActivity(i)
      
            
End If

        
End Select
    
Else
        
ToastMessageShow("Error: " & Job.ErrorMessage , True)
    
End If
    Job.Release
    
ProgressDialogHide
End Sub


常见的MIME类型文件
Table 1. Common MIME types
Suffixes applicableMedia type and subtype(s)
.au --> audio/basic
.avi -->video/msvideo, video/avi, video/x-msvideo
.bmp -->image/bmp
.bz2 -->application/x-bzip2
.css -->text/css
.dtd -->application/xml-dtd
.doc -->application/msword
.docx -->application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx -->application/vnd.openxmlformats-officedocument.wordprocessingml.template
.es -->application/ecmascript
.exe -->application/octet-stream
.gif -->image/gif
.gz -->application/x-gzip
.hqx -->application/mac-binhex40
.html -->text/html
.jar -->application/java-archive
.jpg -->image/jpeg
.js -->application/x-javascript
.midi -->audio/x-midi
.mp3 -->audio/mpeg
.mpeg -->video/mpeg
.ogg -->audio/vorbis, application/ogg
.pdf -->application/pdf
.pl -->application/x-perl
.png -->image/png
.potx -->application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx -->application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppt -->application/vnd.ms-powerpointtd>
.pptx -->application/vnd.openxmlformats-officedocument.presentationml.presentation
.psv -->application/postscript
.qt -->video/quicktime
.ra-->audio/x-pn-realaudio, audio/vnd.rn-realaudio
.ram-->audio/x-pn-realaudio, audio/vnd.rn-realaudio
.rdf-->application/rdf, application/rdf+xml
.rtf-->application/rtf
.sgml-->text/sgml
.sit-->application/x-stuffit
.sldx-->application/vnd.openxmlformats-officedocument.presentationml.slide
.svg-->image/svg+xml
.swf-->application/x-shockwave-flash
.tar.gz-->application/x-tar
.tgz-->application/x-tar
.tiff-->image/tiff
.tsv-->text/tab-separated-values
.txt-->text/plain
.wav-->audio/wav, audio/x-wav
.xlam-->application/vnd.ms-excel.addin.macroEnabled.12
.xls-->application/vnd.ms-excel
.xlsb-->application/vnd.ms-excel.sheet.binary.macroEnabled.12
.xlsx-->application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx-->application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xml-->application/xml
.zip --> application/zip, application/x-compressed-zip
  评论这张
 
阅读(72)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017