Saturday, October 10, 2015

[ERROR] E/MicroMsg.SDK.MMessageAct: send fail, target ActivityNotFound Android


我的代码:

@Kroll.method
  public void regToWx()
  {
    Log.d(current_module, "=======start to register to wechat==========");
    api = WXAPIFactory.createWXAPI(getActivity(),null);
    Log.d(current_module, "=======create api after====="+api);
    api.registerApp(APP_ID);
    Log.d(current_module, "====注册微信成功======");
  }


  @Kroll.method
  public void sendMessageToWx()
  {
    Log.d(current_module, "====下面发送消息给微信======");
    WXTextObject text_obj = new WXTextObject();
    text_obj.text="we are young!!!";
    Log.d(current_module, "====构造Media Message======");
    WXMediaMessage msg_obj = new WXMediaMessage();
    msg_obj.mediaObject = text_obj;
    msg_obj.description = "this is desciption";
    Log.d(current_module, "====构造 Request======");
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = msg_obj;
    req.scene = SendMessageToWX.Req.WXSceneTimeline;
    Log.d(current_module, "====发送请求给微信了======");
    boolean result = api.sendReq(req);
    Log.d(current_module, "====result======"+result);
    Activity activity = TiApplication.getInstance().getCurrentActivity();
    Log.d(current_module, activity.toString());

  }


参考的解决方案:

I solved this trouble.
@Kroll.onAppCreate
  public static void onAppCreate(TiApplication app)
  {
    Log.d(LCAT, "inside onAppCreate");
    api = WXAPIFactory.createWXAPI(app,APP_ID,true);
    api.registerApp(APP_ID);
    Log.d(LCAT, "================= register App success=====================");

  }

参考文档:
IWXAPI 有状态信息appId,每次调用时都实例化一个新对象



========== METHOD SUMMARY ===========
Method Summary
static IWXAPI
createWXAPI(Context context, java.lang.String appId) 
           
static IWXAPI
createWXAPI(Context context, java.lang.String appId, boolean checkSignature) 
           


其实最主要的就是因为, 签名不对的问题。所以,一定要确保签名没有问题!

参考链接http://stackoverflow.com/questions/29075496/how-to-set-the-activity-in-titanium-when-i-send-message-to-wechat





No comments:

Post a Comment