lubritto / flutter_share Goto Github PK
View Code? Open in Web Editor NEWA Flutter plugin for IOS and Android providing a simple way to share a message, link or local files.
License: MIT License
A Flutter plugin for IOS and Android providing a simple way to share a message, link or local files.
License: MIT License
when share pdf through android it work perfect but when share pdf through gmail in ios it show subject same as text we passed but it should show title as subject.
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method share on channel flutter_share)
Thanks for the plugins..
I want to redirect the user after they shared a file . However, it seems that the callback occurs when the sheet is shown and not after the action is completed (selecting the application and sharing the file)
is this possible?
I tried to use flutter_share to share an image with description as a LinkedIn Post, but the image won't be attached in the post.
Facebook for example works perfectly.
What do I have to change so that LinkedIn works too? Or does it need an other solution than flutter_share?
Thanks for help!
Future shareFile2(tempDir) async {
await FlutterShare.shareFile(
title: 'Title',
text: 'This is the description.',
filePath: '${tempDir.path}/myImage.png'
);
}
When I use this along with other file-based plugins such as ImagePicker, the file providers will conflict with each other. In order to fix this, i've had to create a new Java class for the provider like this:
package com.example.my_app;
import androidx.core.content.FileProvider;
public class ShareFileProvider extends FileProvider {}
and declare the provider in AndroidManifest.xml
like this:
<provider
android:name="com.example.my_app.ShareFileProvider"
android:authorities="${applicationId}.share_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
flutter share causes ipad devices to close host app without any error messages. I tested on ipad mini 2 Model MF075LL/A with iOS 12.4.4 and ipad Model MP2H2LL/A with iOS 13.3.
i have added provider in AndroidManifest.xml like below
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
then i build the apk and decompile it, i found that my provider not exists and it replace by
<provider
android:name="io.flutter.plugins.imagepicker.ImagePickerFileProvider"
android:exported="false"
android:authorities="com.example.fire.flutter.image_provider"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@ref/0x7f0c0000" />
</provider>
i have used the plugin of image_picker,
maybe the config replace by image_picker.
can you tell me how to solve the problem?
I added androidx.core.content.FileProvider
and provider_paths.xml
, but still encountered such an error:
E/DatabaseUtils(22545): Writing exception to parcel
E/DatabaseUtils(22545): java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.example.app.provider/external_files/Android/data/com.example.app/files/test.json from pid=22857, uid=1000 requires the provider be exported, or grantUriPermission()
E/DatabaseUtils(22545): at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
E/DatabaseUtils(22545): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
E/DatabaseUtils(22545): at android.content.ContentProvider$Transport.query(ContentProvider.java:231)
E/DatabaseUtils(22545): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
E/DatabaseUtils(22545): at android.os.Binder.execTransactInternal(Binder.java:1021)
E/DatabaseUtils(22545): at android.os.Binder.execTransact(Binder.java:994)
Hi,
I use the shareFiles method in a very simple example:
final tempDir = await getTemporaryDirectory();
final Uint8List fileContent = <someBytes>
final targetPath =
"${tempDir.path}${"/$fileNameForFile${h4uFileType.fileExtension}"}";
File(targetPath).writeAsBytesSync(fileContent);
await Share.shareFiles([targetPath], text: text, subject: subject);
When I share a pdf file on my iPhone and then select the iOS option "Save to Files" two documents are saved to the selected directory. One file is the expected pdf file and the other an empty document called "Text":
Any help for this issue?
Thanks in advance!
Best regards
I was having success when the file to share was located on the android external storage. I elected to move my files from an external storage location to the Application Document Directory, located using getApplicationDocumentsDirectory(). I did this so I can deploy to iOS which does not allow access to external storage. I can write the file to:
/data/user/0/com.PlantListGPSv1.Android.PlantListGPSv1/app_flutter/Backup/Backup 2020-08-12@20_18.pgps
placing the above full path into a string variable _fullPathName, and running the code below,
///
print('Full path name: $_fullPathName');
FlutterShare.shareFile(
title: _fileName,
text: 'Plant List GPS File:' + _fileName,
filePath: _fullPathName,
);
///
I get a debug console message and this error message
Full path name: /data/user/0/com.PlantListGPSv1.Android.PlantListGPSv1/app_flutter/Backup/Backup 2020-08-12@20_18.pgps
Exception has occurred.
PlatformException (PlatformException(Failed to find configured root that contains /data/data/com.PlantListGPSv1.Android.PlantListGPSv1/app_flutter/Backup/Backup 2020-08-12@20_18.pgps, null, null))
====
In trying to troubleshoot what FutterShare stopped working I find that my code runs without problem on iOS which has me thinking something changed with Android. I currently have an app working on Google play, build at the end of July with Android 28. After this post, I moved to Android 29 and I can remember when exactly things started breaking, but was soon after I started working in Android 29. I found that my permission-handler plugin went from permission_handler: '^4.2.0+hotfix.2' to permission_handler: ^5.0.1+1 which was a major change. I suspect internal storage, external storage, shared storage(new?) has changed too and could be the root cause of why the flutter_share stopped working with the path provide by getApplicationDocumentsDirectory. I offer this insight to help other to thing in this direction if a cause has not yet been found.
I have developed a work-around as sharing files is important to my app. In a high level, my app reads from the ApplicationDocumentDirectory and writes the file to ExternalStorageDirectory when flutter_share works. Below is an extract of my code that is working for me. I have logged a provider error message that I do not understand, but since flutter_share works, I'm not sure how relevant the exception is, and would appreciate any help in resolving it.
//permission_handler: ^5.0.1+1
Future<String> askStoragePermission() async {
var permission = await Permission.storage.request().isGranted;
if (permission) {
return 'Ok';
} else {
print('Storage permission denied');
return 'Not OK';
}
}
Future<void> shareFile(_subDir, _fileName) async {
final String _fullPathName = await getShareFileFullPath(_subDir, _fileName);
print('Find file at: \n$_fullPathName');
await FlutterShare.shareFile(
title: _fileName,
text: 'PLGPS File:' + _fileName,
filePath: _fullPathName,
);
}
Future getShareFileFullPath(String _subDir, String _fileName) async {
String _fullPathName, _rootDir, _storagePermission;
Io.Directory _storDir;
if (Platform.isAndroid) {
// work around FlutterShare not able to read App Doc Dir
// get file to re-write to external Storage
_storDir = await getApplicationDocumentsDirectory();
_rootDir = _storDir.toString();
_fullPathName =
_rootDir.substring(12, _rootDir.length - 1) + _subDir + _fileName;
print('$_fullPathName');
final _myFile = new Io.File(_fullPathName);
final String _fileData = await _myFile.readAsString(); // have file read
//
// write file to external storage so it can be shared
_storagePermission = await _iOX.askStoragePermission();
print('Storage permission: $_storagePermission');
var _path = await ExtStorage.getExternalStorageDirectory();
_subDir = 'Test';
final String _plgpsDirPath = _path + '/$_subDir/';
Io.Directory(_plgpsDirPath)
.create(recursive: true)
.then((Io.Directory directory) {});
final String _fullPathFileName = _plgpsDirPath + _fileName;
new File(_fullPathFileName).writeAsString(_fileData);
print('File written to:\n$_fullPathFileName');
return _fullPathFileName;
}
// iOS and other OS routine
else {
Io.Directory _storDir = await getApplicationDocumentsDirectory();
_rootDir = _storDir.toString();
_fullPathName = _rootDir.substring(0, _rootDir.length - 1) +
_subDir +
"/" +
_fileName;
print('$_fullPathName');
return _fullPathName;
}
}
AndroidManifest.xml highlights
I'm not sure about the following error message. The share process powers through the Permission denied exception. I suspect sharing between routines is not happening, but not familiar enough with the topic to know the issue. Maybe someone who knows can chime in to help with the reported issue. Thanks.
Debug Console:
I/flutter (23897): /data/user/0/com.PlantListGPSv1.Android.PlantListGPSv1/app_flutter/Backup/Backup 2020-08-14@21_14.pgps
I/flutter (23897): Storage permission: Ok
I/flutter (23897): File written to:
I/flutter (23897): /storage/emulated/0/Test/Backup 2020-08-14@21_14.pgps
I/flutter (23897): Find file at:
I/flutter (23897): /storage/emulated/0/Test/Backup 2020-08-14@21_14.pgps
I/.PlantListGPSv(23897): NativeAlloc concurrent copying GC freed 7847(424KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1589KB/3179KB, paused 44.346ms total 466.370ms
E/DatabaseUtils(23897): Writing exception to parcel
E/DatabaseUtils(23897): java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.PlantListGPSv1.Android.PlantListGPSv1.provider/external_files/Test/Backup%202020-08-14%4021_14.pgps from pid=21487, uid=1000 requires the provider be exported, or grantUriPermission()
E/DatabaseUtils(23897): at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
E/DatabaseUtils(23897): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
E/DatabaseUtils(23897): at android.content.ContentProvider$Transport.query(ContentProvider.java:231)
E/DatabaseUtils(23897): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
E/DatabaseUtils(23897): at android.os.Binder.execTransactInternal(Binder.java:1021)
E/DatabaseUtils(23897): at android.os.Binder.execTransact(Binder.java:994)
Sharing using FlutterShare.shareFile gives an error popup, when I select instagram post, story or message.
Only occurs on iOS
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="_{myAppID}_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
I made a nw file in src/res/xml/provider_paths.xml with the following content
The application works in iOS simulator both post error in android simulator
ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Couldn't find meta-data for provider with authority - list my application id.
I'm using the package up to date but I'm getting this warning, there's no problem with my app working but I just wanted to let you know.
......\Pub\Cache\hosted\pub.dev\flutter_share-2.0.0\android\src\main\java\com\example\fluttershare\FlutterSharePlugin.java
uses or overrides a deprecated API.
Hi,
Can we change the package name com.example => flutter.dev, or something more official?
Thanks.
I get this error when running as it as my as Web App:
Uncaught MissingPluginException(No implementation found for method share on channel flutter_share)
Does this mean there is no web support? Because if I were to believe this page, it should support web: https://pub.dev/packages/flutter_share
PlatformException(Failed to find configured root that contains /file:/storage/emulated/0/project/1590844068701.png, null, null)
I'm facing this exception while sharing image file. I had added path provider code in AndroidMinifest.xml file, make new file provider_path.xml in src/xml/...
Any solution please.
IOS whatsapp image share not working but android working well
When I share the file via email, the file is sent along with the title and text. But when I share it on WhatsApp the file is not sent and also the title is not sent.
my code:
`var status = await Permission.storage.request();
if (status.isGranted) {
final baseStorge = await getExternalStorageDirectory();
final file = '${baseStorge!.path}/$fileName';
final response = await Dio().download(url, file);
if (response.statusCode == 200) {
final share = await FlutterShare.shareFile(
title: 'Proposta: $taskTitulo',
text: 'Cliente: $taskClienteName',
filePath: file,
);
if (share == true) {
NotificationService().showNotification(
title: 'Proposta Guardado',
body: 'A sua proposta "$taskTitulo", foi guardado com sucesso.',
);
}
} else {
myMessage("ERROR!⛔.");
}`
When trying to share a JPEG file, it works fine on Facebook and GMail, but no file is sent to LinkedIn (only the text is) and Instagram just opens (while sharing to feed) or not even open (while sharing to stories).
Has anyone had experiences in sharing files through those social medias?
Hi, it seems there is a swift header file missing? My XCode build fails with the following output. Using version 0.0.4
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET sqflite OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/benbieker/Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_share-0.0.4/ios/Classes/FlutterSharePlugin.m:2:9: fatal error: 'flutter_share/flutter_share-Swift.h' file not found
#import <flutter_share/flutter_share-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Launching lib/main.dart on ASUS X00TD in debug mode...
Note: /home/aryan/Documents/development/flutter/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/android/src/main/java/fr/g123k/deviceapps/DeviceAppsPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 37.0s
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk... 22.9s
After this nothing happens my app doesnt open at all I have completed the initial setup
App is crashing but I cant get whats the reason
Flutter 1.17.1 • channel stable •
https://github.com/flutter/flutter.git
Framework • revision f7a6a7906b (11 days ago) •
2020-05-12 18:39:00 -0700
Engine • revision 6bc433c6b6
Tools • Dart 2.8.2
When I try to share video it is downloaded from flutter_downloader plugin, and it says file not support error,
can someone please help me with that.
Thanks
[general] Connection to daemon was invalidated
2020-04-10 10:22:55.475056-0700 Runner[12846:792761] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<UIPopoverPresentationController: 0x10b0c6540>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
*** First throw call stack:
(0x1b43b2164 0x1b40c6c1c 0x1b7da7088 0x1b7db1424 0x1b7daef3c 0x1b8505c10 0x1b84f513c 0x1b852688c 0x1b432cc54 0x1b43278e4 0x1b4327d84 0x1b4327660 0x1be738604 0x1b84fc15c 0x100bc8328 0x1b41a31ec)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
await FlutterShare.share(
title: 'Example share',
text: 'Example share text',
linkUrl: 'https://flutter.dev/',
chooserTitle: 'Example Chooser Title',
);
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-US)
• Flutter version 1.12.13+hotfix.9 at /Users/grandleaf/Development/flutter
• Framework revision f139b11009 (11 days ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/grandleaf/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4, Build version 11E146
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.44.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.9.1
[✓] Connected device (1 available)
• xxxx iPad • xxxxxxxxxxxxxxxxxx • ios • iOS 13.4
There is no way to except 'title' property?
I don't want display title...
Because the README says the package was discontinued there should be no way to create new issues/PRs, also to warn users they should not rely on flutter_share
anymore, this repo should be archived.
Hi,
I use flutter_share to share a file in my App. Now I want to automate this step. Is it possible to save the destination the user choosed at the first call and to call the methode the next time with this destination?
So something like this:
await FlutterShare.shareFile(
**destination: '$destination',**
title: 'Test',
text: 'Automation',
filePath: '$path'
Thanks for your help!
It would be nice if something along these lines was possible:
final image = ...; // gets the reference from already existing in-memory image
FlutterShare.shareFile(title: 'My Image', file: image);
I tried to test out your pluging today, and I get this error, only by adding the dependency it's already triggered:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.android.support:appcompat-v7' has different version for the compile (27.1.0) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.