分享文字和图片到微博、微信等公众平台遇到的问题
来源:互联网 发布:最好的英汉翻译软件 编辑:程序博客网 时间:2024/05/16 06:05
看了网上关于分享的解决方法,现在总结一下。
文字很简单,通过intent进行参数传递就行。
图片需要序列化才能分享,这里intent是通过Uri.fromFile(new File())来实现序列化。
public void shareScore(Activity context) { String content = "本次得分" + myScore; PictureUtil.savePic(context, PictureUtil.takeScreenShot(context), gameShareName); File file = context.getFileStreamPath(gameShareName); Uri uri = Uri.fromFile(file); Intent shareIntent = new Intent(Intent.ACTION_SEND); if (uri != null) { shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/*"); } else { shareIntent.setType("text/plain"); } shareIntent.putExtra(Intent.EXTRA_TEXT, content); context.startActivity(shareIntent); }
public static boolean savePic(Activity context, Bitmap b, String filename) { FileOutputStream fos = null; try { fos = ((Activity) context).openFileOutput(filename, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); if (null != fos) { b.compress(Bitmap.CompressFormat.PNG, 90, fos); try { fos.flush(); fos.close(); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
/** * 进行截取屏幕 * * @param pActivity * @return bitmap */ public static Bitmap takeScreenShot(Activity pActivity) { View view = pActivity.getWindow().getDecorView(); Rect frame = new Rect(); view.getWindowVisibleDisplayFrame(frame); int stautsHeight = frame.top; int width = pActivity.getWindowManager().getDefaultDisplay().getWidth(); int height = pActivity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height - stautsHeight, Bitmap.Config.ARGB_8888); view.draw(new Canvas(bitmap)); return bitmap; }
通过以上方法能实现对屏幕截图的图片和文字分享。分享过程中遇到的问题:
1.文件读取权限的问题,如果存储文件到SD卡上,报错出现java.io.IOException: Permission denied。 该问题出现的可能是:
1)没有设置user权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission><uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
2)文件路径错误:应该在Environment.getExternalStorageDirectory()路径下读写文件。
3)真机开发的。。。,在调试过程中SD卡禁止访问,需要与电脑断开USB连接后,SD卡正常插入后读写文件。
2.分享照片时,需要Uri生成的序列化数据,才能正常分享:
Uri uri = Uri.fromFile(file);
3.公共平台是否支持相关的文字图片同事分享的接口。。
0 0
- 分享文字和图片到微博、微信等公众平台遇到的问题
- 关于第三方应用(Android平台)通过微信分享文字、图片的问题研究。
- 关于android微信QQ等平台分享功能实现中遇到的问题处理
- 微信硬件平台设备直连全讲解(4)接收和回复微信客户端的文字、图片等信息
- 微信公众平台分享
- 微信公众平台开发之分享问题总结
- 基于微信公众平台开发过程中遇到的问题及解决方案
- 微信公众平台开发遇到的问题记录.不定时更新.
- 在微信扫描二维码登录网站和微信授权登录公众平台的WAP网站中遇到的问题
- 微信公众平台开发-分享接口的实现
- java微信公众平台分享朋友圈
- 微信公众号开发之图片,音乐等文件出现该公众号无法提供服务的问题
- 微信分享多个图片和文字到朋友圈
- 微信公众平台和开放平台的区别
- 微信开放平台和公众平台的区别
- 微信开放平台和公众平台的区别?
- 微信开放平台和公众平台的区别?
- 微信公众号开发中遇到的问题——支付回调,分享,获取openId(三)
- 学习网站
- Theme.Holo.Light Activity上端灰线问题
- struts2系列十三之resulttype的四种类型
- lsof命令
- eclipse的项目分组功能
- 分享文字和图片到微博、微信等公众平台遇到的问题
- 外部中断设计实验
- 谈谈C# 4.0新特性“缺省参数”的实现
- java泛型接口详解
- 定时器/计数器设计实验
- 音视频优秀博客链接
- 关于javascript浮点数计算
- Lucene异常:org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
- 中英文切换