Skip to content

Commit 69027ea

Browse files
author
李宾
committed
微信分享,等待正式app_id
1 parent 1b1f681 commit 69027ea

File tree

10 files changed

+145
-4
lines changed

10 files changed

+145
-4
lines changed

app/libs/libammsdk.jar

146 KB
Binary file not shown.

app/proguard-rules.pro

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@
4242

4343
-dontwarn com.umeng.**
4444
-keep class com.umeng.update.** {*;}
45-
-keep class com.umeng.analytics.** {*;}
45+
-keep class com.umeng.analytics.** {*;}
46+
47+
-keep class com.tencent.mm.sdk.** {
48+
*;
49+
}

app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@
8787
android:label="@string/main_drawer_settings"
8888
android:theme="@style/AppTheme.ActionBar" />
8989

90+
<activity android:name=".wxapi.WXEntryActivity"
91+
android:label="@string/app_name"
92+
android:exported="true"/>
93+
94+
<activity android:name=".views.SendToWXActivity"
95+
android:configChanges="keyboardHidden|orientation|screenSize"
96+
android:label="分享到朋友圈"
97+
android:icon="@drawable/icon_res_download_moments"
98+
android:theme="@style/DirectShareDialogTheme"
99+
>
100+
<intent-filter>
101+
<action android:name="android.intent.action.SEND" />
102+
<category android:name="android.intent.category.DEFAULT" />
103+
<data android:mimeType="text/plain" />
104+
</intent-filter>
105+
<meta-data
106+
android:name="android.service.chooser.chooser_target_service"
107+
android:value=".TesterChooserTargetService" />
108+
</activity>
109+
90110
<service
91111
android:name="com.umeng.update.net.DownloadingService"
92112
android:process=":DownloadingService"/>

app/src/main/java/com/testerhome/nativeandroid/TesterChooserTargetService.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import android.annotation.TargetApi;
44
import android.content.ComponentName;
55
import android.content.IntentFilter;
6+
import android.graphics.drawable.Icon;
67
import android.os.Build;
8+
import android.os.Bundle;
79
import android.service.chooser.ChooserTarget;
810
import android.service.chooser.ChooserTargetService;
911

12+
import com.testerhome.nativeandroid.views.SendToWXActivity;
13+
1014
import java.util.ArrayList;
1115
import java.util.List;
1216

@@ -15,8 +19,29 @@
1519
*/
1620
@TargetApi(Build.VERSION_CODES.M)
1721
public class TesterChooserTargetService extends ChooserTargetService {
22+
1823
@Override
1924
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
20-
return new ArrayList<>();
25+
26+
ComponentName componentName = new ComponentName(getPackageName(), SendToWXActivity.class.getCanonicalName());
27+
28+
List<ChooserTarget> targets = new ArrayList<>();
29+
30+
String title = "微信朋友圈";
31+
Icon icon = Icon.createWithResource(this, R.drawable.icon_res_download_moments);
32+
33+
float score = 1;
34+
35+
Bundle extras = new Bundle();
36+
extras.putString("type", "circle");
37+
38+
39+
targets.add(new ChooserTarget(
40+
title,
41+
icon,
42+
score,
43+
componentName,
44+
extras));
45+
return targets;
2146
}
2247
}

app/src/main/java/com/testerhome/nativeandroid/views/MainActivity.java

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import android.widget.Toast;
1919

2020
import com.facebook.drawee.view.SimpleDraweeView;
21+
import com.tencent.mm.sdk.openapi.IWXAPI;
22+
import com.tencent.mm.sdk.openapi.WXAPIFactory;
2123
import com.testerhome.nativeandroid.Config;
2224
import com.testerhome.nativeandroid.R;
2325
import com.testerhome.nativeandroid.auth.TesterHomeAccountService;
@@ -46,6 +48,16 @@ protected void onCreate(Bundle savedInstanceState) {
4648
setupView();
4749

4850
UmengUpdateAgent.update(this);
51+
52+
initWeixin();
53+
}
54+
55+
private static final String APP_ID = "wxecf3c70cafae1f8c";
56+
private IWXAPI api;
57+
58+
private void initWeixin() {
59+
api = WXAPIFactory.createWXAPI(this, APP_ID, true);
60+
api.registerApp(APP_ID);
4961
}
5062

