|
| 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 | +} |
0 commit comments