package com.example.vnote_device_plugin_example;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;

import java.util.ArrayList;

import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        initPermission();
        super.onCreate(savedInstanceState);
    }

    // todo 蓝牙动态申请权限
    private void initPermission(){
        ArrayList<String> mPermissionList=new ArrayList<>();
//        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
//            // Android 版本大于等于 Android12 时
//            // 只包括蓝牙这部分的权限，其余的需要什么权限自己添加
//            mPermissionList.add(Manifest.permission.BLUETOOTH_SCAN);
//            mPermissionList.add(Manifest.permission.BLUETOOTH_ADVERTISE);
//            mPermissionList.add(Manifest.permission.BLUETOOTH_CONNECT);
//        } else {
//            // Android 版本小于 Android12 及以下版本
//            mPermissionList.add(Manifest.permission.ACCESS_COARSE_LOCATION);
//            mPermissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
//        }

        mPermissionList.add(Manifest.permission.BLUETOOTH_SCAN);
        mPermissionList.add(Manifest.permission.BLUETOOTH_ADVERTISE);
        mPermissionList.add(Manifest.permission.BLUETOOTH_CONNECT);
        mPermissionList.add(Manifest.permission.ACCESS_COARSE_LOCATION);
        mPermissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);

        if(mPermissionList.size() > 0){
            ActivityCompat.requestPermissions(getActivity(),mPermissionList.toArray(new String[0]),1001);
        }
    }

}
