Closed erdoganabaci closed 4 years ago
You need to create file firstly, and then provide the path to the plugin. Something like this:
final client = HttpClient();
final _downloadData = <int>[];
final directoryPath = (Platform.isAndroid
? await getExternalStorageDirectory()
: await getApplicationDocumentsDirectory())
.path;
final fileSave = File('$directoryPath/${name}');
fileSave.create(recursive: true);
client
.getUrl(Uri.parse(url)
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
response.listen((d) => _downloadData.addAll(d), onDone: () async {
await fileSave.writeAsBytes(_downloadData);
if (await DeviceApps.isAppInstalled('com.instagram.android')) {
InstagramShare.share(fileSave.path, isImage ? 'image' : 'video');
}
});
});
I'm checking the Instagram app using the DeviceApps(https://pub.dev/packages/device_apps)
@erdoganabaci Does it help you?
this answer did not help, in fact i want to share like esys_flutter_share but i want to make it special only for instagram.I want it to work on both ios and android like esys_flutter_share.I shared example code in my github account.Can you look the codes ? This is link where I need share with instagram work in ios and android. => https://github.com/erdoganabaci/flutterShareExample If link doesnt redict just copy the browser
I don't have support for iOS as I write it on dart pub :) But maybe I will support it later. Using the different things for ios. I will write it tomorrow.
Can you support for ios too as soon as possible? This is so important for me. How did esys_flutter_share flutter package do it for both ios and android?
This is open source project, so I will work on it in my free time, cannot set any predictions, sorry.
ср, 24 июн. 2020 г. в 23:52, Erdogan Abacı notifications@github.com:
Can you support for ios too as soon as possible? This is so important for me. How did esys_flutter_share flutter package do it for both ios and android?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JEuler/instagram_share/issues/1#issuecomment-649065129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYUDUQVMEDSR5ESWLAFGLRYJRRVANCNFSM4N7XXAHQ .
-- Terekhin Ivan
You can use this code for iOS direct share:
if (await Permission.photos.request().isGranted) {
final mediaId = await ImageDownloader.downloadImage(url);
final instagramUrl = 'instagram://library?LocalIdentifier=$mediaId';
if (await canLaunch(instagramUrl)) {
try {
final instagramUrl = 'instagram://library?LocalIdentifier=$mediaId';
await launch(instagramUrl);
} on PlatformException {
// do something
}
} else {
// do something
}
} else {
// do something with permissions
}
}
This uses the https://pub.dev/packages/permission_handler, https://pub.dev/packages/image_downloader, https://pub.dev/packages/url_launcher
I am using that in my own project - sharing for ios is working. You can check for Platform using the Platform.isIOS (or something like that).
first of all thank you for your time. Can you also share canLaunch and launch methods ? Would you share all of the running code example, if you have ?
In addition how can I share video url final mediaId = await ImageDownloader.downloadImage(url);
I think this is only work for images ?
You can use it for videos also. :) This is example code is fully working. As I said, you need to use mentioned libs.
canLaunch is from https://pub.dev/packages/url_launcher
hi again, I tested your code but couldnt work with url.Could you look my codes in github ? => https://github.com/erdoganabaci/flutterShareExample If link doesnt redict just copy the browser
I will have a look after work day.
Thank you for your help, I would be glad if you look at it in the day
Sorry, I don't have time today, tough working day. will try to have a look tomorrow, thx.
чт, 25 июн. 2020 г. в 11:55, Erdogan Abacı notifications@github.com:
Thank you for your help, I would be glad if you look at it in the day
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
-- Terekhin Ivan
So, I've checked your problem. It is not related to my package, you just need to add the NSPhotoLibraryUsageDescription to the Info.plist. Actually, you need to follow the setup guide here https://pub.dev/packages/image_downloader.
@erdoganabaci Does it help?
No it doesn't help
But it is working on my side, I have tested your project.
ср, 1 июл. 2020 г. в 14:07, Erdogan Abacı notifications@github.com:
No it doesn't help
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JEuler/instagram_share/issues/1#issuecomment-652354252, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYUDTWJ3BPTRWBA5O2G2LRZMKITANCNFSM4N7XXAHQ .
-- Terekhin Ivan
Can you send me the codes that work on you? Can you send me the demo app soruce code?
Here you go - https://github.com/JEuler/flutterShareExample.git
сб, 4 июл. 2020 г. в 01:56, Erdogan Abacı notifications@github.com:
Can you send me the codes that work on you?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JEuler/instagram_share/issues/1#issuecomment-653691867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYUDS3L5BWRPWZKWRSUF3RZZO3FANCNFSM4N7XXAHQ .
-- Terekhin Ivan
It gives an error.It was making such an error before.I have already install instagram but it couldnt share with instagram ??
You asked me for the iOS example, and you are running it on Android. :)
сб, 4 июл. 2020 г. в 13:07, Erdogan Abacı notifications@github.com:
It gives an error.It was making such an error before
[image: issue error] https://user-images.githubusercontent.com/43154455/86510295-2a271e80-bdf7-11ea-9173-6e00d60f2690.png
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JEuler/instagram_share/issues/1#issuecomment-653747205, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYUDWLVMBYJRGBSG3JQXLRZ35ORANCNFSM4N7XXAHQ .
-- Terekhin Ivan
No, I want to work with both platform ios and Android. How can I do?
I don't understand. I said, that this plugin not working with iOS. You need to use a workaround. I submitted the workaround in the repo, it is working for iOS as you wanted.
I will not write all the code you need. For iOS you should use the code which I show you today. You can check platform by using
if (Platform.isAndroid) {
// Android-specific code
} else if (Platform.isIOS) {
// iOS-specific code
}
That code can be used to download and share img for Android.
final client = HttpClient();
final _downloadData = <int>[];
final directoryPath = (Platform.isAndroid
? await getExternalStorageDirectory()
: await getApplicationDocumentsDirectory())
.path;
final fileSave = File('$directoryPath/${name}');
fileSave.create(recursive: true);
client
.getUrl(Uri.parse(url)
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
response.listen((d) => _downloadData.addAll(d), onDone: () async {
await fileSave.writeAsBytes(_downloadData);
if (await DeviceApps.isAppInstalled('com.instagram.android')) {
InstagramShare.share(fileSave.path, isImage ? 'image' : 'video');
}
});
});
So, I'm closing it for now. Looking forward to add native ios support for this plugin :)
I want to use your plugin but my images comes from network so I convert url to path then share my images to directly instagram ios and android.Can you help me how can I share images from url for instagram?
Uint8List bytes = await consolidateHttpClientResponseBytes(response);
InstagramShare.share(bytes.toString(), "image/jpg");