index.uts 1.1 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import { OpenAppAuthorizeSettingOptions, OpenAppAuthorizeSetting, OpenAppAuthorizeSettingSuccess, OpenAppAuthorizeSettingFail, OpenAppAuthorizeSettingComplete } from "../interface.uts";
import Intent from 'android.content.Intent';
import Settings from 'android.provider.Settings';
import Uri from 'android.net.Uri';

export const openAppAuthorizeSetting: OpenAppAuthorizeSetting = function(options: OpenAppAuthorizeSettingOptions) {
	try{
		const context = UTSAndroid.getUniActivity()!!;
		const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
		const uri = Uri.fromParts("package", context.getPackageName(), null);
		intent.setData(uri);
		context.startActivity(intent);
		let result : OpenAppAuthorizeSettingSuccess = {
			errMsg:""
		}
		const completeResult : OpenAppAuthorizeSettingComplete = {
			errMsg:""
		}
		options?.success?.(result);
		options?.complete?.(completeResult);
	}catch(e){
		let result : OpenAppAuthorizeSettingFail = {
			errMsg: e.message ?? ""
		};
		const completeResult : OpenAppAuthorizeSettingComplete = {
			errMsg: e.message ?? ""
		}
		options?.fail?.(result);
		options?.complete?.(completeResult);
	}
};