diff --git a/permission_handler_ohos/example/lib/main.dart b/permission_handler_ohos/example/lib/main.dart index c77451cde514f7fc7c62c90a6d1775ec349e7664..280836c610b6e376d8a0dd0aa73ef5dd99d8c8b3 100644 --- a/permission_handler_ohos/example/lib/main.dart +++ b/permission_handler_ohos/example/lib/main.dart @@ -49,24 +49,44 @@ class PermissionHandlerWidget extends StatefulWidget { } class _PermissionHandlerWidgetState extends State { + final PermissionHandlerPlatform _permissionHandler = + PermissionHandlerPlatform.instance; @override Widget build(BuildContext context) { - return Center( - child: ListView( - children: Permission.values - .where((permission) { - return permission != Permission.unknown && - permission != Permission.mediaLibrary && - permission != Permission.photosAddOnly && - permission != Permission.reminders && - permission != Permission.bluetooth && - permission != Permission.appTrackingTransparency && - permission != Permission.criticalAlerts && - permission != Permission.assistant && - permission != Permission.backgroundRefresh; - }) - .map((permission) => PermissionWidget(permission)) - .toList()), + return Scaffold( + backgroundColor: Colors.black.withOpacity(0.8), + body: Center( + child:Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: () async { + final boo = await _permissionHandler.openAppSettings(); + print('_permissionHandler:: boo: $boo'); + }, + child: Text('Open App Setting'), + ), + Expanded( + child: ListView( + children: Permission.values + .where((permission) { + return permission!= Permission.unknown && + permission!= Permission.mediaLibrary && + permission!= Permission.photosAddOnly && + permission!= Permission.reminders && + permission!= Permission.bluetooth && + permission!= Permission.appTrackingTransparency && + permission!= Permission.criticalAlerts && + permission!= Permission.assistant && + permission!= Permission.backgroundRefresh; + }) + .map((permission) => PermissionWidget(permission)) + .toList(), + ), + ), + ], + ), + ) ); } } diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets index 8a7c9dc032b7a59ce8b51f0a1f82e663071e345a..1a084e9ec3a4907e6c8b090b5d602575c3d31686 100644 --- a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/AppSettingManager.ets @@ -20,36 +20,35 @@ import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; import { ErrorCallback } from './ErrorCallback'; import PermissionConstants from './PermissionConstants'; import Want from '@ohos.app.ability.Want'; +import { common } from '@kit.AbilityKit'; export class AppSettingManager { - openAppSettings(ability: UIAbility | null, successCallback: OpenAppSettingsSuccessCallback, errorCallback: ErrorCallback): void { + openAppSettings(context: common.Context, ability: UIAbility | null, successCallback: OpenAppSettingsSuccessCallback, errorCallback: ErrorCallback): void { if(ability == null) { Log.d(PermissionConstants.LOG_TAG, "Context cannot be null."); - errorCallback?.onError("PermissionHandler.AppSettingsManager", "Android context cannot be null."); + errorCallback?.onError("PermissionHandler.AppSettingsManager", "Ohos context cannot be null."); return; } - bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo) => { - if (bundleInfo == null) { - successCallback.onSuccess(false); - return; - } - let want: Want = { - abilityName: 'com.huawei.hmos.settings.MainAbility', - bundleName: 'com.huawei.hmos.settings', - uri: 'application_info_entry', - parameters: { - pushParams : bundleInfo.name - } - }; - try { - ability.context.startAbility(want).then(() => { - successCallback.onSuccess(true); - }); - } catch (error) { - Log.i(PermissionConstants.LOG_TAG, "start ability exception"); - successCallback?.onSuccess(false); + + let bundleName = context.applicationInfo.name; + console.log('_permissionHandler:: bundleName: ' + bundleName); + + let want: Want = { + abilityName: 'com.huawei.hmos.settings.MainAbility', + bundleName: 'com.huawei.hmos.settings', + uri: 'application_info_entry', + parameters: { + pushParams : bundleName } - }); + }; + try { + ability.context.startAbility(want).then(() => { + successCallback.onSuccess(true); + }); + } catch (error) { + Log.i(PermissionConstants.LOG_TAG, "start ability exception"); + successCallback?.onSuccess(false); + } } } diff --git a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets index 39dfeab66bb67b813206b226883d193a2acb03f0..7b9218d79704887dc1815c0eec44bd4317b59720 100644 --- a/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets +++ b/permission_handler_ohos/ohos/src/main/ets/com/baseflow/permissionhandler/MethodCallHandlerImpl.ets @@ -89,7 +89,7 @@ export class MethodCallHandlerImpl implements MethodCallHandler { } as ESObject); break; case 'openAppSettings': - this.appSettingManager.openAppSettings(this.ability, { + this.appSettingManager.openAppSettings(this.applicationContext, this.ability, { onSuccess: (isSuccess: boolean) => { result.success(isSuccess) }