Requesting notification permission in unity not showing native dialog, auto declining - c#

calling
Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS", permissionCallbacks);
however the native dialog never appears, and the PermissionDenied callback is called. have deleted the app data and uninstalled so the permission hasn't been set. If i call the RegisterNotificationChannel the native dialog does appear...
var general = new AndroidNotificationChannel()
{
// use the app id as the default ID
Id = GeneralChannelId,
Name = "General",
Importance = Importance.High,
Description = "General Game Notifications",
};
general.CanShowBadge = true;
general.EnableVibration = true;
AndroidNotificationCenter.RegisterNotificationChannel(general);
but i can't hook onto that native dialog to see there decision. Any help appreciated
target SDK set to latest installed (33)
tried calling Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS", permissionCallbacks);
expect a native dialog to appear, followed by a PermissionGranted or PermissionDenied callback depending on the choice.
dialog isn't appearing, permissionDenied being called.

Related

Type password automatically for RDP connection (CredentialUIBroker)

As an exercise, I'm trying to automate typing RDP credentials using FlaUI.
My OS is Windows 10.
I'm able to start mstsc.exe and type into this window:
But then I get this window and I can't find it anywhere:
It's not an mstsc window, even though it appears above it as a modal window: mstsc always has just one window.
Apparently it's a window of "Credential Manager UI Host", but that process has... zero windows.
Even in task manager it's listed in the background tasks and not in the applications section.
FlaUI Inspect doesn't see it at all.
By the way, this is my code:
var CurrentAutomation = new UIA3Automation();
var Process = Application.Attach(Process.GetProcessesByName("CredentialUIBroker")[0]);
var Windows = Process.GetAllTopLevelWindows(CurrentAutomation); // 0 elements
How can I get a handle to this window and access its textbox using FlaUI?
It turns out it was just a matter of knowing the name of the "window", which is Credential Dialog Xaml Host; also, it can be found using FlaUI Inspect.
Once the mstsc part is done and the "Windows Security" window comes out, you can go on with this sample code:
// Declare all variables, which might be method parameters instead
var Password = "MyLamePassword";
var MaxTimeout = new TimeSpan(10 * 1000 * 2000);
var CurrentAutomation = new UIA3Automation();
var Desktop = CurrentAutomation.GetDesktop();
// Get the window, using a Retry call to wait for it to be available
var CredentialWindow = Retry
.WhileEmpty(
() => Desktop.FindAllDescendants(f => f.ByClassName("Credential Dialog Xaml Host")),
timeout: MaxTimeout,
throwOnTimeout: true)
.Result[0];
// Get the password box
AutomationElement PasswordBox = null;
Retry.WhileNull(
() => PasswordBox = CredentialWindow.FindFirstDescendant(f => f.ByName("Password").And(f.ByControlType(ControlType.Edit))),
timeout: MaxTimeout,
throwOnTimeout: true);
// Type the password
PasswordBox.FocusNative();
Keyboard.Type(Password);
// I have some Retry code here too, just to check that the password is actually typed, and type Enter after it.
CurrentAutomation.Dispose();

How to prevent Alert Dialog from being shut down

I am using c# and Xamarin.Android.
I want to create an app, and when it realized it has a new version, it will let user download the new version and force itself off.
So I used AlertDialog.
My code:
if (NeedUpdate)
{
alertDialog = null;
builder = new AlertDialog.Builder(this);
alertDialog = builder
.SetTitle("New Version")
.SetMessage("please update the app to the latest version.")
.SetPositiveButton("OK", (s, e) =>
{
})
.Create(); //Create alertDialog
alertDialog.Show();
var dialog = new AlertDialog.Builder(this);
}
In my code, NeedUpdate is a variable to store whether there's a new version.
But the question has begun.
In this app, the AlertDialog is translucent.
So the user can click on the translucent area to close it (without triggering the event I wrote).
I just want to ask, how to avoid user to close it without triggering the event I wrote, or if that's a event for what I said?
I admit, it's a very bad idea that force my users to update the app.
But I just want to know how to achieve it.
Who have solutions?
PS:Some parts of the article is translated by machine, include this sentence.
Well i guess you could do the following
alertDialog.SetCancelable(false);
Also if the above is what you want have you checked the Google Play core's playstore update plugin?

C# White UI Automation: can't find SWT window

