How to capture image from camera without user interaction using Xamarin iOS - xamarin.ios

I want to capture series of images based on the device orientation (using compass) but my specific requirement is to capture automatically without the need to manually taking photos which is the only way i could find possible.
Im using Xamarin.Mobile library and also tried Medai Plugin from Xamarin components .
if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
{
var mediaOptions = new Media.Plugin.Abstractions.StoreCameraMediaOptions()
{
Directory = "Receipts",
Name = "test.jpg"
};
var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
}

Related

How to detect that iOS App was launched for first time by specific user (not on specific device)?

I am using in my App cloudKit + Core Data in my App (iOS 13+) (swift).
I cannot figure out how to detect very first run of the app regardless of device to initialize some default data.
There are many posts how to detect first launch of a iOS app on specific device - that's easy. I cannot find solution for detecting the first run of app for specific user or in other words - if in user's iCloud does exist initialized container with specific containerIdentifier.
If user had already used the app on another device before, so during first launch on new device, there will be sync with iCloud and app will use user's data. But if the user has never used the app before I need to initialize some data.
I am searching for clue how to deal with it for hours, cannot find nothing relevant.
Any idea?
Thanks for help in advance.
A bit more information on your cloudkit schema would help, but assuming you are using a publicDB to store information, a unique record will be create for the user when they first take an action that saves data to cloudkit.
So you could check and look at the createDate timestamp of the User object in cloudkit and compare to the current time (a bit clunky, but possible).
Example code to fetch the user:
iCloudUserIDAsync { (recordID: CKRecord.ID?, error: NSError?) in
if let userID = recordID?.recordName {
self.loggedInUserID = userID
self.loggedInWithiCloud = true
} else {
self.loggedInWithiCloud = false
print("Fetched iCloudID was nil")
}
}
Alternatively, and more elegantly, you could write a boolean flag to the user object CloudKit (or locally in CoreData) on first launch. Then on any launch get the entire user object for the logged in iCloud user, you can then initialize it and then act on your Boolean variable from there.
Example code to get the full user and initialize it locally:
CKContainer.default().publicCloudDatabase.fetch(withRecordID: userRecordID) { (results, error ) in
if results != nil {
//now that you have the user, you can perform your checks
self.currentUser = MyUser(record: results!)
}
if let error = error {
print("couldn't set user reference")
}
DispatchQueue.main.async {
completion(nil)
}
}

Auto focus camera without preview

I am running Win10 IoT on a pi 2. I need to be able to take pictures that are focused but cannot get the focus working. The application is a background app so I don't have a way of previewing the camera on a display. Is there any way of doing this? Currently I have
await _mediaCapture.StartPreviewAsync();
_mediaCapture.VideoDeviceController.FocusControl.Configure(new FocusSettings
{
Mode = FocusMode.Continuous,
WaitForFocus = true
});
await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
await _mediaCapture.StopPreviewAsync();
but I am getting the error
WinRT information: Preview sink not set
when I try to focus. All of the examples I've seen online show that the preview is output to a control and I assume it wires a sink up automagically. Is there a way to do this manually through code? Possibly without the preview?
I wonder if the code may work even without FocusControl.
I propose you follow Customer Media Sink implementation example and use of StartPreviewToCustomSinkIdAsync method described at http://www.codeproject.com/Tips/772038/Custom-Media-Sink-for-Use-with-Media-Foundation-To
I didn't find a way to do this. I ended up converting the background app to a UI app with a Page containing a CaptureElement control in order to preview and focus.
Instead of adding a UI, just create a CaptureElement and set the source to the _mediaCapture before calling await _mediaCapture.StartPreviewAsync();
Something like:
_captureElement = new CaptureElement { Stretch = Stretch.Uniform };
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(...);
_captureElement.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();

How to get the file path and file name of image captured from firefox camera in Firefox OS (ZTE device)

