我已成功注册微信。我现在想给微信发消息,但我发现了:
[ERROR] E/MicroMsg.SDK.MMessageAct: send fail, target ActivityNotFound
这是我的android模块(src / / .java)代码:
@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());
}
这是我的test_app
<activity android:name="com.happysoft.testmodule.TestModuleModule" android:exported="true" android:label="@string/app_name"></activity>
答案 0 :(得分:0)
我解决了这个问题。
@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=====================");
}