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

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

一些文本图片分享的代码片断  

2015-12-06 16:55:54|  分类: QQ微信分享 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
我从这篇文章中使用以下代码 http://www.basic4ppc.com/android/forum/threads/share-bitmap-question-how-to.11638/ 
代码:
Dim r As Reflector
  Dim f As Object
  f = r.CreateObject2("java.io.File", Array As Object("file:///sdcard/1.jpg"), Array As String("java.lang.String"))
  Dim share As Intent
  share.Initialize(share.ACTION_SEND,"")
  share.SetType("image/jpeg")
  share.PutExtra("android.intent.extra.STREAM", r.RunStaticMethod("android.net.Uri", "fromFile", _
      Array As Object(f), Array As String("java.io.File")))
  share.WrapAsIntentChooser("Share Photo:)")
  StartActivity(share)



http://www.b4x.com/android/forum/threads/how-to-share-image-using-intent.30976/

dim share as intent
share.Initialize(share.ACTION_SEND,"")
share.SetType("text/plain")
share.PutExtra("android.intent.extra.TEXT", mytext)
share.WrapAsIntentChooser("Share text via")
StartActivity(share)


,基本上我想分享一个图像到twitter和facebook /社交媒体 

我尝试了很多教程在这里但没有工作. . 最近的一个是这样的: 
代码:
Dim r As Reflector
Dim f As Object
f = r.CreateObject2("java.io.File", Array As Object("file:///sdcard/spectacle.pdf"), Array As String("java.lang.String"))
Dim share As Intent
share.Initialize(share.ACTION_SEND,"")
share.SetType("*/*")
share.PutExtra("android.intent.extra.STREAM", r.RunStaticMethod("android.net.Uri", "fromFile", _
    Array As Object(f), Array As String("java.io.File")))
share.WrapAsIntentChooser("Share PDF:)")
StartActivity(share)
因为如果我试试这个使用: 

代码:
Dim r As Reflector
Dim f As Object
f = r.CreateObject2("java.io.File", Array As Object("file:///sdcard/spectacle.jpg"), Array As String("java.lang.String"))
Dim share As Intent
share.Initialize(share.ACTION_SEND,"")
share.SetType("image/*")
share.PutExtra("android.intent.extra.STREAM", r.RunStaticMethod("android.net.Uri", "fromFile", _
    Array As Object(f), Array As String("java.io.File")))
share.WrapAsIntentChooser("Share JPG:)")
StartActivity(share)



http://www.b4x.com/android/forum/threads/share-bitmap-question-how-to.11638/

我知道如何共享一个文本: 

代码:
mytext = "some text"

Sub share_Click

   share.Initialize(share.ACTION_SEND,"")
   share.SetType("text/plain")
   share.PutExtra("android.intent.extra.TEXT", mytext)
   share.WrapAsIntentChooser("Share text:)")
   StartActivity(share)
   
End Sub
但是我可以分享一个位图。 我有尝试: 
代码:
Sub share_Click

   share.Initialize(share.ACTION_SEND,"")
   share.SetType("image/jpeg")
   share.PutExtra("android.intent.extra.stream", mypicture)
   share.WrapAsIntentChooser("Share Photo:)")
   StartActivity(share)
   
End Sub




这段代码使用Gmail: 
代码:
Dim r As Reflector
   Dim f As Object
   f = r.CreateObject2("java.io.File", Array As Object("file:///sdcard/1.jpg"), Array As String("java.lang.String"))
   Dim share As Intent
   share.Initialize(share.ACTION_SEND,"")
   share.SetType("image/jpeg")
   share.PutExtra("android.intent.extra.STREAM", r.RunStaticMethod("android.net.Uri", "fromFile", _
      Array As Object(f), Array As String("java.io.File")))
   share.WrapAsIntentChooser("Share Photo:)")
   StartActivity(share)


在这里: 
代码:
Sub Activity_Create(FirstTime As Boolean)
   ShareMultipleImages(Array As String(File.Combine(File.DirRootExternal, "bitmap.png"), _
     File.Combine(File.DirRootExternal, "1.jpg")))
End Sub

Sub ShareMultipleImages(files As List)
   Dim i As Intent
   i.Initialize("android.intent.action.SEND_MULTIPLE", "")
   i.SetType("image/jpeg")
   Dim Uris As List
   Uris.Initialize
   For Each f As String In files
     Dim u As Uri
     u.Parse("file://" & f)
     Uris.Add(u)
   Next
   Dim jo As JavaObject = i
   jo.RunMethod("putParcelableArrayListExtra", Array As Object("android.intent.extra.STREAM", Uris))
   StartActivity(i)
End Sub
取决于JavaObject和ContentResolver库。


Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.SetType("*/*")
i.PutExtra("android.intent.extra.TEXT", "This is the text")
Dim u As Uri
u.Parse("file://" & File.Combine(File.DirRootExternal, "1.jpg")) '<-- change to a valid image file
i.PutExtra("android.intent.extra.STREAM", u)


http://www.b4x.com/android/forum/threads/uri-content-media-to-real-file.13473/#post-76176


  评论这张
 
阅读(27)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

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

页脚

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