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

Commit

Permalink
Add canLaunch method to url_launcher plugin (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias authored Apr 27, 2017
1 parent 7372c60 commit 66892d1
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 106 deletions.
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

0 comments on commit 66892d1

Please sign in to comment.