Skip to content

Commit

Permalink
Merge pull request #13 from punisher-303/patch-4
Browse files Browse the repository at this point in the history
Android 13 & 14 Song Offline Download Issue Fixed
  • Loading branch information
HemantKArya authored Jul 21, 2024
2 parents aa16914 + e416b7f commit a83e95e
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';

class DownloadSettings extends StatefulWidget {
const DownloadSettings({super.key});
Expand All @@ -16,6 +17,36 @@ class DownloadSettings extends StatefulWidget {
State<DownloadSettings> createState() => _DownloadSettingsState();
}

Future<bool> storagePermission() async {
final DeviceInfoPlugin info =
DeviceInfoPlugin(); // import 'package:device_info_plus/device_info_plus.dart';
final AndroidDeviceInfo androidInfo = await info.androidInfo;
debugPrint('releaseVersion : ${androidInfo.version.release}');
final int androidVersion = int.parse(androidInfo.version.release);
bool havePermission = false;

if (androidVersion >= 13) {
final request = await [
Permission.videos,
Permission.photos,
//..... as needed
].request(); //import 'package:permission_handler/permission_handler.dart';

havePermission =
request.values.every((status) => status == PermissionStatus.granted);
} else {
final status = await Permission.storage.request();
havePermission = status.isGranted;
}

if (!havePermission) {
// if no permission then open app-setting
await openAppSettings();
}

return havePermission;
}

class _DownloadSettingsState extends State<DownloadSettings> {
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -110,7 +141,7 @@ class _DownloadSettingsState extends State<DownloadSettings> {
},
),
onTap: () async {
final hasStorageAccess = Platform.isAndroid
/*final hasStorageAccess = Platform.isAndroid
? await Permission.storage.isGranted
: true;
if (!hasStorageAccess) {
Expand All @@ -120,6 +151,9 @@ class _DownloadSettingsState extends State<DownloadSettings> {
return;
}
}
}*/
final permission = await storagePermission();
debugPrint('permission : $permission');
FilePicker.platform.getDirectoryPath().then((value) {
if (value != null) {
context.read<SettingsCubit>().setDownPath(value);
Expand Down

0 comments on commit a83e95e

Please sign in to comment.