Attempting to write app that retrieves images from local storage (camera roll) on Android Mobile device. All research suggests using MediaStore.Images to accomplish this. Unable to get clean compile as keep getting error 'object cannot be found'
This is statement producing error : MediaStore.Images.Media.ExternalContentUri;
Also :
string path = cursor.GetString(cursor.GetColumnIndex(
MediaStore.Images.ImageColumns.Data));
Tried declaring separate Interface declaration to no avail
I believe these classes are defined in Android dll which I have reference to.
Very frustrating to a long time C# developer looking to write cross-platform Mobile apps.
looked for sample code on net that would illustrate solution showing exactly how to access/declare/use MediaShow.Images to no avail.
Surprised there does not appear to be a single example of a full solution illustrating its use
Related
I am trying to convert a windows desktop application from WinUI 2 to WinUI 3. However, I am having a problem with the Windows.Storage.ApplicationData class. When I call ApplicationData.Current (so I can access a file in the app's local data store or to get a local setting) a System.TypeInitializationException exception is thrown.
The following screenshot shows the problem:
System.TypeInitializationException
(This is a default application that I created in Visual Studio 2022 using the project template "Blank App, Packaged (WinUI 3 in Desktop)", the only change I made was to add the line to get the current ApplicationData object in the App class's OnLaunched() method:
var appData = Windows.Storage.ApplicationData.Current;)
Any idea what I am doing wrong here? I think maybe there is a trust or cababilities issue, or I should use other methods to get the app's local data folder or settings for a WinUI 3 desktop application.
I encountered the same problem recently. No matter where I made the call in my WinUI 3 application, whenever I invoked a call to the ApplicationData API, I would always encounter the same exact exception (System.TypeInitializationException with an inner COMException). I failed to find an answer in the API documentation, particularly where one would hope to find such an answer. (If it's there, it's buried or perhaps easily overlooked by someone who is not as familiar with .NET programming, such as myself.) The following line of code always threw an exception for me:
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
The solution that worked for me was something I learned from a response to an issue on the WindowsAppSDK GitHub repository. To quote the information I found most relevant to the issue I was having:
A client that is not running in an App Container must open ApplicationData using this API: https://learn.microsoft.com/en-us/uwp/api/Windows.Management.Core.ApplicationDataManager?view=winrt-22000, while a client that is running in an App Container must open ApplicationData using this API instead: https://learn.microsoft.com/en-us/uwp/api/windows.storage.applicationdata?view=winrt-22000
Basically, I learned that I needed to open ApplicationData using the ApplicationDataManager class. As noted from the GitHub link, the solution I found was to replace the offending line of code with the following:
var localSettings = ApplicationDataManager.CreateForPackageFamily(Package.Current.Id.FamilyName).LocalSettings;
From there I can save and load app settings as usual, which is suitably explained here:
localSettings.Values["test setting"] = "a device specific setting";
String localValue = localSettings.Values["test setting"] as string;
Hopefully this helps anyone who finds themselves facing the same issue.
Scratch that, the problem only happens if in the debugger I put a breakpoint on the "ApplicationData.Current" line. Very weird. I think I am having the same problem as here:
Getting values of ApplicationData.Current.LocalSettings in static context
Here's what I've done so far:
I wrote a little C# class library to run GET requests to a REST API.
I compiled it, made sure that it worked within another c# application before trying to import this thing into my webpage. Pulled what I wanted to, worked like a charm whilst operating within another c# console app.
I followed this guide to make sure my dll was COM interoperable and reachable:
http://timheuer.com/blog/archive/2007/03/10/14009.aspx
Now, I was given this PHP webpage by someone else, and while I am not an expert in PHP, from what I've gathered it doesn't take much to be.
The only real important stuff is here:
function APIGet($url) {
$object = new COM("API_Call.ApiCaller");
$result = $object->cURLGET($token, $url);
return $result;
}
I wrote that into my function file, which has many other functions that work just fine on the page. The dll contains the namespace API_Call and a public static class, ApiCaller, as well as some other classes that aren't used here.
So then I go to call it on the actual page itself here:
$output = APIGet($apicall);
echo $output;
From which I get this error (edited for readability):
Fatal error: Uncaught com_exception: Failed to create COM object `API_Call.ApiCall':
Invalid syntax in C:\xampp\htdocs\canvasAPI.php:32
Stack trace: #0 C:\xampp\htdocs\canvasAPI.php(32):
com->com('API_Call.ApiCal...') #1 C:\xampp\htdocs\CAForm.php(169):
APIGet('api/v1/courses') #2 {main} thrown in C:\xampp\htdocs\canvasAPI.php on line 32
I have my file, canvasAPI.php with all my functions in it and then the CAForm.php file is the form itself. I've searched high and low for an answer here, but everything either says make the class library COM visible and interoperable, or to enable [COM] com.allow_dcom in php.ini, both of which I already did.
For anyone googling this, I just ended up using C# the whole way. I didn't see a point in continuing down the path of messing with custom COM objects in PHP.
According to the docs, OpenHardwareMonitor should publish 2 class (Hardware and Sensor) to the WMI but I cannot see any. I OpenHardwareMonitor has full read & write access to WMI so I'm not sure what's wrong. Am I even going about it the right way and should you be able to see those classes?
EDIT
Probably a cause of the same problem but when attempting to use the namespace OpenHardwareMonitor in my c# app
using OpenHardwareMonitor;
it does not recognise it
I forgot to add the .dll to my resources. Rookie error
I am an iOS developer which has been asked to do development in Xamarin. I want to log the outputs in Xamarin.
I am trying to find a library for this. I found one library for this called MetroLog.
Link : https://github.com/onovotny/MetroLog
But the problem is I am getting blue coloured output for every log level.Like this:
I was expecting that the errors would be in red , warnings would be in orange, and others in green or blue or something, but I could not get the required output in the manner I thought I would. I am running sample project from their repo , which has source code as follows:
_log.Info("Information - We are about to do magic!");
_log.Warn("Warning!");
_log.Trace("Trace some data.");
_log.Error("Something bad happened at {0}", DateTime.Now);
_log.Fatal("Danger Will Robinson!");
Are there some changes that I need to make to the logging project when it has been added to my project?
Is there any other library which can solve my use case for logging ?
If not then how can I achieve similar and coloured option from MetroLog ? I am open to other options(open source project) as well.
MORE INFO or EXTENDED QUESTION:
As I am used to iOS development I used to use the following statements in order to log the information:
NSLog(#"%# %# started" ,[self class] ,NSStringFromSelector(_cmd));
NSLog(#"%# %# ends " ,[self class] ,NSStringFromSelector(_cmd));
I am expecting some sort of quick logging option like the one for iOS as shown above without including any library. Is that possible?( including the class name and the method name which is executing the code)
Thanks.
I have not use MetroLog but, in general, such libraries requires you to set a destination / endpoint / server for your logs. The default one is often the basic one offered by the OS (which is the one that Xamarin Studio will redirect) and that won't give you coloured output.
Quick Logging: Every string given to System.Console.WriteLine ends up calling NSLog on iOS. Since that's part of mscorlib.dll (SDK) there's nothing else you'll need to add to your project to use it.
Hello fellow programmers.
I recently made a mistake while using the SQLite-NET package for Windows Phone 8.1. When opening a new SQLiteConnection, I would give as parameter to its constructor the string "data.db", without being actually aware of what was going on under the hood. Later on, I noticed that the file wouldn't be deleted, even if I uninstalled the application (since I would have in my app the same entries that I had before uninstalling it); I assume that I should be using the local folder for application data instead.
However, here is the real question: what the hell is the folder where the data.db file was created? I tried to figure it out with the following piece of code:
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///data.db"));
System.Diagnostics.Debug.WriteLine(file.Path);
and what I got as output of the WriteLine method was the path
C:\Data\SharedData\PhoneTools\AppxLayouts\f7529f24-ba24-4fdb-8353-cff9214180a0VS.Debug_ARM.Valbrand\data.db,
which only got me even more confused. I couldn't find any satisfactory info on this, and I would REALLY like to further my understanding of what happened here.
Thanks in advance!
The path you are looking at is the install directory of your app. You have a Silverlight 8.1 app, so the path is slightly different than a Silverlight 8.0 app, but the articles here and here will help you get a rough understanding.
The recommended usage of this directory is to take the resources that you want backed up out of it on first run and move them to the app data container, so they can be backed up by the system.
C:\Data\SharedData\PhoneTools\AppxLayouts\f7529f24-ba24-4fdb-8353-cff9214180a0VS.Debug_ARM.Valbrand\data.db
This is the path on your phone/emulator.
And This is not the location where you can find in your PC.