Skip to content

Commit 2abc741

Browse files
Added implementation of SBS to flutter_template.
1 parent c9bab5e commit 2abc741

File tree

11 files changed

+477
-38
lines changed

11 files changed

+477
-38
lines changed

Template/MobileTemplate/flutter_template/.metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: 4d7946a68d26794349189cf21b3f68cc6fe61dcb
7+
revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
88
channel: stable
99

1010
project_type: app

Template/MobileTemplate/flutter_template/android/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ android {
3939
targetSdkVersion 30
4040
versionCode flutterVersionCode.toInteger()
4141
versionName flutterVersionName
42+
manifestPlaceholders = [
43+
'appAuthRedirectScheme': 'io.identityserver.demo'
44+
]
4245
}
4346

4447
buildTypes {

Template/MobileTemplate/flutter_template/android/app/src/main/AndroidManifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,37 @@
3131
<action android:name="android.intent.action.MAIN"/>
3232
<category android:name="android.intent.category.LAUNCHER"/>
3333
</intent-filter>
34+
<!-- Deep Links -->
35+
<!--intent-filter>
36+
<action android:name="android.intent.action.VIEW" />
37+
<category android:name="android.intent.category.DEFAULT" />
38+
<category android:name="android.intent.category.BROWSABLE" />
39+
<data android:scheme="opentouryo" android:host="hoge" />
40+
</intent-filter-->
41+
<!-- App Links -->
42+
<!--intent-filter android:autoVerify="true">
43+
<action android:name="android.intent.action.VIEW" />
44+
<category android:name="android.intent.category.DEFAULT" />
45+
<category android:name="android.intent.category.BROWSABLE" />
46+
<data android:scheme="http" android:host="opentouryo.com" />
47+
</intent-filter-->
3448
</activity>
3549
<!-- Don't delete the meta-data below.
3650
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
3751
<meta-data
3852
android:name="flutterEmbedding"
3953
android:value="2" />
4054
</application>
55+
<queries>
56+
<intent>
57+
<action android:name="android.intent.action.VIEW" />
58+
<category android:name="android.intent.category.BROWSABLE" />
59+
<data android:scheme="https" />
60+
</intent>
61+
<intent>
62+
<action android:name="android.intent.action.VIEW" />
63+
<category android:name="android.intent.category.APP_BROWSER" />
64+
<data android:scheme="https" />
65+
</intent>
66+
</queries>
4167
</manifest>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
package com.opentouryo.flutter_template
22

3+
import androidx.annotation.NonNull
34
import io.flutter.embedding.android.FlutterActivity
5+
import io.flutter.embedding.engine.FlutterEngine
6+
import io.flutter.plugin.common.MethodChannel
7+
8+
import android.content.Context
9+
import android.content.ContextWrapper
10+
import android.content.Intent
11+
import android.content.IntentFilter
12+
import android.os.BatteryManager
13+
import android.os.Build.VERSION
14+
import android.os.Build.VERSION_CODES
415

516
class MainActivity: FlutterActivity() {
17+
private val CHANNEL = "flutter_template.opentouryo.com/battery"
18+
19+
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
20+
super.configureFlutterEngine(flutterEngine)
21+
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
22+
call, result ->
23+
// Note: this method is invoked on the main thread.
24+
// TODO
25+
if (call.method == "getBatteryLevel") {
26+
val batteryLevel = getBatteryLevel()
27+
28+
if (batteryLevel != -1) {
29+
result.success(batteryLevel)
30+
} else {
31+
result.error("UNAVAILABLE", "Battery level not available.", null)
32+
}
33+
} else {
34+
result.notImplemented()
35+
}
36+
}
37+
}
38+
39+
private fun getBatteryLevel(): Int {
40+
val batteryLevel: Int
41+
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
42+
val batteryManager = getSystemService(Context.BATTERY_SERVICE) as BatteryManager
43+
batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
44+
} else {
45+
val intent = ContextWrapper(applicationContext).registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
46+
batteryLevel = intent!!.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
47+
}
48+
49+
return batteryLevel
50+
}
651
}

Template/MobileTemplate/flutter_template/android/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ allprojects {
2121
rootProject.buildDir = '../build'
2222
subprojects {
2323
project.buildDir = "${rootProject.buildDir}/${project.name}"
24-
}
25-
subprojects {
2624
project.evaluationDependsOn(':app')
2725
}
2826

Template/MobileTemplate/flutter_template/ios/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Flutter/App.framework
1818
Flutter/Flutter.framework
1919
Flutter/Flutter.podspec
2020
Flutter/Generated.xcconfig
21+
Flutter/ephemeral/
2122
Flutter/app.flx
2223
Flutter/app.zip
2324
Flutter/flutter_assets/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
// ignore_for_file: lines_longer_than_80_chars
6+
7+
import 'package:url_launcher_web/url_launcher_web.dart';
8+
9+
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
10+
11+
// ignore: public_member_api_docs
12+
void registerPlugins(Registrar registrar) {
13+
UrlLauncherPlugin.registerWith(registrar);
14+
registrar.registerMessageHandler();
15+
}

0 commit comments

Comments
 (0)