Java 用flatter打开谷歌定位
我想在android上用我的Flitter应用程序从WhatsApp location打开google locations,并获取[纬度,经度]数据在地图上绘制 我试过这个Java 用flatter打开谷歌定位,java,android,flutter,android-intent,whatsapp,Java,Android,Flutter,Android Intent,Whatsapp,我想在android上用我的Flitter应用程序从WhatsApp location打开google locations,并获取[纬度,经度]数据在地图上绘制 我试过这个 在android.manifest.xml中 最后 <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="geo&quo
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
</intent-filter>
public class MainActivity extends FlutterActivity {
private String sharedText;
private static final String CHANNEL = "app.channel.shared.data";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String type = intent.getType();
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action) && type != null) {
handleSendText(intent);
}
}
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler(
(call, result) -> {
if (call.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
);
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
}
void getSharedText() async {
var sharedData = await platform.invokeMethod("getSharedText");
if (sharedData != null) {
setState(() {
dataShared = sharedData;
});
}
}