Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example运行起来后报错,我把代码集成到项目以后,setAlias同样报错 #14

Open
a314730500 opened this issue Jul 2, 2019 · 4 comments

Comments

@a314730500
Copy link

D/FlutterJPushPlugin(30870): MyJPushMessageReceiver init
E/AndroidRuntime(30870): FATAL EXCEPTION: MessageReceiver
E/AndroidRuntime(30870): Process: com.jzoom.pushtest, PID: 30870
E/AndroidRuntime(30870): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: MessageReceiver
E/AndroidRuntime(30870): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/AndroidRuntime(30870): at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556)
E/AndroidRuntime(30870): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:131)
E/AndroidRuntime(30870): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime(30870): at com.jzoom.flutterjpush.FlutterJPushPlugin$MyJPushMessageReceiver.onAliasOperatorResult(FlutterJPushPlugin.java:766)
E/AndroidRuntime(30870): at cn.jpush.android.a.b.run(Unknown Source:90)
E/AndroidRuntime(30870): at android.os.Handler.handleCallback(Handler.java:808)
E/AndroidRuntime(30870): at android.os.Handler.dispatchMessage(Handler.java:101)
E/AndroidRuntime(30870): at android.os.Looper.loop(Looper.java:166)
E/AndroidRuntime(30870): at android.os.HandlerThread.run(HandlerThread.java:65)
I/HwCust (30870): Constructor found for class android.net.HwCustConnectivityManagerImpl
D/HwCust (30870): Create obj success use class android.net.HwCustConnectivityManagerImpl
I/HwApiCacheMangerEx(30870): apicache pi null
I/HwApiCacheMangerEx(30870): apicache pi PackageInfo{db15c83 com.jzoom.pushtest}
D/NetworkSecurityConfig(30870): No Network Security Config specified, using platform default
I/Process (30870): Sending signal. PID: 30870 SIG: 9

@zgzhuwenbing
Copy link

一样的 大佬 你解决了么?

@Deain
Copy link

Deain commented Jul 16, 2019

修改result运行在主线程,自定义MainThreadResult类实现MethodChannel.Result接口

class MainThreadResult implements MethodChannel.Result {
    private MethodChannel.Result result;
    private Handler handler;

    MainThreadResult(MethodChannel.Result result) {
        this.result = result;
        handler = new Handler(Looper.getMainLooper());
    }

    @Override
    public void success(final Object o) {
        handler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        result.success(o);
                    }
                });
    }

    @Override
    public void error(
            final String errorCode, final String errorMessage, final Object errorDetails) {
        handler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        result.error(errorCode, errorMessage, errorDetails);
                    }
                });
    }

    @Override
    public void notImplemented() {
        handler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        result.notImplemented();
                    }
                });
    }
}

JPushEventReceiver.javaonAliasOperatorResult

 @Override
    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
        super.onAliasOperatorResult(context, jPushMessage);

        int sequence = jPushMessage.getSequence();

        Result callback = JPushPlugin.instance.callbackMap.get(sequence);
        if (callback == null) {
            Log.i("JPushPlugin", "Unexpected error, callback is null!");
            return;
        }
++   callback = new MainThreadResult(callback);
        if (jPushMessage.getErrorCode() == 0) { // success
            Map<String, Object> res = new HashMap<>();
            res.put("alias", (jPushMessage.getAlias() == null) ? "" : jPushMessage.getAlias());
            callback.success(res);

        } else {
            callback.error(Integer.toString(jPushMessage.getErrorCode()), "", "");
        }

        JPushPlugin.instance.callbackMap.remove(sequence);
    }

@rootzm
Copy link

rootzm commented Nov 1, 2019

能把这问题rp吗

@rootzm
Copy link

rootzm commented Nov 1, 2019

@jzoom 能把这问题pr了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants