Skip to content

Commit df5ed65

Browse files
committed
新增微信sdk插件demo
1 parent 24cbf69 commit df5ed65

File tree

11 files changed

+183
-1
lines changed

11 files changed

+183
-1
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include 'PluginCore', 'PluginShareLib'
22
include 'PluginMain'
3-
include ':PluginTest', ':PluginHelloWorld', ':PluginBase'
3+
include ':PluginTest', ':PluginHelloWorld', ':PluginBase', ':wxsdklibrary'

wxsdklibrary/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

wxsdklibrary/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "22.0.1"
6+
7+
defaultConfig {
8+
minSdkVersion 14
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
}

wxsdklibrary/libs/libammsdk.jar

151 KB
Binary file not shown.

wxsdklibrary/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/cailiming/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.wxsdklibrary"
3+
android:versionCode="1"
4+
android:versionName="1.0.1"
5+
android:sharedUserId="com.example.pluginmain">
6+
7+
<application
8+
android:allowBackup="true"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true">
11+
12+
<activity
13+
android:name="com.example.wxsdklibrary.TestSendToWXActivity">
14+
</activity>
15+
16+
<activity
17+
android:name="com.example.pluginmain.wxapi.WXEntryActivity"/>
18+
19+
</application>
20+
21+
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.example.pluginmain.wxapi;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.widget.Toast;
7+
8+
import com.tencent.mm.sdk.openapi.BaseReq;
9+
import com.tencent.mm.sdk.openapi.BaseResp;
10+
import com.tencent.mm.sdk.openapi.IWXAPI;
11+
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
12+
import com.tencent.mm.sdk.openapi.WXAPIFactory;
13+
14+
public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
15+
16+
public static final String APP_ID = "wx8ce466b2fc952d31";
17+
18+
private IWXAPI api;
19+
20+
@Override
21+
public void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
api = WXAPIFactory.createWXAPI(this, APP_ID, false);
24+
api.handleIntent(getIntent(), this);
25+
}
26+
27+
@Override
28+
protected void onNewIntent(Intent intent) {
29+
super.onNewIntent(intent);
30+
setIntent(intent);
31+
api.handleIntent(intent, this);
32+
}
33+
34+
@Override
35+
public void onReq(BaseReq baseReq) {
36+
//nothing
37+
}
38+
39+
@Override
40+
public void onResp(BaseResp resp) {
41+
String result = "";
42+
43+
switch (resp.errCode) {
44+
case BaseResp.ErrCode.ERR_OK:
45+
result = "发送成功";
46+
break;
47+
case BaseResp.ErrCode.ERR_USER_CANCEL:
48+
result = "发送取消";
49+
break;
50+
case BaseResp.ErrCode.ERR_AUTH_DENIED:
51+
result = "发送被拒绝";
52+
break;
53+
default:
54+
result = "发送返回";
55+
break;
56+
}
57+
58+
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
59+
60+
finish();
61+
}
62+
63+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.example.wxsdklibrary;
2+
3+
4+
import android.app.Activity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Button;
8+
9+
import com.example.pluginmain.wxapi.WXEntryActivity;
10+
import com.tencent.mm.sdk.openapi.IWXAPI;
11+
import com.tencent.mm.sdk.openapi.SendMessageToWX;
12+
import com.tencent.mm.sdk.openapi.WXAPIFactory;
13+
import com.tencent.mm.sdk.openapi.WXMediaMessage;
14+
import com.tencent.mm.sdk.openapi.WXTextObject;
15+
16+
public class TestSendToWXActivity extends Activity {
17+
18+
private IWXAPI api;
19+
20+
@Override
21+
public void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
api = WXAPIFactory.createWXAPI(this, WXEntryActivity.APP_ID, false);
24+
api.registerApp(WXEntryActivity.APP_ID);
25+
26+
Button btn = new Button(this);
27+
btn.setText("点击发送信息到微信");
28+
setContentView(btn);
29+
30+
btn.setOnClickListener(new View.OnClickListener() {
31+
32+
@Override
33+
public void onClick(View v) {
34+
WXTextObject textObj = new WXTextObject();
35+
textObj.text = "呵呵更健康";
36+
37+
WXMediaMessage msg = new WXMediaMessage();
38+
msg.mediaObject = textObj;
39+
msg.title = "Will be ignored";
40+
msg.description = "呵呵更健康";
41+
42+
SendMessageToWX.Req req = new SendMessageToWX.Req();
43+
req.transaction = "呵呵更健康" + String.valueOf(System.currentTimeMillis());
44+
req.message = msg;
45+
req.scene = SendMessageToWX.Req.WXSceneSession;//发送给某人
46+
47+
api.sendReq(req);
48+
}
49+
});
50+
}
51+
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">WxSdkLibrary</string>
3+
</resources>

0 commit comments

Comments
 (0)