Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add canLaunch method to url_launcher plugin #8

Merged
merged 12 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/url-launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.3.0] - 2017-04-27

* Add `canLaunch` method.

## [0.2.0] - 2017-04-24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Copyright 2017 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 io.flutter.plugins.url_launcher;

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

Expand All @@ -13,34 +18,45 @@
* UrlLauncherPlugin
*/
public class UrlLauncherPlugin implements MethodCallHandler {
private FlutterActivity activity;

public static UrlLauncherPlugin register(FlutterActivity activity) {
return new UrlLauncherPlugin(activity);
}

private UrlLauncherPlugin(FlutterActivity activity) {
this.activity = activity;
new MethodChannel(
activity.getFlutterView(), "plugins.flutter.io/URLLauncher").setMethodCallHandler(this);
}

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("UrlLauncher.launch")) {
launchURL((String) call.arguments);
result.success(null);
} else {
result.notImplemented();
private FlutterActivity activity;

public static UrlLauncherPlugin register(FlutterActivity activity) {
return new UrlLauncherPlugin(activity);
}

private UrlLauncherPlugin(FlutterActivity activity) {
this.activity = activity;
new MethodChannel(
activity.getFlutterView(), "plugins.flutter.io/url_launcher").setMethodCallHandler(this);
}

@Override
public void onMethodCall(MethodCall call, Result result) {
String url = call.arguments();
if (call.method.equals("canLaunch")) {
canLaunch(url, result);
} else if (call.method.equals("launch")) {
launchURL(url, result);
} else {
result.notImplemented();
}
}

private void launchURL(String url, Result result) {
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(url));
activity.startActivity(launchIntent);
result.success(null);
}
}
private void launchURL(String url) {
try {
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(url));
activity.startActivity(launchIntent);
} catch (java.lang.Exception exception) {
// Ignore parsing or ActivityNotFound errors

private void canLaunch(String url, Result result) {
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(url));
ComponentName componentName = launchIntent.resolveActivity(activity.getPackageManager());

boolean canLaunch = componentName != null &&
!"{com.android.fallback/com.android.fallback.Fallback}".
equals(componentName.toShortString());
result.success(canLaunch);
}
}
}
102 changes: 51 additions & 51 deletions packages/url-launcher/example/ios/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading