titanium-mobiletitanium-modulestitanium-android

how to set the Activity in titanium when I send message to wechat?


I already registered to wechat successfully. and I want to send message to wechat now, but I occured:

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

this is my android module(src//.java) code:

 @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());
  }

and this my test_app

<activity android:name="com.happysoft.testmodule.TestModuleModule" android:exported="true" android:label="@string/app_name"></activity>

Solution

  • 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=====================");
    
      }