flatter深度链接,错误:在尝试将深度链接添加到我的flatter应用程序时找不到符号

ybzsozfc  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(219)

我正试图在我的flatter应用程序中实现深度链接,我遵循了这个指南,从我的用户那里得到了这个错误 application.java 文件夹:

error: cannot find symbol

下面是我的applicaton.java代码:

package com.deliveryrunner.vendor;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.net.Uri;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

import static com.google.firebase.messaging.Constants.MessageNotificationKeys.CHANNEL;

public class Application extends FlutterApplication implements PluginRegistrantCallback {

    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);

        Intent intent = getIntent();
        Uri data = intent.getData();
        new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
                new MethodChannel.MethodCallHandler() {
                    @Override
                    public void onMethodCall(MethodCall call, MethodChannel.Result result) {
                        if (call.method.equals("initialLink")) {
                            if (startString != null) {
                                result.success(startString);
                            }
                        }
                    }
                }
        );
        new EventChannel(getFlutterView(), EVENTS).setStreamHandler(
                new EventChannel.StreamHandler() {
                    @Override
                    public void onListen(Object args, final EventChannel.EventSink events) {
                        linksReceiver = createChangeReceiver(events);
                    }

                    @Override
                    public void onCancel(Object args) {
                        linksReceiver = null;
                    }
                }
        );
        if (data != null) {
            startString = data.toString();
            if (linksReceiver != null) {
                linksReceiver.onReceive(this.getApplicationContext(), intent);
            }
        }
    }
    @Override
    public void registerWith(PluginRegistry registry) {
        FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
    }

    private BroadcastReceiver createChangeReceiver(final EventChannel.EventSink events) {
        return new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // NOTE: assuming intent.getAction() is Intent.ACTION_VIEW

                String dataString = intent.getDataString();

                if (dataString == null) {
                    events.error("UNAVAILABLE", "Link unavailable", null);
                } else {
                    events.success(dataString);
                }
            }
        };
    }

    @Override
        public void onNewIntent(Intent intent){
            super.onNewIntent(intent);
            if(intent.getAction() == android.content.Intent.ACTION_VIEW && linksReceiver != null) {
                linksReceiver.onReceive(this.getApplicationContext(), intent);
            }
        }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题