当前位置: 移动技术网 > IT编程>移动开发>Android > Android编程实现微信分享信息的方法

Android编程实现微信分享信息的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

重生之荣华富贵,每当我走过老师窗前合唱,行尸走肉下载

本文实例讲述了android编程实现微信分享信息的方法。分享给大家供大家参考,具体如下:

随着微信越来越火,越来越多的应用要求有分享到微信的功能。虽然有很多平台都帮集成有分享功能,比如友盟。但是个人觉得友盟集成的东西太多了,自己封装得太过分了,很多资源文件也要带进去,所以感觉不是怎么好,所以自己也研究了一下微信的调用其sdk分享。下面说说步骤。

第一:下载官方的sdk demo。

下载地址:http://open.weixin.qq.com/download/?lang=zh_cn

第二:解压,并将工程导入到eclipse

解压出来的时候,发现根目录下有一个debug.keystore文件,这个文件很关键的哦。
然后我们运行看看,你会发现分享根本就不成功,是微信原因吗,当然不是。

第三:在上面说到项目的根目录下有一个debug.keystore文件,因为我们编译、签名apk的时候,用的是我们自带的那个debug.keystore,每台电脑都是不一样的签名文件,而且微信那个app_id已经签名文件debug.keystore绑定了的,所以为什么我们直接运行时候是不成功的。

解决方法就是将微信的那个debug.keystore拷贝到我们电脑默认的那个debug.keystore位置,将其覆盖(建议先备份)。

在window系统,这个签名文件在c:\用户\你的用户名\.android目录下(注意.android文件夹默认是隐藏的)。

再次运行,分享就成功了。

如果是我们的应用,将app_id替换成我们在官网上面申请的app_id就行了。

其实我们分享信息到微信,还有一种更简单的方法,不用其提供的sdk api,直接调用微信相关的activity,这样更加省事,例如:

/** 
* 分享信息到朋友 
* 
* @param file,假如图片的路径为path,那么file = new file(path); 
*/ 
private void sharetofriend(file file) { 
    intent intent = new intent(); 
    componentname componentname = new componentname("com.tencent.mm", "com.tencent.mm.ui.tools.shareimgui"); 
    intent.setcomponent(componentname); 
    intent.setaction(intent.action_send); 
    intent.settype("image/*"); 
    intent.putextra(intent.extra_text, "测试微信"); 
    intent.putextra(intent.extra_stream, uri.fromfile(file)); 
    startactivity(intent); 
}
/** 
* 分享信息到朋友圈 
* 
* @param file,假如图片的路径为path,那么file = new file(path); 
*/ 
private void sharetotimeline(file file) { 
    intent intent = new intent(); 
    componentname componentname = new componentname("com.tencent.mm", "com.tencent.mm.ui.tools.sharetotimelineui"); 
    intent.setcomponent(componentname); 
    intent.setaction(intent.action_send); 
    intent.putextra(intent.extra_stream, uri.fromfile(file)); 
//   intent.setaction(android.content.intent.action_send_multiple); 
//   arraylist<uri> uris = new arraylist<uri>(); 
//   for (int i = 0; i < images.size(); i++) { 
//     uri data = uri.fromfile(new file(thumbpaths.get(i))); 
//     uris.add(data); 
//   } 
//   intent.putparcelablearraylistextra(intent.extra_stream, uris); 
    intent.settype("image/*"); 
    startactivity(intent); 
} 

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网