Xamarin.Android Camera2 API Camera don`t appears in default apps - xamarin

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

Related

How to use Share in Xamarin.iOS

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))
});

mediafilepicker: how to gain access to selected file

Hi I am new to nativescript and i am trying to select video files, i was trying to use nativescript-mediafilepicker, it successfully opens the folders but i am not sure how to select a file using the same programatically.
let mediafilepicker = new Mediafilepicker();
mediafilepicker.openImagePicker(options);
mediafilepicker.on("getFiles", function (res) {
let results = res.object.get('results');
console.dir(results);
})
mediafilepicker.on("error", function (res) {
let msg = res.object.get('msg');
console.log(msg);
});
mediafilepicker.on("cancel", function (res) {
let msg = res.object.get('msg');
console.log(msg);
});
Thanks in advance
You won't have any control on the selection UI / videos as it will be a system or third party app that was opened through Intent, which is totally outside your app context.
If you like more control over every user action in picker UI, then you will probably have to build one yourself. There are few open source iOS / Android libraries that may probably support this feature, you can extend them to NativeScript if you are familiar with plugins architecture.

Mozilla add-on and var {Cc, Ci, Cu} = require("chrome");

i new in Mozilla addons.
I make addon who use option to off images and scripts. Used code:
let button_img = ToggleButton({ id: "btn2", label: "Show/hide images", icon: "./img1.png", onChange: imgChange});
var {Cc, Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
var PrefBranch = Cc["#mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
button_img_is_cecked=0;
function imgChange(state) {
if (state.checked) {//Blocking images
button_img.icon="./img2.png";
PrefBranch.setIntPref("permissions.default.image",2);//Disable images
PrefBranch.setIntPref("permissions.default.script",2);//Disable script
button_img_is_cecked=1
}else {
button_img.icon="./img1.png";
PrefBranch.setIntPref("permissions.default.image",1);//enable images
PrefBranch.setIntPref("permissions.default.script",1);//enable script
button_img_is_cecked=0
}
}
Code and addon works correctly, but when I send addon to checking I receive message:
Usage of flagged or non-SDK interface
Warning: This SDK-based add-on uses interfaces that aren't part of the SDK or are flagged as sensitive.
var {Cc, Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
I have other variants to off images and scripts without using this imported resource?
Also this code off images for all tabs in Mozilla. Can I do it jost for one tab where my addon works?
You should be able to get and set preferences using this low-level sdk module:
https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/preferences_service
So your code would probably look like:
var gPrefs = require("sdk/preferences/service");
...
gPrefs.set("permissions.default.image",1);
gPrefs.set("permissions.default.script",1);

IsShowingUser not working in Xamarin Forms

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.

Can we generate QR code through Xamarin

I am developing an Android app in xamarin in which I require to create a QR code from the data input by the user in various fields.
SO my question is can I do it with the help of Xamarin? If yes then please help me with any sample code or tutorial link.
ZXing.Net has a QR code generator built in. Take a look at that.
Something like this could do the job (following code not tested):
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions
{
Height = 200,
Width = 600
}
};
var bitmap = writer.Write("My content");
This should generate an image with the QR code. There are loads of other options you can mess with.
ZXing is also available as a component for Xamarin.Android, Xamarin.iOS and Windows Phone

Resources