Browse Source

added support for android extern intent result

pull/106/head
Devmel Apps 1 year ago
parent
commit
00da815402
  1. 4
      zxscanner/android/app/src/main/AndroidManifest.xml
  2. 2
      zxscanner/lib/configs/app_store.dart
  3. 19
      zxscanner/lib/main.dart
  4. 8
      zxscanner/lib/pages/scanner_page.dart
  5. 1
      zxscanner/pubspec.yaml

4
zxscanner/android/app/src/main/AndroidManifest.xml

@ -25,6 +25,10 @@
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

2
zxscanner/lib/configs/app_store.dart

@ -15,6 +15,8 @@ const String isVibrationOnPref = 'isVibrationOnPref';
const String languagePref = 'languagePref'; const String languagePref = 'languagePref';
abstract class AppStoreBase with Store { abstract class AppStoreBase with Store {
static bool isExternCall = false;
@observable @observable
ThemeMode themeMode = ThemeMode.system; ThemeMode themeMode = ThemeMode.system;

19
zxscanner/lib/main.dart

@ -1,8 +1,10 @@
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:receive_intent/receive_intent.dart';
import 'configs/app_store.dart'; import 'configs/app_store.dart';
import 'configs/app_theme.dart'; import 'configs/app_theme.dart';
@ -31,6 +33,23 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
final AppRouter _appRouter = AppRouter(); final AppRouter _appRouter = AppRouter();
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
if (Platform.isAndroid) {
final receivedIntent = await ReceiveIntent.getInitialIntent();
if(receivedIntent?.fromPackageName != null){
AppStoreBase.isExternCall = true;
}else{
AppStoreBase.isExternCall = false;
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

8
zxscanner/lib/pages/scanner_page.dart

@ -1,6 +1,9 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:receive_intent/receive_intent.dart';
import '../configs/app_store.dart';
import '../models/models.dart' as model; import '../models/models.dart' as model;
import '../utils/db_service.dart'; import '../utils/db_service.dart';
import '../utils/extensions.dart'; import '../utils/extensions.dart';
@ -34,5 +37,10 @@ class _ScannerPageState extends State<ScannerPage> {
final model.Code code = model.Code.fromCodeResult(result); final model.Code code = model.Code.fromCodeResult(result);
DbService.instance.addCode(code); DbService.instance.addCode(code);
context.showToast('Barcode saved:\n${code.text ?? ''}'); context.showToast('Barcode saved:\n${code.text ?? ''}');
if (Platform.isAndroid) {
if(AppStoreBase.isExternCall) {
ReceiveIntent.setResult(kActivityResultOk, data: {"SCAN_RESULT": "${code.text ?? ''}"}, shouldFinish:true);
}
}
} }
} }

1
zxscanner/pubspec.yaml

@ -30,6 +30,7 @@ dependencies:
share_plus: ^7.0.0 share_plus: ^7.0.0
shared_preferences: ^2.0.0 shared_preferences: ^2.0.0
url_launcher: ^6.1.11 url_launcher: ^6.1.11
receive_intent: any
flutter_intl: flutter_intl:
main_locale: en_US main_locale: en_US

Loading…
Cancel
Save