标签:android des style http java 使用 os 文件
首先,请下载插件包。 
http://pan.baidu.com/s/1gdejb9L
第一步:将src下的文件拷贝到你的项目src目录下,打开WeiXin.java文件,在大约28行处你可以看到代码:
import com.example.weixin.R;
把这里的包名修改为你自己的包名。
第二步:把wxapi文件夹拷贝至你自己的包下面。该文件夹下的WXEntryActivity.java文件是用来接收微信的回调信息的。打开后大约35行处,设置你在微信申请的appID。(请参考微信开放平台的相关内容) 
现在,你需要在AndroidManifest..xml文件的Application标签中添加以下内容:
<activity
        android:name=".wxapi.WXEntryActivity"
        android:label="@string/app_name"
        android:exported="true"
        android:theme="@android:style/Theme.NoDisplay"
        >
        <!--
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="sdksample"/>
        </intent-filter>
        -->
    </activity> 
第三步:把libs文件夹下的libammsdk.jar拷贝至你的项目libs文件夹下,并添加至build path。(若不知如何操作,请参阅百度)
第四步:打开res->xml->config.xml文件,在末尾处添加下面的配置信息:
<feature name="WeiXin">
    <param name="android-package" value="com.phonegap.plugins.weixin.WeiXin" />
</feature> 
第五步:把icon文件夹下的图标拷贝至res->drawable文件夹中,这几个图标在实际中作为默认图标使用,不是必须的,但为了避免java程序报错,需要加上。
第六步:把assets->www目录下的weixin.js文件拷贝至你的网页目录下,然后在cordova_plugins.js文件中module.exports数组中增加以下配置信息:
{
    "file": "js/lib/weixin.js", //注意这里的路径修改为你的weixin.js所在的位置
    "id": "com.phonegap.plugins.weixin.WeiXin",
    "clobbers": [
        "navigator.weixin"
    ]
} 
好了,这样应该就安装成功了,非常繁琐,期待以后改进安装方法吧。_
在上面的安装中提到过申请微信的appID,这一步很重要,在申请appID的过程中,需要注意正确填写包名和签名,任何一项信息的出错都会导致不能正常使用微信分享功能。(如有疑问,可以参阅百度中的相关资料)
首先,需要注册app:
navigator.weixin.register(appId, Success, Fail);
这里需要输入你的appID,Success为执行成功的回调,Fail为失败的回调
打开微信:
navigator.weixin.openWeixin(Success, Fail);
Success为执行成功的回调,Fail为失败的回调
发送信息到微信:
navigator.weixin.send(args, Success, Fail);
args为json格式的配置信息,Success为执行成功的回调,Fail为失败的回调
args的详细配置:
发送文字:
{
    type: ‘text‘,
    text: ‘I want to send text‘,
    isSendToTimeline: true  //if true, send to "朋友圈", else send to WeiXin friends.
} 
发送图片:
{type: ‘image‘,
imageType: ‘path‘,//you can also use ‘url‘ to send image.
data: ‘/test.png‘,//SD card path or Url
isSendToTimeline: true} 
发送音乐:
{type: ‘music‘,
url: ‘http://x.x.x/test.mp3‘,
title: ‘title‘,
desc: ‘desc‘,
isLowBand: true,//WeiXin will use different API when mobile in low band environment. default false
imgUrl: ‘http://www.baidu.com/img/bdlogo.gif‘,//if not defined, use ‘res/drawable/music.png‘
isSendToTimeline: true} 
发送视频:
{type: ‘video‘,
url: ‘http://x.x.x.swf‘,
title: ‘title‘,
desc: ‘desc‘,
isLowBand: true,
imgUrl: ‘http://www.baidu.com/img/bdlogo.gif‘,//if not defined, use ‘res/drawable/video.png‘
isSendToTimeline: true} 
发送网页:
{type: ‘webpage‘,
url: ‘http://www.baidu.com‘,
title: ‘title‘,
desc: ‘desc‘,
imgUrl: ‘http://www.baidu.com/img/bdlogo.gif‘,//if not defined, use ‘res/drawable/webpage.png‘
isSendToTimeline: true} 
发送文件:
{type: ‘file‘,
path: ‘file:///test.mp3‘,//file‘s fullPath
desc: ‘我在发本地文件‘,
title: ‘文件‘,
imgUrl: ‘http://www.baidu.com/img/bdlogo.gif‘,//if not defined, use ‘res/drawable/file.png‘
isSendToTimeline: true} 
另外还有两个api:
取消注册app:
navigator.weixin.unregister(Success, Fail);
不知道有什么用?
提示信息:
navigator.weixin.showToast(txt);
显示一段原生app的提示信息,可以尝试一下,比alert要美观的多。
任何问题,欢迎给我留言,定仔细回复!
phonegap分享到微信插件(安卓版),布布扣,bubuko.com
标签:android des style http java 使用 os 文件
原文地址:http://my.oschina.net/crazymus/blog/296725