-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add canLaunch method to url_launcher plugin #8
Changes from 9 commits
d7b5dbb
7c3ed27
2b3b91e
18c3b53
6c6e71d
96c1963
44786cc
6c1e633
4354c1a
16634fc
b7ec3d6
f97821c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
|
|
||
| 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; | ||
|
|
||
|
|
@@ -13,34 +18,51 @@ | |
| * 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 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 UrlLauncherPlugin(FlutterActivity activity) { | ||
| this.activity = activity; | ||
| new MethodChannel( | ||
| activity.getFlutterView(), "plugins.flutter.io/URLLauncher").setMethodCallHandler(this); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMethodCall(MethodCall call, Result result) { | ||
| String url = call.arguments(); | ||
| if (call.method.equals("UrlLauncher.canLaunch")) { | ||
|
||
| canLaunch(url, result); | ||
| } else if (call.method.equals("UrlLauncher.launch")) { | ||
| launchURL(url, result); | ||
| } else { | ||
| result.notImplemented(); | ||
| } | ||
| } | ||
|
|
||
| private void launchURL(String url, Result result) { | ||
| try { | ||
| Intent launchIntent = new Intent(Intent.ACTION_VIEW); | ||
| launchIntent.setData(Uri.parse(url)); | ||
| activity.startActivity(launchIntent); | ||
| result.success(null); | ||
| } catch (java.lang.Exception exception) { | ||
|
||
| result.error("ERROR", exception.getMessage(), null); | ||
| } | ||
| } | ||
|
|
||
| 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()); | ||
| if (componentName == null || | ||
| "{com.android.fallback/com.android.fallback.Fallback}". | ||
| equals(componentName.toShortString())) { | ||
| result.success(false); | ||
| } else { | ||
| result.success(true); | ||
| } | ||
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ buildscript { | |
| } | ||
|
|
||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:2.2.3' | ||
| classpath 'com.android.tools.build:gradle:2.3.1' | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decide on format for the channel name suffix: camelCase, multi_word, acronyms in lower or upper case, whatever. Just be consistent across plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choosing multi_word to be consistent with plugins in G3