`
897371388
  • 浏览: 530923 次
文章分类
社区版块
存档分类
最新评论

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.setType("image/*");
		intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
		startActivity(intent);
	}




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics