Skip to content

Commit 807205a

Browse files
authored
First commit of android_intent plugin. (flutter#99)
* First commit of android_intent plugin. * Comments and formatting fixes * Add back the iOS dummy code for android_intent as per discussion on github.com/flutter/flutter/issues/10530. * Review comments * missing meta dependency. Caught by pub publish --dryrun
1 parent c58d066 commit 807205a

File tree

68 files changed

+1609
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1609
-0
lines changed

packages/android_intent/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/android_intent/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial release

packages/android_intent/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/android_intent/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Android Intent Plugin for Flutter
2+
3+
This plugin allows Flutter apps to launch arbitrary intents when the platform
4+
is Android. If the plugin is invoked on iOS, it will crash your app. In checked
5+
mode, we assert that the platform should be Android.
6+
7+
Use it by specifying action, category, data and extra arguments for the intent.
8+
It does not support returning the result of the launched activity. Sample usage:
9+
10+
```
11+
if (platform.isAndroid) {
12+
AndroidIntent intent = new AndroidIntent(
13+
action: 'action_view',
14+
data: 'https://play.google.com/store/apps/details?'
15+
'id=com.google.android.apps.myapp',
16+
arguments: {'authAccount': currentUserEmail},
17+
);
18+
await intent.launch();
19+
}
20+
```
21+
22+
See documentation on the AndroidIntent class for details on each parameter.
23+
24+
Action parameter can be any action including a custom class name to be invoked.
25+
If a standard android action is required, the recommendation is to add support
26+
for it in the plugin and use an action constant to refer to it. For instance:
27+
28+
`'action_view'` translates to `android.os.Intent.ACTION_VIEW`
29+
30+
Feel free to add support for additional Android intents.
31+
32+
> Note that a similar method does not currently exist for iOS. Instead, the
33+
system plugin ([UrlLauncher](https://docs.flutter.io/flutter/services/UrlLauncher-class.html))
34+
can be used for deep linking. UrlLauncher can also be used for creating
35+
ACTION_VIEW intents for Android, however this intent plugin also allows
36+
clients to set extra parameters for the intent.
37+
38+
## Getting Started
39+
40+
For help getting started with Flutter, view our online
41+
[documentation](http://flutter.io/).
42+
43+
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
group 'io.flutter.plugins.androidintent'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.3'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'android_intent'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.androidintent"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
</manifest>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.androidintent;
6+
7+
import android.app.Activity;
8+
import android.content.Context;
9+
import android.content.Intent;
10+
import android.net.Uri;
11+
import android.os.Bundle;
12+
import android.util.Log;
13+
import io.flutter.plugin.common.MethodCall;
14+
import io.flutter.plugin.common.MethodChannel;
15+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
16+
import io.flutter.plugin.common.MethodChannel.Result;
17+
import io.flutter.plugin.common.PluginRegistry.Registrar;
18+
import java.util.Map;
19+
20+
/** AndroidIntentPlugin */
21+
@SuppressWarnings("unchecked")
22+
public class AndroidIntentPlugin implements MethodCallHandler {
23+
private final Context context;
24+
25+
/** Plugin registration. */
26+
public static void registerWith(Registrar registrar) {
27+
final MethodChannel channel =
28+
new MethodChannel(registrar.messenger(), "plugins.flutter.io/android_intent");
29+
channel.setMethodCallHandler(new AndroidIntentPlugin(registrar.activity()));
30+
}
31+
32+
private AndroidIntentPlugin(Activity activity) {
33+
this.context = activity;
34+
}
35+
36+
private String convertAction(String action) {
37+
switch (action) {
38+
case "action_view":
39+
return Intent.ACTION_VIEW;
40+
case "action_voice":
41+
return Intent.ACTION_VOICE_COMMAND;
42+
default:
43+
return action;
44+
}
45+
}
46+
47+
private Bundle convertArguments(Map<String, ?> arguments) {
48+
Bundle bundle = new Bundle();
49+
for (String key : arguments.keySet()) {
50+
Object value = arguments.get(key);
51+
if (value instanceof Integer) {
52+
bundle.putInt(key, (Integer) value);
53+
} else if (value instanceof String) {
54+
bundle.putString(key, (String) value);
55+
} else if (value instanceof Boolean) {
56+
bundle.putBoolean(key, (Boolean) value);
57+
} else if (value instanceof Double) {
58+
bundle.putDouble(key, (Double) value);
59+
} else if (value instanceof Long) {
60+
bundle.putLong(key, (Long) value);
61+
} else {
62+
throw new UnsupportedOperationException("Unsupported type " + value);
63+
}
64+
}
65+
return bundle;
66+
}
67+
68+
@Override
69+
public void onMethodCall(MethodCall call, Result result) {
70+
String action = convertAction((String) call.argument("action"));
71+
// Build intent
72+
Intent intent = new Intent(action);
73+
if (call.argument("category") != null) {
74+
intent.addCategory((String) call.argument("category"));
75+
}
76+
if (call.argument("data") != null) {
77+
intent.setData(Uri.parse((String) call.argument("data")));
78+
}
79+
if (call.argument("arguments") != null) {
80+
intent.putExtras(convertArguments((Map) call.argument("arguments")));
81+
}
82+
Log.i("android_intent plugin", "Sending intent " + intent);
83+
context.startActivity(intent);
84+
result.success(null);
85+
}
86+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="FLUTTER_MODULE_TYPE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<excludeFolder url="file://$MODULE_DIR$/.idea" />
7+
<excludeFolder url="file://$MODULE_DIR$/.pub" />
8+
<excludeFolder url="file://$MODULE_DIR$/build" />
9+
<excludeFolder url="file://$MODULE_DIR$/packages" />
10+
</content>
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
<orderEntry type="library" name="Dart Packages" level="project" />
13+
<orderEntry type="library" name="Dart SDK" level="project" />
14+
</component>
15+
</module>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/android">
6+
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="Flutter for Android" level="project" />
11+
</component>
12+
</module>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock
10+
.flutter-plugins
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# android_intent_example
2+
3+
Demonstrates how to use the android_intent plugin.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter, view our online
8+
[documentation](http://flutter.io/).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/android">
6+
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="Flutter for Android" level="project" />
11+
</component>
12+
</module>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
GeneratedPluginRegistrant.java
10+
11+
/gradle
12+
/gradlew
13+
/gradlew.bat
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withInputStream { stream ->
5+
localProperties.load(stream)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
apply plugin: 'com.android.application'
15+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
16+
17+
android {
18+
compileSdkVersion 25
19+
buildToolsVersion '25.0.3'
20+
21+
lintOptions {
22+
disable 'InvalidPackage'
23+
}
24+
25+
defaultConfig {
26+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
27+
28+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
29+
applicationId "io.flutter.plugins.androidintentexample"
30+
}
31+
32+
buildTypes {
33+
release {
34+
// TODO: Add your own signing config for the release build.
35+
// Signing with the debug keys for now, so `flutter run --release` works.
36+
signingConfig signingConfigs.debug
37+
}
38+
}
39+
}
40+
41+
flutter {
42+
source '../..'
43+
}
44+
45+
dependencies {
46+
androidTestCompile 'com.android.support:support-annotations:25.0.0'
47+
androidTestCompile 'com.android.support.test:runner:0.5'
48+
androidTestCompile 'com.android.support.test:rules:0.5'
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.androidintentexample"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
8+
<!-- The INTERNET permission is required for development. Specifically,
9+
flutter needs it to communicate with the running application
10+
to allow setting breakpoints, to provide hot reload, etc.
11+
-->
12+
<uses-permission android:name="android.permission.INTERNET"/>
13+
14+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
15+
calls FlutterMain.startInitialization(this); in its onCreate method.
16+
In most cases you can leave this as-is, but you if you want to provide
17+
additional functionality it is fine to subclass or reimplement
18+
FlutterApplication and put your custom class here. -->
19+
<application android:name="io.flutter.app.FlutterApplication" android:label="android_intent_example" android:icon="@mipmap/ic_launcher">
20+
<activity android:name=".MainActivity"
21+
android:launchMode="singleTop"
22+
android:theme="@android:style/Theme.Black.NoTitleBar"
23+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
24+
android:hardwareAccelerated="true"
25+
android:windowSoftInputMode="adjustResize">
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
</application>
32+
</manifest>

0 commit comments

Comments
 (0)