I am using Web activity to launch default Firefox camera from my web app in Firefox OS. Able to launch default Firefox camera and took picture. Got this.result as return value inside pick success.
Now I need to get file path, where image get saved and also image file name.
Tried to parse the this.result.blob, but couldn't find the path or file related parameter .
Below is the code I'm using
var activity = new MozActivity({
// Ask for the "pick" activity
name: "pick",
// Provide the data required by the filters of the activity
data: {
type: "image/jpeg"
}
});
activity.onsuccess = function() {
var picture = this.result;
console.log("A picture has been retrieved");
};
The image file name is not returned, as you can see from the code. If you would need the file name (I can't really think of a very good use case to be honest) you can iterate over the pictures storage in the DeviceStorageAPI and get the last saved file. It's probably the one from the camera (compare blobs to be totally sure).
In your success handler, you will get the file name if you use:
this.result.blob.name
And, you can get the path to the file as:
window.URL.createObjectURL(this.result.blob);
Source

For testing GPS based J2ME app, Is there any emulator which have built in GPS?

I am new in J2ME app development field. I am developing GPS based app using Nokia Maps for series 40 mobiles. I want such emulator which provide GPS(to retrieve & set current coordinates & many other purposes). I search a lot on google but I didn't found such emulator.... even what ever emulators provide by Nokia SDKs; they also don't have GPS capability... Then how should I get such emulator??
You can download the latest Nokia IDE (which includes the Nokia Maps Plugin) here:
Emulator download
The emulator associated with the SDK includes tools to simulate JSR-179 location calls (e.g. Cell-Id/GPS), you can play back coordinates for a saved file and receive them at regular intervals. Look at the emulator's Tools > Route Editor menu.
The confusion here is the difference between GPS positioning and Cell-Id positioning. There are currently no series 40 mobiles (that I know of) with a GPS unit - hence positioning will need to be done by Cell-ID - In this case the only way to retrieve frequent location updates in the Cell-ID scenario is to call the getLocation() method within a repeating loop. Retrieving location objects via the locationUpdated() method, can only be done in a GPS-based location retrieval.
In summary you can get a location from any Java ME phone supporting JSR-179, you won't be using GPS though.
To get a location use the following:
cellIdLocator = getCellIdProvider();
cellIdLocator.getLocation(DEFAULT_TIMEOUT);
Where the cell-id provider can be held in a singleton
private LocationProvider cellIdLocator;
public LocationProvider getCellIdProvider() throws LocationException {
if (cellIdLocator == null) {
int[] methods = {
Location.MTA_ASSISTED | Location.MTE_CELLID
| Location.MTY_NETWORKBASED};
cellIdLocator = LocationUtil.getLocationProvider(methods, null);
}
return cellIdLocator;
}

Flex - how to download a string variable as a file to the local machine?

I have a String variable in my flex (flash builder 4) application containing CSV data. I need to allow the user to download this data to a local file. For example, giving them a "csv" button to click and it might present them with a save file dialog (and I would be sending the contents of my string variable).
Is this possible / how ?
I am using the ResuableFX component for the datagrid to csv. This the code I ended up with that works to save the string to a text file for the user (in a web browser):
var dg2CSV:DataGrid2CSV = new DataGrid2CSV();
dg2CSV.includeHeader=true;
dg2CSV.target=adgEncounters;
var csvText:String=dg2CSV.getCSV();
var MyFile:FileReference = new FileReference();
var csvFileNameDT:String = QuickDateFormatter.format(new Date().toString(),"YYYYMMDDJJNNSS");
MyFile.save(csvText,"Encounters"+csvFileNameDT+".csv");
If you're in an AIR App you can use File.browseForSave().
If you're in a web app, you can use FileReference.save() . The FileReference docs have a lot more info on this.
In many cases, I would recommend using navigateToURL() to open the file outside of Flash and let the browser deal with it.
I'm not sure if there is a way to do this without user interaction.

Resources