Я пытаюсь настроить приложение Flutter для получения данных из других приложений через диалоговые окна общего доступа iOS / Android. В основном я хочу получать http-ссылки. Хотя есть несколько плагинов, которые позволяют делиться с Flutter, я не могу ничего найти, когда дело доходит до получения данных (по крайней мере, не кросс-платформенных). Я проработал этот пример из официальной документации Flutter, но он не работает. MainActivity.java выдает исключение «не удается найти символ MethodCallHandler».
MainActivity.java:
package com.example.flutterlink;
import android.content.Intent;
import android.os.Bundle;
import java.nio.ByteBuffer;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.ActivityLifecycleListener;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
private String sharedText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
}
Какие-нибудь намеки?
документация был обновлен несколько дней назад и теперь включает отсутствующий импортный import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
.
Хорошо, на самом деле это довольно просто: в коде документации отсутствует импорт.
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
до сих пор не знает, как добиться того же на iOS.