mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Android platform implementation of uri_launcher.mojom (#2760)
This commit is contained in:
parent
62f7eeee8d
commit
02b7238cbb
@ -25,6 +25,7 @@ if (is_android) {
|
||||
"src/org/domokit/platform/PathProviderImpl.java",
|
||||
"src/org/domokit/platform/SystemChromeImpl.java",
|
||||
"src/org/domokit/platform/SystemSoundImpl.java",
|
||||
"src/org/domokit/platform/UriLauncherImpl.java",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package org.domokit.platform;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import org.chromium.mojom.flutter.platform.UriLauncher;
|
||||
|
||||
/**
|
||||
* Android implementation of UriLauncher.
|
||||
*/
|
||||
public class UriLauncherImpl implements UriLauncher {
|
||||
private final Activity mActivity;
|
||||
|
||||
public UriLauncherImpl(Activity activity) {
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
@Override
|
||||
public void launch(String urlString, LaunchResponse callback) {
|
||||
try {
|
||||
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
|
||||
launchIntent.setData(Uri.parse(urlString));
|
||||
mActivity.startActivity(launchIntent);
|
||||
callback.call(true);
|
||||
} catch (java.lang.Exception exception) {
|
||||
// In case of parsing or ActivityNotFound errors
|
||||
callback.call(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,7 @@ import org.chromium.mojom.flutter.platform.HapticFeedback;
|
||||
import org.chromium.mojom.flutter.platform.PathProvider;
|
||||
import org.chromium.mojom.flutter.platform.SystemChrome;
|
||||
import org.chromium.mojom.flutter.platform.SystemSound;
|
||||
import org.chromium.mojom.flutter.platform.UriLauncher;
|
||||
import org.chromium.mojom.media.MediaService;
|
||||
import org.chromium.mojom.mojo.NetworkService;
|
||||
import org.chromium.mojom.sensors.SensorService;
|
||||
@ -50,6 +51,7 @@ import org.domokit.platform.HapticFeedbackImpl;
|
||||
import org.domokit.platform.PathProviderImpl;
|
||||
import org.domokit.platform.SystemChromeImpl;
|
||||
import org.domokit.platform.SystemSoundImpl;
|
||||
import org.domokit.platform.UriLauncherImpl;
|
||||
import org.domokit.vsync.VSyncProviderImpl;
|
||||
|
||||
/**
|
||||
@ -210,6 +212,13 @@ public class FlutterMain {
|
||||
return SystemSound.MANAGER.bind(new SystemSoundImpl((android.app.Activity) context), pipe);
|
||||
}
|
||||
});
|
||||
|
||||
registry.register(UriLauncher.MANAGER.getName(), new ServiceFactory() {
|
||||
@Override
|
||||
public Binding connectToService(Context context, Core core, MessagePipeHandle pipe) {
|
||||
return UriLauncher.MANAGER.bind(new UriLauncherImpl((android.app.Activity) context), pipe);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user