I am trying to create an app for Android 4.0.3 that listens for UDP-telegrams and starts other apps, depending on the received message.
I am already able to Launch some apps, like the "Music" app:
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
intent.SetFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
Is there any chance to do the same for the Video app?
I dont find a valid command for that. (especially WITHOUT loading a defined Video, like Action_View would do)
I was also thinking about using the StartApp, like the following:
OpenApp(context, "com.google.android.apps.maps");
But I also dont find a valid package-name for the Video app, like the other apps have.
Background:
This is for a car-project. The Android-tablet should be used as infotainment system and I want to use an "Ardoino Leonardo Ethernet" to switch between the most important app, using hardkeys instead of the touchscreen.
I prefer to avoid hardcoding any package names as doing so will cause the code to break on different APIs and different vendor's ROMs as they include their own "players" and "viewers".
You can determine which packages are installed that will response to different Uri and Mime types by using the Package Manager and making a query to it, i.e.
var activityIntent = new Intent(Intent.ActionView);
activityIntent.SetDataAndTypeAndNormalize(Uri.Parse("pseudo.mp4"), "video/mp4");
var resolvedActivityList = PackageManager.QueryIntentActivities(activityIntent, PackageInfoFlags.MatchAll);
foreach (var info in resolvedActivityList)
{
Log.Debug("SO", info.ActivityInfo.ApplicationInfo.PackageName);
}
Related
tl;dr How can you print pdfs from a .net Core 3.1 Windows Service?
I've created a simple print spooler BackgroundService class, which is being run as a Windows Service, and monitors a print queue via a web api, all very happily.
The small problem I've discovered as started to write the actual printing code is that it seems .net core doesn't want people to print documents from BackgroundService classes.
The docs for System.Printing seem to suggest this anyway.
Classes within the System.Printing namespace are not supported for use
within a Windows service or ASP.NET application or service. Attempting
to use these classes from within one of these application types may
produce unexpected problems, such as diminished service performance
and run-time exceptions.
System.Drawing.Printing has a similar note in its docs, stating that it will not work reliably for Windows Services either.
Is printing from a BackgroundService Windows Service a bad thing (tm)? Is there an obvious alternative to System.Printing / System.Drawing.Printing, that my (brief) googling has failed to find? The printing requirements should be pretty simple, I've got pdf byte array data, that I just need to get to a printer somehow).
I realise I could do something like convert the spooler to a Console app, and run it from a Scheduled Task, but the Windows Service model seemed like it'd be simpler to just install and forget (it's destined for a PC next to a printer in a warehouse)
Any helpful suggestions would be much appreciated
Incredibly, we did manage to achieve the impossible - printing PDFs from a .net Core 3.1 Windows Service.
We use the FreeSpire.PDF v5.4.0 nuget package and the following code to print pre-generated pdf data, to a Zebra Label printer.
bool printedOK = true;
string printErrorMessage = "";
try
{
PdfDocument pdf = new PdfDocument(printJobResult.printJob.PrintData);
pdf.PrintSettings.PrinterName = jobInfo.PrinterAddress;
pdf.PrintSettings.DocumentName = jobInfo.Type == PrintJobType.Label ? $"Label {jobInfo.OrderNumber}" : $"DeliveryNote {jobInfo.OrderNumber}";
if(jobInfo.Type == PrintJobType.Label)
{
pdf.PrintSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", _labelWidth, _labelHeight);
pdf.PrintSettings.SetPaperMargins(2, 2, 2, 2);
}
pdf.PrintSettings.SelectSinglePageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.FitSize, true);
_logger.LogDebug($"Paper Size - Width:{pdf.PrintSettings.PaperSize.Width} Height:{pdf.PrintSettings.PaperSize.Height} Name:{pdf.PrintSettings.PaperSize.PaperName} Kind:{pdf.PrintSettings.PaperSize.Kind} RawKind:{pdf.PrintSettings.PaperSize.RawKind}");
pdf.Print();
}
catch (Exception ex)
{
printErrorMessage = "Printing Error: " + ex.ToString();
printedOK = false;
}
Note to self - Do go and check the details of these following points...
Newer versions of the FreeSpire.PDF plugin don't allow printing, and I believe there are limits even with the 5.4.0 version (10 pages of printing I think), but for our purposes, the 5.4.0 version of the plugin has allowed us to create a tidy little delivery label print spooler, running as a Windows Service on a warehouse PC.
I did a small test for my own puposes and i did find that this works for me. My test worked for .txt and .pdf. The .png did only print some error code and unreadable text.
public Task StartAsync(CancellationToken cancellationToken)
{
FileInfo fileInfo = new FileInfo(#"c:\temp\my_pdf.pdf");
fileInfo.CopyTo(PrinterName);
return Task.CompletedTask;
}
I have to implement firebase in 2 configurations Debug and Release.
This is the reason I have removed json files and wrote code line this:
for configuration 1-
var env1 = new FirebaseOptions.Builder()
.SetApplicationId(myId)
.SetApiKey(myKey)
.SetStorageBucket(appspot.com)
.SetProjectId(myPID)
.SetDatabaseUrl(MYURL)
.Build();
var app1 = FirebaseApp.InitializeApp(Application.Context, env1, "Debug");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);
For configuration 2-
var env2 = new FirebaseOptions.Builder()
.SetApplicationId(myId)
.SetApiKey(myKey)
.SetStorageBucket(appspot.com)
.SetProjectId(myPID)
.SetDatabaseUrl(MYURL)
.Build();
var app2 = FirebaseApp.InitializeApp(Application.Context, env2, "Release");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);
Here either it is giving error like missing_google_id or firebase is not initialized.
I have tried adding string value in xml file for android,still same error.
To acieve my goal I have also tried adding multiple json files in different directories as per the link below
Xamarin firebase different google-services,json for different build configurations
but it seems it still looks for json file in root folder..
So how to implement firebase without or with json file for multiple environments
There definitely is no way to report analytics data from multiple FirebaseApp instances in a single app. See Firebase Analytics (Two projects) for single app.
If I remember correctly, Google Analytics for Firebase always reports analytics for the default FirebaseApp instance. The best reference I found for that is Use multiple firebase accounts in single android app for google analytics, but if someone has a more authoritative source I'd love to hear.
If that is the case, since each build is either Debug *or Release, you could initialize only the relevant FirebaseApp instances for the specific build target.
I've built a WPF app in C# which needs to know the user's location, and currently requires that it be entered manually. I'm using the Desktop Bridge to make it be able to run as a UWP app. When it's running as a UWP app, I want to take advantage of the Windows 10 location API if it is enabled. I'm using the following code to request for location access when the program starts:
public static async void RequestAccess()
{
var accessStatus = await Windows.Devices.Geolocation.Geolocator.RequestAccessAsync();
switch (accessStatus)
{
case Windows.Devices.Geolocation.GeolocationAccessStatus.Allowed:
UwpDesktop.hasLocationAccess = true;
break;
case Windows.Devices.Geolocation.GeolocationAccessStatus.Denied:
UwpDesktop.hasLocationAccess = false;
break;
case Windows.Devices.Geolocation.GeolocationAccessStatus.Unspecified:
MessageBox.Show("Failed to access Windows 10 location API", "Error");
UwpDesktop.hasLocationAccess = false;
break;
}
}
However I get the following error when I run my app if the location permission is not enabled for it:
System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'
The cause of this error as far as I can tell is that the RequestAccessAsync function needs to be run in the main UWP UI thread. The reason it only happens when the location permission is not enabled is because Windows tries to launch a UWP dialog requesting that the user grant location access, but fails to do so in a Desktop Bridge app.
I'm aware of two solutions to this problem. One would be to launch the Location section of the Settings app and show a messagebox to users asking them to grant location access there, which could work but I would really prefer to use the official API. The other option is to create a new UWP code project and write this code there, and then run it from the WPF app.
Microsoft has some documentation that is supposed to explain how to do the second option, but their examples are complicated and I don't know how to apply them to what I'm trying to do. I don't want to create a XAML UI or a background service, all I need is a way to safely call RequestAccessAsync and return a value based on the outcome. I'm wondering if I really need to create a UWP project to make this behave the way I want, or what the simplest way would be to go about it.
I want to populate a ListBox with the localized display names of all the installed Windows Store apps in a Windows 8 desktop app. I tried this:
string Apps = Interaction.Environ("ProgramFiles") + "\\WindowsApps";
foreach ( App in IO.Directory.GetDirectories(Apps)) {
XmlDocument xml = new XmlDocument();
xml.LoadXml(My.Computer.FileSystem.ReadAllText(App + "\\AppxManifest.xml"));
lbApps.Items.Add(xml.GetElementsByTagName("DisplayName")(0).InnerText);
}
But it adds up ms-resource strings and default apps that are uninstalled.
EDIT: I found that all the installed apps have their shortcuts in %LocalAppData%\Microsoft\Windows\Application Shortcuts but those shortcuts don't have the localized name and are non-functional when opened.
Instead of parsing the AppxManifest files directly, use the PackageManager class.
On MSDN, there are quite a few samples that demonstrate how to gather a variety of content about installed application packages, including the Enumerate app packages by user SID sample.
Did you try that: http://marcominerva.wordpress.com/2012/12/17/localizing-app-name-in-windows-store-apps/
If you set correctly the AppPackage Name on the AppDevCenter, your appx on the client side will return you the localized name.
I don't think that There are Windows Runtime APIs which can expose this particular information back to the app. The owner of app is responsible to providing the information to the Appx Manifest in the first place. whatever you can take a look there-[http://msdn.microsoft.com/en-us/library/Hh446622 ] hope something can be useful for you.
How can I programatically change the default audio device on a vista / win 7 system? Using C# or a Win API call?
The WinMM API should provide the functionality that you request.
You would use the DRVM_MAPPER_PREFERRED_SET message, which is sent with waveOutMessage() function.
Documentation: http://msdn.microsoft.com/en-us/library/aa909789.aspx
However, if you are trying to send the waveform sound out yourself, you should look at the WinMM.Net library.
http://winmm.codeplex.com
This can now (actually for quite some time already) be done very easily using the AudioSwitcher.AudioApi.CoreAudio NuGet package.
Simply create a new CoreAudioController:
var controller = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController();
Get hold of the desired device using its GUID:
var device = controller.GetDevice(Guid.Parse(...));
And lastly set it as the default playback device:
controller.DefaultPlaybackDevice = device;