I am following the documentation here:
https://learn.microsoft.com/en-us/xamarin/essentials/share?tabs=android
To implement the share functionality in my Xamarin.iOS app. My code:
byte[] pdf = await DownloadPdfFile();
var fn = "myfile.pdf";
var file = Path.Combine(FileSystem.CacheDirectory, fn);
await File.WriteAllBytesAsync(file, pdf);
await Share.RequestAsync(new ShareFileRequest
{
Title = ViewModel.Parameter.Title,
File = new ShareFile(file)
});
Nothing happens when I run this code.
My guess is you need to add some permissions in your info.plist
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos gallery for saving photos and videos.</string>
Let me know in case you have queries
I solved it. There is a bug when running on iPad as mentioned here and you can fix this by specifying the PresentationSourceBounds:
await Share.RequestAsync(new ShareFileRequest
{
Title = "My title",
File = new ShareFile(file),
PresentationSourceBounds = new System.Drawing.Rectangle((int)View.Frame.Width, 0, (int)(View.Frame.Width), (int)(View.Frame.Height))
});
Related
I downloaded the sample Сamera2 API code to my device. In another app, I want to launch a third-party camera, but I can't select the one I downloaded.
I Found solution for Xamarin.Android. I added above my CameraActivity page right near that Manifest String
[Activity (Label = "Camera2Basic", MainLauncher = true, Icon = "#drawable/icon")]
my Intent Filter which contains this code
[IntentFilter(new[] { "android.media.action.IMAGE_CAPTURE" },
Categories = new[] { Intent.CategoryDefault})]
This code write strings in Manifest, they needs for default intent call
I have this code:
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.AllowCropping = false;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
How can I implement to auto save image option when click on the capture button?
How can I implement to auto save image option when click on the capture button?
The StorageFile containing the captured photo is given a dynamically generated name and saved in our app's local folder if we do not cancel the capture, so if we click on the capture button without clicking the confirm button, the photo will be saved automatically in our app's TempState folder.
For more info, refer Capture photos and video with Windows built-in camera UI.
To better organize your captured photos, you may want to move the file to a different folder. Please refer to the following sample which shows how to copy the latest capture photo from the TempState folder to the LocalFolder.
For example:
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.AllowCropping = false;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
var allFiles =await localFolder.GetFilesAsync();
foreach (StorageFile item in allFiles.OrderByDescending(a => a.DateCreated))
{
StorageFolder destinationFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder", CreationCollisionOption.OpenIfExists);
await item.CopyAsync(destinationFolder, DateTimeOffset.Now.ToString("yyyyMMddHHmmssfff") + ".jpg", NameCollisionOption.ReplaceExisting);
await item.DeleteAsync();
return;
}
i'm developing an app based on maps.
Here my problem is i'm not able to display user location on maps. but i can able to displaying the map's using Xamarin.Forms.
Here is my Code
var map = new Map(
MapSpan.FromCenterAndRadius(
new Position(17.3660, 78.4760), Distance.FromMiles(0.3)))
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
var stack = new StackLayout { Spacing = 0 };
stack.Children.Add(map);
Content = stack;
My out put
here i want to display the user current location.
this entire code was return in Xamarin Shared code.
i'm not using Xamarin Android.
can any one help me to solve this problem.
Thanks in advance.
Most platforms require you to request permission to get a users location via GPS.
For Android this is located in the Android Manifest (under project properties). Check both ACCESS_FINE_LOCATION and ACCESS_COURSE_LOCATION.
It's a known bug on Android. It's working fine on iOS.
Here's the link to the bug report on bugzilla.
A possible workaround would be to show a map pin instead for as long as the bug hasn't been fixed. It goes like this:
map.Pins.Add(new Pin { Label = "You are here",
Position = new Position(17.3660, 78.4760) });
UPDATE: This issue has been fixed on Xamarin.Forms.Maps version 1.3.0.6292.
I'm building a mobile website which lets users upload photos from their camera.
I can get images from the users albums, and I can get images when the user takes a photo in iOS6 on iPhone4 and Android 4, but when the user takes a photo with an iPhone5 (also using iOS6), I get nothing. I can get the image from the users photo albums, but not when taking a photo.
here's the code and jsfiddle below
$('input#file_api').change(function(evt){
var image = evt.target.files[0];
var reader = new FileReader();
reader.onerror = (function(){alert('error reading file')});
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var tempImg = new Image();
tempImg.src = reader.result;
tempImg.onload = function(){
var canvas = document.createElement('canvas');
canvas.width=tempImg.width;
canvas.height=tempImg.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(tempImg,0,0);
$('body').append(canvas);
})(image);
reader.readAsDataURL(image);
I've got an example here http://jsfiddle.net/8DJUy/4/
If you use the file picker to get a photo, it will append the photo to the page.
If you take a photo with an iPhone5, it won't append anything. But at the same time, it doesn't error out either.
Any suggestions on how to get around this?
I can't quite figure out what the problem is with grabbing the photo.
The reason I'm grabbing the photos like this is that the file sizes are quite large when uploaded directly from the phone, and the use case does not require high resolution images, so I'm using the canvas to resize the image before uploading it.
Try this instead:
ctx.drawImage(tempImg, 0, 0, canvas.width, canvas.height);
I'm using a button to select an image from the Pictures folder, what I want is to save that selected image to the app's Local Storage in order to be able to show that image using binding in a GridView. Is this posible? How could I do it? Thanks
You would do it something like this:
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);
}