第三方app分享内容到朋友圈,点击分享后可以弹出登录界面,登陆后没有分享提示框

圈圈_cheng 发布于 2014/07/01 11:44
阅读 2K+
收藏 0
第三方app分享内容到朋友圈,点击分享后可以弹出登录界面,登陆后没有分享提示框,以下是我的代码:


点击事件里面的代码,在这个类的onCreate里面注册的appid。
String videoUrl = "http://v.youku.com/v_show/id_XNjY3ODU2NDI4.html";  
String text = body;
WXTextObject wxTextObject = new WXTextObject();
wxTextObject.text = text;

               WXMediaMessage msg = new WXMediaMessage(wxTextObject);  
               msg.mediaObject = wxTextObject;  
               msg.description = text;  
               msg.title = "央广手机电视";
               SendMessageToWX.Req req = new SendMessageToWX.Req();
               req.scene = SendMessageToWX.Req.WXSceneTimeline;
               req.transaction = String.valueOf(System.currentTimeMillis());  
               req.message = msg;  
               
               wxapi.sendReq(req);  [/code]
WXEntryActivity代码,类在包名.wxapi包下

public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
IWXAPI mapi;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

mapi = WXAPIFactory.createWXAPI(this,Configuration.WX_APP_ID, false);
mapi.registerApp(Configuration.WX_APP_ID);
mapi.handleIntent(getIntent(), this);
}


@Override
public void onReq(BaseReq req) {
switch (req.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
goToGetMsg();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
goToShowMsg((ShowMessageFromWX.Req) req);
break;
}

}


@Override
public void onResp(BaseResp resp) {
int result = 0;
switch (resp.errCode) {
case BaseResp.ErrCode.ERR_OK:
result = R.string.errcode_success;
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
result =R.string.errcode_cancel;
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
result = R.string.errcode_deny;
break;
default:
result =R.string.errcode_unknown;
break;
}
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}


private void goToGetMsg() {
Intent intent = new Intent(this,DetailPlayerActivity.class);
intent.putExtras(getIntent());
startActivity(intent);
finish();
}
private void goToShowMsg(ShowMessageFromWX.Req showReq) {
WXMediaMessage wxMsg = showReq.message;
WXAppExtendObject obj = (WXAppExtendObject) wxMsg.mediaObject;


StringBuffer msg = new StringBuffer(); // 组织一个待显示的消息内容
msg.append("description: ");
msg.append(wxMsg.description);
msg.append("\n");
msg.append("extInfo: ");
msg.append(obj.extInfo);
msg.append("\n");
msg.append("filePath: ");
msg.append(obj.filePath);

Intent intent = new Intent(this,
ShowFromWXActivity.class);
intent.putExtra("title", wxMsg.title);
intent.putExtra("msg", msg.toString());
intent.putExtra("data", wxMsg.thumbData);
startActivity(intent);
finish();
}

}




ShowFromWXActivity
[code=java]
public class ShowFromWXActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.show_from_wx);
System.out.println("-----------------[[[[[[");
initView();
}


private void initView() {


final String title = getIntent().getStringExtra("title");
final String message = getIntent().getStringExtra("msg");
final byte[] thumbData = getIntent().getByteArrayExtra("data");

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage(message);

if (thumbData != null && thumbData.length > 0) {
ImageView thumbIv = new ImageView(this);
thumbIv.setImageBitmap(BitmapFactory.decodeByteArray(thumbData, 0, thumbData.length));
builder.setView(thumbIv);
}

builder.show();
}
}
[/code]




加载中
0
曼曼哒
曼曼哒
你都是全部自己写的呀? 真牛! 我直接用的友推SDK,都已经集成好了
返回顶部
顶部