I'm using White for UI automation and it was working fine until I met an app that was created in Java. In that case I'm unable to find any windows. If I get all Windows from the desktop then I can see the window's name I'm looking for:
List<White.Core.UIItems.WindowItems.Window> windows = new List<White.Core.UIItems.WindowItems.Window>();
windows = White.Core.Desktop.Instance.Windows();
int a = 0;
for (int i = 0; i < windows.Count; i++)
if (windows[i].Name == "HP Service Manager Client") a = i;
This is working, but if I attach the running process and try to get its windows, then I get nothing, the list will be empty:
windows=app.GetWindows();
This is the code that should find the main window:
var processes = Process.GetProcessesByName("ServiceManager");
White.Core.Application app = White.Core.Application.Attach(processes[0]);
White.Core.UIItems.WindowItems.Window main = app.GetWindow(SearchCriteria.ByText("HP Service Manager Client"), InitializeOption.NoCache);
The error I get: Additional information: Couldn't find window with SearchCriteria Name=HP Service Manager Client in process 7396, after waiting for 5000 ms
I can see the Window in VisualUIAVerify and I know that the name of it is correct.
This is the only app which is not working, IE, Firefox, etc. are all working fine, I can always identify the main window, but this time I can't find any windows at all.
I wonder if someone could explain me why it is doing this and help me to resolve this issue (or find a workaround). Many thanks in advance.

Automatically install updates with ClickOnce deployment