5163
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.testerhome.nativeandroid.views;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.util.Log;
7+
8+
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
9+
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
10+
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
11+
import com.tencent.mm.sdk.openapi.WXAPIFactory;
12+
import com.testerhome.nativeandroid.views.base.BackBaseActivity;
13+
14+
/**
15+
* Created by vclub on 15/11/2.
16+
*/
17+
public class SendToWXActivity extends BackBaseActivity {
18+
19+
private String mTitle;
20+
private String mBody;
21+
22+
@Override
23+
protected void onCreate(@Nullable Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
26+
boolean resolved = resolveIntent(getIntent());
27+
if (!resolved){
28+
finish();
29+
return;
30+
}
31+
32+
prepareUI();
33+
34+
}
35+
36+
private boolean resolveIntent(Intent intent){
37+
if (Intent.ACTION_SEND.equals(intent.getAction()) &&
38+
"text/plain".equals(intent.getType())){
39+
mTitle = intent.getStringExtra(Intent.EXTRA_TITLE);
40+
mBody = intent.getStringExtra(Intent.EXTRA_TEXT);
41+
return true;
42+
}
43+
return false;
44+
}
45+
46+
private void prepareUI() {
47+
Log.e("share info", mBody);
48+
// mTextMessageBody.setText(mBody);
49+
50+
WXWebpageObject webpageObject = new WXWebpageObject(mBody);
51+
52+
WXMediaMessage msg = new WXMediaMessage();
53+
msg.mediaObject = webpageObject;
54+
msg.description = "测试";
55+
56+
SendMessageToWX.Req req = new SendMessageToWX.Req();
57+
req.transaction = String.valueOf(System.currentTimeMillis());
58+
req.message = msg;
59+
60+
WXAPIFactory.createWXAPI(this, "wxecf3c70cafae1f8c", true).sendReq(req);
61+
62+
this.finish();
63+
}
64+
}

app/src/main/java/com/testerhome/nativeandroid/views/adapters/TopicReplyAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
7474
holder.topicItemBody.getPaint().setFlags(0);
7575
holder.userAvatar.setImageURI(Uri.parse(Config.getImageUrl(topicReplyEntity.getUser().getAvatar_url())));
7676

77-
holder.mToReply.setTag(String.format("#%s楼 @%s ", position, topicReplyEntity.getUser().getLogin()));
77+
holder.mToReply.setTag(String.format("#%s楼 @%s ", position + 1, topicReplyEntity.getUser().getLogin()));
7878
holder.mToReply.setOnClickListener(new View.OnClickListener() {
7979
@Override
8080
public void onClick(View v) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.testerhome.nativeandroid.wxapi;
2+
3+
import android.app.Activity;
4+
5+
/**
6+
* Created by vclub on 15/11/2.
7+
*/
8+
public class WXEntryActivity extends Activity {
9+
10+
}
Loading

app/src/main/res/values/styles.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<resources>
1+
<resources xmlns:tools="http://schemas.android.com/tools">
22

33
<!-- Base application theme. -->
44
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
@@ -55,4 +55,10 @@
5555
<item name="second_bg">@color/bg_second_dark</item>
5656
<item name="second_text_color">@color/text_color_second_dark</item>
5757
</style>
58+
59+
<style name="DirectShareDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
60+
<item name="android:colorPrimary">@color/colorPrimary</item>
61+
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
62+
<item name="android:colorAccent">@color/colorAccent</item>
63+
</style>
5864
</resources>

0 commit comments

Comments
 (0)