微信Android SDK示例代码及运行方法

最近在研究微信SDK,无奈网上好使的教程太少,对于程序员来说最好的东西,一个是微信的开发文档,一个是微信SDK的范例代码。无奈文档小白很难看懂,范例代码又没有详细的解释,导致我折腾了好多天,现在有点眉目了,先记下来。


转载请注明来自:http://blog.youkuaiyun.com/icyfox_bupt/article/details/23742217

 

1、申请应用AppKey

微信的SDK要求应用的包名、签名的MD5、AppID严格对应,所以没有申请的应用是肯定无法使用的。申请了的应用如果这三个对不上,是无法使用的。

·包名,是应用建立时候的名称,你可以在AndroidManifest.xml文件的package项中找到

·签名的MD5,这个比较复杂,如果你不了解Android的签名发布机制请看签名。一般开发者在发布应用的时候都会有一个自己的签名来认证应用,获取这个签名的MD5值,需要用到腾讯的MD5获取工具,手机上安装后,输入自己程序的包名,会出现程序的签名MD5信息,复制下来,如下图:

 

 

·获取这些信息后进入微信开放平台(https://open.weixin.qq.com),注册登录。

·管理平台--创建移动应用

·第一步:填写基本信息,填上应用信息即可,不再赘述。

·第二步:填写平台信息,选中Android。填写上正确的应用包名和应用签名,如下图:

 

·第三步,提交审核并等待,在“未通过审核”页面中可以查看:

 

 

审核通过后,应用会出现在“已通过审核”分类里。进入应用可以看到微信的AppID,记住它:

 

2、使用范例代码

 
对于我这种水平的人来说看Android文档真的是太痛苦了,学习功能最简单的方法还是看范例代码,微信的范例代码其实做的很好,下面来看如何使用:
 
首先在微信开放平台的资源中心下载 微信SDK范例代码,下载完成后加入Eclipse工程。
在项目的压缩包中可以看到一个 debug.keystore文件,这个就是范例代码使用的签名。
在项目的Constants.java中有如下代码:
 
[java]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. public class Constants {  
  2.     // APP_ID 替换为你的应用从官方网站申请到的合法appId  
  3.     public static final String APP_ID = "wxd930ea5d5a258f4f";  
上面的APP_ID就是这个签名,在通过审核以后的APPID。我们什么都不需要更改。
 
打包APK:
 
使用debug.keystore对程序进行签名,操作流程:
·右键项目 ----> Android Tools ----> Export Signed Application Package.
·Use existing keystore ---> Location填写debug.keystore的地址,密码填写 android,下一步密码继续填写android --> finish。
·完成
 
 

3、功能展示

 
将打包好的“ 微信范例”程序安装到手机上,就可以测试分享的各项功能了:
 

1、分享文字

分享文字的功能和我们用微信发出去的效果差不多,不过多了个小尾巴,在这里小尾巴是“段总特别帅的APP”, 好吧谁能告诉我这个段总是谁?
 

 

2、分享网页

微信里分享网页其实挺麻烦的,有了SDK就会方便很多了。SDK会给出默认的一个对话框,用户可以对网页进行评论,如下图:
 
 
 
 
 
 
 

3、发送APP消息

与分享文字图片视频链接 不同,发送APP消息允许回调到我们自己的APP。
发送APP信息后,看起来和发送链接没有什么不同,除了边上的那个小箭头:
 
 
但是点击后不是打开浏览器,而是跳回我们的程序,如果没有安装这个APP,就会跳转到我们审核程序时填写的 程序下载地址。非常赞
 
 
我现在遇到的问题:
1、目前APP消息只能在和用户的会话中使用,无法发送到朋友圈,我想应该是微信的限制吧?
2、上面的图中,点击“段总特别帅的APP”,可以实现跳转,但是我的APP、还有网易新闻的APP,分享后那个按钮都不好使。
有人做出来了请务必告诉我~~!
List of Sample Apps The list below provides a summary of the sample applications that are available with the Android SDK. Using the links on this page, you can view the source files of the sample applications in your browser. You can also download the source of these samples into your SDK, then modify and reuse it as you need. For more information, see Getting the Samples. API Demos A variety of small applications that demonstrate an extensive collection of framework topics. Backup and Restore A simple example that illustrates a few different ways for an application to implement support for the Android data backup and restore mechanism. Bluetooth Chat An application for two-way text messaging over Bluetooth. BusinessCard An application that demonstrates how to launch the built-in contact picker from within an activity. This sample also uses reflection to ensure that the correct version of the contacts API is used, depending on which API level the application is running under. Contact Manager An application that demonstrates how to query the system contacts provider using the ContactsContract API, as well as insert contacts into a specific account. Home A home screen replacement application. JetBoy A game that demonstrates the SONiVOX JET interactive music technology, with JetPlayer. Live Wallpaper An application that demonstrates how to create a live wallpaper and bundle it in an application that users can install on their devices. Lunar Lander A classic Lunar Lander game. Multiple Resolutions A sample application that shows how to use resource directory qualifiers to provide different resources for different screen configurations. Note Pad An application for saving notes. Similar (but not identical) to the Notepad tutorial. SampleSyncAdapter Demonstrates how an application can communicate with a cloud-based service and synchronize its data with data stored locally in a content provider. The sample uses two related parts of the Android framework — the account manager and the synchronization manager (through a sync adapter). Searchable Dictionary A sample application that demonstrates Android's search framework, including how to provide search suggestions for Quick Search Box. Snake An implementation of the classic game "Snake." Soft Keyboard An example of writing an input method for a software keyboard. Spinner A simple application that serves as an application-under-test for the SpinnerTest sample application. SpinnerTest An example test application that contains test cases run against the Spinner sample application. To learn more about the application and how to run it, please read the Activity Testing tutorial. TicTacToeLib An example of an Android library project that provides a game-play Activity to any dependent application project. For an example of how an application can use the code and resources in an Android library project, see the TicTacToeMain sample application. TicTacToeMain An example of an Android application that makes use of code and resources provided in an Android library project. Specifically, this application uses code and resources provided in the TicTacToeLib library project. Wiktionary An example of creating interactive widgets for display on the Android home screen. Wiktionary (Simplified) A simple Android home screen widgets example.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值