-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove device_info_plus and implement getting the android versi…
…on directly in the app
- Loading branch information
Showing
6 changed files
with
53 additions
and
39 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
android/app/src/main/kotlin/tk/user5522/timetable/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
package tk.user5522.timetable | ||
|
||
import io.flutter.embedding.android.FlutterActivity | ||
import android.os.Build | ||
import androidx.annotation.NonNull | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
|
||
class MainActivity: FlutterActivity() { | ||
private val CHANNEL = "tk.user5522.timetable/androidVersion" | ||
|
||
fun getAndroidVersion(): Int { | ||
return Build.VERSION.SDK_INT | ||
} | ||
|
||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { | ||
call, result -> | ||
if (call.method == "getAndroidVersion") { | ||
val androidVersion = getAndroidVersion() | ||
|
||
if (androidVersion != -1) { | ||
result.success(androidVersion) | ||
} else { | ||
// result.error("UNAVAILABLE", 0, null) | ||
} | ||
} else { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'dart:async'; | ||
import 'package:flutter/services.dart'; | ||
|
||
const platform = MethodChannel('tk.user5522.timetable/androidVersion'); | ||
|
||
Future<int> getAndroidVersion() async { | ||
int version; | ||
|
||
try { | ||
final result = await platform.invokeMethod<int>('getAndroidVersion'); | ||
version = result!; | ||
} on PlatformException { | ||
version = 0; | ||
} | ||
|
||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters