flutter_downloader
flutter_downloader copied to clipboard
openFileFromNotification not working
When download is finished, the notification show a Complete status, when i click on it, it doesn't open the file. Here's my code:
app.dart
FlutterDownloader.enqueue(
url: url,
headers: {'Authorization': user.token},
fileName: fileName,
savedDir: localPath,
showNotification: true,
openFileFromNotification: true,
);
AndroidManifest.xml
<manifest>
<application>
....
....
<provider
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
android:authorities="${applicationId}.flutter_downloader.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
</manifest>
What can be the problem?
Hi, I am also facing this issues but now fixed:
Dont mind, It is code from my project, just check relevant functionality for downloading task.
import 'dart:isolate';
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:chewie/chewie.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:office_mngmnt/application/addToFavouriteLogic.dart';
import 'package:office_mngmnt/application/postList.dart';
import 'package:office_mngmnt/presentation/elements/boldCaption.dart';
import 'package:office_mngmnt/presentation/elements/heigh_sized_box.dart';
import 'package:office_mngmnt/presentation/elements/lightCaption.dart';
import 'package:office_mngmnt/presentation/elements/loading_widget.dart';
import 'package:office_mngmnt/presentation/helper/appKeys.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';
const debug = true;
class PostsCard extends StatefulWidget {
final String postID;
final String title;
final String authorName;
final String postType;
final String postFile;
final String authorDp;
final String date;
final VoidCallback onImageTap;
final VoidCallback onFavouriteBtnClick;
final bool isSavedPost;
PostsCard(
{@required this.postID,
@required this.title,
@required this.postType,
@required this.authorName,
@required this.onImageTap,
@required this.postFile,
@required this.authorDp,
@required this.onFavouriteBtnClick,
this.isSavedPost = false,
@required this.date});
@override
_PostsCardState createState() => _PostsCardState();
}
class _PostsCardState extends State<PostsCard> {
AddToFavouriteLogic _addToFavouriteLogic = AddToFavouriteLogic();
VideoPlayerController _controller;
ChewieController _chewieController;
ReceivePort receivePort = ReceivePort();
int progress = 0;
@override
void initState() {
IsolateNameServer.registerPortWithName(
receivePort.sendPort, "downloadingVideo");
receivePort.listen((message) {
setState(() {
progress = message;
});
});
FlutterDownloader.registerCallback(downloadCallback);
// TODO: implement initState
if (widget.postType == AppKeys.videos)
_chewieController = ChewieController(
videoPlayerController: VideoPlayerController.network(
widget.postFile,
),
aspectRatio: 7 / 8,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: false,
// Errors can occur for example when trying to play a video
// from a non-existent URL
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
);
super.initState();
}
static downloadCallback(id, status, progress) {
SendPort sendPort = IsolateNameServer.lookupPortByName('downloadingVideo');
sendPort.send(progress);
}
@override
Widget build(BuildContext context) {
var postsID = Provider.of<PostsIDList>(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(widget.authorDp),
),
title: BoldCaption(widget.authorName),
subtitle: LightCaption(widget.date),
trailing: widget.isSavedPost
? Container(
height: 1,
width: 1,
)
: Row(
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
onTap: () => widget.onFavouriteBtnClick(),
child: Icon(
_addToFavouriteLogic.isFavouritePost(context,
postID: widget.postID)
? Icons.favorite
: Icons.favorite_border,
color: Colors.red[500],
)),
InkWell(
onTap: () {
_downloadFile();
},
child: Icon(
Icons.download_sharp,
color: Colors.red[500],
)),
],
),
),
LightCaption(widget.title),
VerticalSpace(10),
getPostDisplay(),
VerticalSpace(15),
Divider(),
],
),
);
}
getPostDisplay() {
if (widget.postType == AppKeys.photos) {
return Container(
width: MediaQuery.of(context).size.width,
child: CachedNetworkImage(
imageUrl: widget.postFile,
errorWidget: (context, val, _) {
return Icon(Icons.error);
},
fit: BoxFit.fitWidth,
placeholder: (context, url) =>
Container(height: 200, child: Center(child: LoadingWidget())),
));
} else if (widget.postType == AppKeys.videos) {
return Chewie(
controller: _chewieController,
);
} else if (widget.postType == AppKeys.docs) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blue),
borderRadius: BorderRadius.circular(10)),
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Image.asset(
"assets/images/docs.png",
height: 50,
),
),
);
}
}
@override
void dispose() {
// TODO: implement dispose
if (widget.postType == AppKeys.videos)
// _videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
_downloadFile() async {
final status = await Permission.storage.request();
if (status.isGranted) {
final baseStorage = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: widget.postFile,
savedDir: baseStorage.path,
);
} else {
print("No permission");
}
}
}
Try this one it might resolve your issue.
Credit : https://www.youtube.com/watch?v=dBDKwZeaTj0
In Android 11 it doesn't open, but in other versions it's open the file from the notification
In android 10 also file is not opening from notification!
Facing the same issue. The file is'nt opening from Notifications. Further there is some issue with the directory in which the file is being stored. I have externally requested permission to write to external storage and have included the relevant tags in Manifest.xml but still I cannot save the downloaded file to some othe external folder.
For Flutter_Downloader
If you are using API 29+(ANDROID 10 and Above) add the below code in AndriodManifest.xml
android:requestLegacyExternalStorage="true"
Like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
...........
<application
..............
<!-- Add This line -->
tools:replace="android:label"
android:requestLegacyExternalStorage="true"> <!-- Add This line if you are targeting android API 29+-->
<activity>
...............
</activity>
</application>
</manifest>
We're running into the same issue. The recommend solution doesn't seem to work.
also having the same issue with android 10, for android 11 and up it's working fine and i can open from notification like normal. my app is targetting API 33. Using manage external storage works but google play console won't tolerate it. The recommend solution doesn't seem to work. Any fix?