I am new to unity and want to connect a page of application in market or any other apps, so I used some script in other threads but it didn't work so I think it need some change in Android manifest too for script to work.
my script is like this and a button in game run it's function.
bool fail = false;
string bundleId = "bazaar://details?id=" + "cab.snapp.passenger"; // your target bundle id
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{ //open app in store
Application.OpenURL("https://google.com");
}
else //open the app
ca.Call("startActivity", launchIntent);
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
I changed string bundle but it didn't work and look forward beside solution for this problem if there is any way to use intent with Uri for openning another app in unity c#.
Related
I am trying to Embed VLc in Winform Application on .net core 3.1 framework. Packages installed are
**
LibVLCSharp 3.6.1
LibVLCSharp.WinForms 3.6.1
**
private void PlayerForm_Load(object sender, EventArgs e)
{
var url = typeof(LibVLC).Assembly.Location;
Core.Initialize();
using(var libvlc = new LibVLC())
using (var mediaPlayer = new MediaPlayer(libvlc))
{
var uri = new Uri("C:\\Active Projects\\ScreenPlayerWeb\\ScreenPlayerWeb\\wwwroot\\Videos\\VID_20190621_112556.3gp");
using var media = new Media(libvlc, uri);
mediaPlayer.Fullscreen = true;
mediaPlayer.Play();
}
}
Core.Initialize() Giving Exception
**
LibVLCSharp.Shared.VLCException: 'Failed to load required native libraries.
Have you installed the latest LibVLC package from nuget for your target platform?
Search paths include C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlccore.dll; C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlccore.dll; C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc.dll,'
**
Its searching for wrong file in my devug/netcore3.1 folder there is no file as libvlc.dll ...
files avaialble are libvlcsharp.dll, libvlcsharp.winforms.dll and vlc.dotnet.core.dll.
There are answers on stack overflow but most of these are more than 5 years old so cant be referenced to updated versions of LIbVlc and .Net
Help will be highly appriciated.
The package doesn't include the actual 'libvlc' as you might expect, its only initialization code in the LibVLCSharp. Ensure you installed the VideoLAN.LibVLC.[YourPlatform] package in your target project. Or download it manually and point towards the folder:
Core.Initialize(#"C:\yourpath\libvlc\win-x64");
var libvlc = new LibVLC();
// Make VideoView control
VideoView vv = new VideoView();
vv.MediaPlayer = new MediaPlayer(libvlc);
vv.Dock = DockStyle.Fill;
// Add it to the form
Controls.Add(vv);
var uri = new Uri(#"C:\Video.mp4");
// Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
var media = new Media(libvlc, uri, ":input-repeat=65535");
vv.MediaPlayer.Play(media);
//Set fullscreen
this.FormBorderStyle = FormBorderStyle.None;
this.Size = Screen.PrimaryScreen.Bounds.Size;
this.Location = Screen.PrimaryScreen.Bounds.Location;
I try to open location settings in android using this tutorial, but in this method:
public void OpenSettings()
{
}
I don't know what to write to openned location settings.
Do I need additional libraries ?
I write this code:
public interface ILocSettings
{
void OpenSettings();
}
public void OpenSettings()
{
}
In the GPS button method I write this code:
var myAction = await DisplayAlert("Location", "Please Turn On Location", "OK", "CANCEL");
if (myAction)
{
if (Device.RuntimePlatform == global::Xamarin.Forms.Device.Android)
{
//DependencyService.Get<ISettingsService>().OpenSettings();
global::Xamarin.Forms.DependencyService.Get<ILocSettings>().OpenSettings();
}
else
{
_ = DisplayAlert("Device", "You are using some other shit", "YEP");
}
}
else
{
_ = DisplayAlert("Alert", "User Denied Permission", "OK");
}
So the message appear, but I don't know what to write in the OpenSettings() to open GPS location settings on the phone..
There is a package that will make opening the App settings way easier.
just write:
CrossPermissions.Current.OpenAppSettings();
Plugin name Plugin.Permissions :)
Opening other Activities on Android is done through Intents. To open Location Settings you can use the ACTION_LOCATION_SOURCE_SETTINGS intent.
Something like this would probably work:
var intent = new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings);
Android.App.Application.Context.StartActivity(intent);
If Android doesn't like the Application Context, you might need to resolve the top Activity and use that as your Context instead.
If you are using Xamarin.Essentials you can get the top activity with: Platform.CurrentActivity:
var intent = new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings);
Platform.CurrentActivity.StartActivity(intent);
I am writing a small app that installs IIS and configures a website before deploying the files to it.
On a freshly reset Windows 10, the first attempt always fails with the 0x80040154 COM+ component failure as documented in This question
I looked at the version I am using and it is the latest and correct one for .net standard (4.8) and not the one meant for .net core
When I press the button to rerun the function it always finishes correctly. I tried using a retry routine, and it fails on each retry, yet runs fine again when the button is pressed. The reason for this I assume is that the server manager object isn't disposed when it hits the catch block since its in a using statement.
I can work around that, but I really want to understand the issue and make a permanent fix.
My routine simply creates a website in IIS and creates an app pool to assign to it.
And it is running with elevated privileges
For reference:
Machine is Windows 10 latest from the downloadable media creator.
Microsoft.Web.Administrator version is 7.0.0.0
App is .net 4.8 standard windows forms
using (var serverManager = new ServerManager())
{
string iisrootdir = drive;
//Check for inetpub/wwwroot
if (!Directory.Exists(iisrootdir)) //Check for Drive D
{
iisrootdir = #"C:\";
}
string iiscmsdir = Path.Combine(iisrootdir, "webdir", "appdir");
if (!Directory.Exists(iiscmsdir))
Directory.CreateDirectory(iiscmsdir);
var settings = new ApplicationSettings();
settings.ReadFromFile();
settings.CMSPATH = iiscmsdir;
settings.SaveToFile();
try
{
string poolName = "DefaultAppPool";
if (serverManager.Sites.Count > 0)
{
Site myDefualtWebsite = serverManager.Sites[0];
if (myDefualtWebsite != null)
{
OnRaiseInstallEvent(new InstallEventArgs("CreateWebsite", ProcessState.Started,
"Remove Default Website"));
serverManager.Sites.Remove(myDefualtWebsite);
serverManager.CommitChanges();
}
}
if (!WebsiteExists("sitename"))
{
mySite.ServerAutoStart = true;
}
Site site = serverManager.Sites["sitename"];
if (!AppPoolExists(poolName))
{
serverManager.ApplicationPools.Add(poolName);
}
ApplicationPool apppool = serverManager.ApplicationPools[poolName];
apppool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
apppool.ManagedRuntimeVersion = "";
serverManager.Sites["sitename"].ApplicationDefaults.ApplicationPoolName = poolName;
foreach (var item in serverManager.Sites["sitename"].Applications)
{
item.ApplicationPoolName = poolName;
}
serverManager.CommitChanges();
apppool.Recycle();
serverManager.CommitChanges();
}
catch (Exception ex)
{
if (ex.Message.Contains("80040154") && errorCount < 4)
{
if (serverManager != null)
serverManager.Dispose();
errorCount++;
OnRaiseInstallEvent(new InstallEventArgs("CreateWebsite", ProcessState.Started,
"Error encountered with COM+ object, trying again: " + errorCount));
CreateWebsite(#"D:\");
}
else
{
if (serverManager != null)
serverManager.Dispose();
errorCount = 0;
OnRaiseErrorEvent(new InstallErrorEventArgs("CreateWebsite", ProcessState.Error, ex));
return false;
}
}
finally
{
serverManager?.Dispose();
}
Thanks for the help Guys. I found the problem.
DISM was running in its own thread. The Process object exited the moment it launched. My function was then attempting to configure IIS before it had finished installing.
I have a Xamarin Project where I generate a .pdf file from scratch and save it in my local storage. This works perfectly fine and can find it and open it in the disk where I saved it. However, I need to open the .pdf file immediately after creation programmatically.
I already tried different variations using Process and ProcessStartInfo but these just throw errors like "System.ComponentModel.Win32Exception: 'The system cannot find the file specified'" and "'System.PlatformNotSupportedException'".
This is basically the path I am trying to open using Process.
var p = Process.Start(#"cmd.exe", "/c start " + #"P:\\Receiving inspection\\Inspection Reports\\" + timestamp + ".pdf");
I also tried ProcessStartInfo using some variations but I'm getting the same errors all over and over.
var p = new Process();
p.StartInfo = new ProcessStartInfo(#"'P:\\Receiving inspection\\Inspection Reports\\'" + timestamp + ".pdf");
p.Start();
The better way is that use LaunchFileAsync method to open file with browser. You could create FileLauncher DependencyService to invoke uwp LaunchFileAsync method from xamarin share project.
Interface
public interface IFileLauncher
{
Task<bool> LaunchFileAsync(string uri);
}
Implementation
[assembly: Dependency(typeof(UWPFileLauncher))]
namespace App14.UWP
{
public class UWPFileLauncher : IFileLauncher
{
public async Task<bool> LaunchFileAsync(string uri)
{
var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(uri);
bool success = false;
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not
}
return success;
}
}
}
Usage
private async void Button_Clicked(object sender, EventArgs e)
{
await DependencyService.Get<IFileLauncher>().LaunchFileAsync("D:\\Key.pdf");
}
Please note if you want to access D or C disk in uwp, you need add broadFileSystemAccess capability. for more please refer this .
Update
If the UWP files are network based, not local zone based, you could use Xamarin.Essentials to open file with browser. And you must specify the privateNetworkClientServer capability in the manifest. For more please refer this link.
I'm trying to use the Twitter Service from the UWPCommunityToolkit, which I have running as a standalone UWP (Universal Windows Platform) app, but when I import it into Unity (2017.2.0f3) as a library, it doesn't open the authentication window.
This is what shows up on the working standalone UWP app:
When in unity, it seems to go through the setup code, but not run this line properly:
var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);
https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.Services/Services/Twitter/TwitterDataProvider.cs#L293
It just returns WebAuthenticationStatus.UserCancel, whereas on the standalone UWP, it'd return WebAuthenticationStatus.Success. Note, it also returns WebAuthenticationStatus.UserCancel on the standalone UWP app when the user clicks the close button on the pop up.
Is it possible to run WebAuthenticationBroker.AuthenticateAsync (https://learn.microsoft.com/en-us/windows/uwp/security/web-authentication-broker) in Unity? Are there any other ways to do web authentication on the Windows platform using Unity?
I've also tried TwitterKit, but unfortunately, it doesn't have support for Windows UWP (only iOS and Android).
Thanks!
LINQ to Twitter supports UWP. It has a UniversalAuthorizer that works like this:
private async void TweetButton_Click(object sender, RoutedEventArgs e)
{
var authorizer = new UniversalAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = "",
ConsumerSecret = ""
}
};
await authorizer.AuthorizeAsync();
var ctx = new TwitterContext(authorizer);
string userInput = tweetText.Text;
Status tweet = await ctx.TweetAsync(userInput);
ResponseTextBlock.Text = tweet.Text;
await new MessageDialog("You Tweeted: " + tweet.Text, "Success!").ShowAsync();
}
Check out the Samples folder for a complete listing: https://github.com/JoeMayo/LinqToTwitter