Android platform implementation of uri_launcher.mojom (#2760)

This commit is contained in:
Chinmay Garde 2016-06-15 12:35:06 -07:00 committed by GitHub
parent 62f7eeee8d
commit 02b7238cbb
3 changed files with 53 additions and 0 deletions

View File

@ -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 = [

View File

@ -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);
}
}
}

View File

@ -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);
}
});
}
/**