I wanted to deploy my project with ClickOnce deployment. But when I did it like that, it was asking in a dialog box at the end user machine:
A new version of XXXX is available. Do you want to download it now?
But my end users don't have a mouse or keyboard. So my intention is: It must take the updates automatically, but it must NOT ask that dialog box at the client side. How do I achieve this by using ClickOnce deployment?
Looks like you can do this by changing some properties in the build.
http://blog.jnericks.com/configuring-msbuild-to-auto-update-clickonce
MinimumRequiredVersion - Tells ClickOnce that when it updates this
application it should update to this version (however this does not
force ClickOnce to perform the update). As you can see we set this
to the same version number that the ApplicationVersion is set to so
that the MinimumRequiredVersion is always the latest version.
UpdateMode=Foreground - Tells ClickOnce to update the application
before it is opened.
UpdateRequired=True - Tells ClickOnce to automatically perform the
update.
No MSBuild scenario:
Right Click your project and select Properties
Go to the "Publish" tab on the bottom left
Click the "Updates..." button to open the Application Updates dialog
Check "The application should check for updates"
Select "Before the application starts"
Check "Specify a minimum required version for this application"
Enter the Publish Version that you can see in the underlying Publish window as the minimum version. Unfortunately, you have to change this every publish. There might be a way for this to be auto, though.
Then publish the application and test it. This was worked fine for me on a local test application.
Edit: looks like some people have been getting the minimum required version to update, might want to look into their solutions.
Edit 2: Image showing where versioning is important:
Also, note I have "Automatically increment revision with each publish" checked. Every time you go into the Properties for the project, that version will be up to date. You'll generally just have to change the "Revision" part of the Version in the "Application Updates" window to match the "Revision" in the Publish tab.
Sure can! As long as it's a network-deployed application, you can easily check for updates using this code. See below:
Private Sub InstallUpdates()
Dim info As UpdateCheckInfo = Nothing
If (ApplicationDeployment.IsNetworkDeployed) Then
Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Try
info = AD.CheckForDetailedUpdate()
Catch dde As DeploymentDownloadException
(You may want to log here)
Return
Catch ioe As InvalidOperationException
(You may want to log here)
Return
End Try
If (info.UpdateAvailable) Then
Try
AD.Update()
Application.Restart()
Catch dde As DeploymentDownloadException
(You may want to log here)
Return
End Try
End If
End If
End Sub
You can enter this snippet and call it in the startup. It works in console applications, Windows Forms applications, but only if you are network deployed! Where you see all my comments about logging is where I was originally using message boxes with prompts, but this is the version that doesn't require any input!
In addition to Gromer's answer, simply install the AutoUpdateProjectsMinimumRequiredClickOnceVersion nuget package in your project. Once you have your project set to check for updates and to use a minimum required version, this will handle making sure the minimum required version always matches your current version (i.e. user's will always be forced to update to the latest version).
Any ClickOnce application based on an .exe file can be silently installed and updated by a custom installer. A custom installer can implement custom user experience during installation, including custom dialog boxes for security and maintenance operations. To perform installation operations, the custom installer uses the InPlaceHostingManager class.
For implementing this solution please refer to this link
I know it's an old Q. but, I will answer anyway. (hope it will help someone):
First, you need to check: Choose when the application should check for updates >> After the application starts.
Secondly, add this method to your code:
private Boolean isVersionOK()
{
UpdateCheckInfo info = null;
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
try
{
info = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException)
{
// No network connection
return false;
}
catch (InvalidDeploymentException)
{
return false;
}
catch (InvalidOperationException)
{
return false;
}
if (info.UpdateAvailable)
{
try
{
ad.Update();
Application.Restart();
Environment.Exit(0);
}
catch (DeploymentDownloadException)
{
// No network connection
}
return false;
}
return true;
}
else
{
return false;
}
}
Lastly, you just need to call isVersionOK() at the start of your app and in every few loops as needed to check for update. it will return TRUE if you are on your latest version otherwise it will return FALSE and expect the app will restart to a newer version automatically without user interaction.
In follow-up of Ahmed's answer, below is the code in VB.NET with minor enhancements. It might not be as per the best practices yet it is readable and descriptive.
''' <summary>
''' Checks if the update is available for network based deployment and download it.
''' </summary>
''' <param name="autoDownloadUpdate">If the update is available, should it be downloaded automatically.<para>Default value is <code>True</code></para></param>
''' <returns>It will return <code>True</code> only if the latest version is already installed.
''' <para>If autoDownloadUpdate is set to <code>True</code>, the update is auto downloaded (and app restarts and nothing is returned) else it returns <code>False</code>.</para>
''' </returns>
Shared Private Function CheckAndDownloadUpdate(ByVal Optional autoDownloadUpdate As Boolean = True) As Boolean
If ApplicationDeployment.IsNetworkDeployed = False Then Return False
Dim appDeployment As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Dim info As UpdateCheckInfo = Nothing
Try
info = appDeployment.CheckForDetailedUpdate
Catch ex As Exception
' Exceptions if you want to handle individually
'DeploymentDownloadException ' No network connection
'InvalidDeploymentException
'InvalidOperationException
Return False
End Try
' If no update is available, it means latest version is installated
If info.UpdateAvailable = False Then Return True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If we are here, it means an update is available on the network
' if autoDownload is False, simply return False
If autoDownloadUpdate = False Then Return False
Try
appDeployment.Update()
Application.Restart()
Environment.Exit(0)
Catch ex As DeploymentDownloadException
' No network connection
Return False
End Try
End Function
An then in your startup code, you can call like this
CheckAndDownloadUpdate()
Any feedback to further ehance the answer...

How to correctly display a dialog from a MSTest method in VS 2010?

I recently upgraded an MSTest project to .NET 4.0 and VS 2010. Several of the tests query an outside vendor service and thus prompt the user for necessary credentials to communicate through our corporate web proxy. This used to work fine in vs2008 but after the upgrade the dialog will only display if the user switches focus from VS to another app immediately after kicking off the tests. Is there anything special that needs to be done when displaying the dialog? The best I can figure is that there is some WPF caveat that got introduced with the redesign of VS.
The code in question
private void PromptUser()
{
if (!credentialsSet)
{
using (CredentialsDialog dialog = new CredentialsDialog(true))
{
Process process = Process.GetCurrentProcess();
IWin32Window window = Control.FromHandle(process.MainWindowHandle);
DialogResult dr = dialog.ShowDialog(window);
if (dr == DialogResult.Cancel)
{
throw new InvalidOperationException("Credentials not entered");
}
credentials = dialog.Credentials;
user = dialog.Username;
password = dialog.Password;
domain = dialog.Domain;
}
credentialsSet = true;
}
}
I would sugest that requiring the credentials is bad practice. Have you conidered adding your credentials in an excrypted fasion to the config of the test assembly.
You will run into a lot of problems if you try to setup this for automated build.
You may need to activate the dialog in order to get it to pop up over whatever programs you have active.
using (CredentialsDialog dialog = new CredentialsDialog(true))
{
Process process = Process.GetCurrentProcess();
IWin32Window window = Control.FromHandle(process.MainWindowHandle);
dialog.Activate();
DialogResult dr = dialog.ShowDialog(window);
// ...
}
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate.aspx

Categories

Resources