How to prevent Alert Dialog from being shut down - c#

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?

Related

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

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.

How to get Selenium to operate two browser windows using only one driver selenium (using c# and chromedriver)?

I am attempting to control two browser windows via selenium using c# and a single chromedriver. The reason being that I need to share session details accross browser windows.
The code that I have tried and failed with is below;
var options = new ChromeOptions();
options.AddArguments("chrome.switches", "--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling --disable-infobars --enable-automation ");
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
options.PageLoadStrategy = PageLoadStrategy.Default;
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
var Driver = new ChromeDriver(service, options);
//THIS WILL OPEN A NEW WINDOW. BUT BECAUSE IT IS A NEW DRIVER DOES NOT WORK FOR SHARING SESSION DETAILS.
//var TestDriver = new ChromeDriver(service, options);
//TestDriver.Manage().Window.Maximize();
//THIS JUST OPENS UP A NEW TAB. NOT A NEW WINDOW (IT WOULD SEEM MOST DOCUMENTATION SUGGESTS THAT IT SHOULD)
IJavaScriptExecutor jscript = Driver as IJavaScriptExecutor;
jscript.ExecuteScript("window.open();", "google.com.au");
//TRY USING THE SEND KEYS TECHNIQUE. NOTHING HAPPENS
var test = Driver.FindElement(By.TagName("html"));
test.SendKeys(Keys.Control + "n");
test.SendKeys(Keys.Control + "t");
//TRY AGAIN USING THE SEND KEYS TECHNIQUE USING A DIFFERENT TAG. NOTHING HAPPENS
var blah = Driver.FindElements(By.TagName("body"));
blah[0].SendKeys(Keys.Control + "t");
//TRY USING ACTIONS. NOTHING HAPPENS
Actions action = new Actions(Driver);
action.SendKeys(OpenQA.Selenium.Keys.Control + "n");
action.Build().Perform();
I may resort to AutoIt to open a browser if I have to, but one more dependency is not what I need. Documentation everywhere around the web seems to suggest than all the options I tried above should work...I suspect it may be a chromedriver issue of some kind.
Any ideas on how to achieve my goal would be greatly appreciated
UPDATE.
Arnons answer below lead me to the solution. If you are in a similar situation the best thing to do is just open up the browser console (from developers tools) and experiment with javascript until you get what you want. Then just execute that. In the end executing the following code has worked for me.
IJavaScriptExecutor jscript = Driver as IJavaScriptExecutor;
jscript.ExecuteScript("window.open('https://www.bing.com.au','_blank','toolbar = 0, location = 0, menubar = 0')");
The other alternative was to use Autoit, which I also got working, much easier than I did figuring out the javascript. But one less dependency is best :)
UPDATE2.
Further complications arise with trying to control the window as an independent browser window. I believe any new window created from a parent window, has the same process id (at least my testing has indicated so), and for all intense and purpose is treated as a tab in the selinium driver. I therefore conclude that certain things are just not possible (for example relocating the child browser window on the screen).
Your first attempt using ExecuteJavaScript was very close, but In order for it to open a new window instead of new tab, you should add the following arguments: `"_blank", "toolbar=0,location=0,menubar=0" to it.
See this question for more details.
I should have read the question better, here is my solution. Ended up using this for selecting windows that popped up after clicking a button but should work with swapping between windows.
//---- Setup Handles ----
//Create a Handle to come back to window 1
string currentHandle = driver.CurrentWindowHandle;
//Creates a target handle for window 2
string popupWindowHandle = wait.Until<string>((d) =>
{
string foundHandle = null;
// Subtract out the list of known handles. In the case of a single
// popup, the newHandles list will only have one value.
List<string> newHandles = driver.WindowHandles.Except(originalHandles).ToList();
if (newHandles.Count > 0)
{
foundHandle = newHandles[0];
}
return foundHandle;
});
//Now you can use these next 2 lines to continuously swap
//Swaps to window 2
driver.SwitchTo().Window(popupWindowHandle);
// Do stuff here in second window
//Swap back to window 1
driver.SwitchTo().Window(currentHandle);
// Do stuff here in first window
You need to explicitly tell Selenium which tab you wish to interact with, which in this case would be;
driver.SwitchTo().Window(driver.WindowHandles.Last());

How to open links in bot framework in a seperate tab

Is there a configuration in the bot framework that makes it open links in a seperate tab?
Looking at this link, seems there is no way to specify in markdown to open a link in a new window and that it is possible using html.
We do not want to specify that long HTML configuration in each link, and we cannot call a function that does that because some of the links appear as a prompt which expects const only (so calling a function is not possible).
Therefore, we are looking for some general configuration in the bot frameowrk that would make links appear in a new window.
Links should open in a new tab by default. There is a GitHub issue tracking this here: https://github.com/Microsoft/BotFramework-WebChat/issues/454
Here is the PullRequest that fixes the issue: configure MarkdownIt to open links in new tab
There is a class in bot framework named CardAction.
If you want to open some link, you should have something like this :
List<CardAction> listButtons = new List<CardAction>();
listButtons.Add(new CardAction
{
Value = "https://google.com",
Type = "openUrl",
Title = "open google",
});

FormsAppCompatActivity and custom ActionBar/ToolBar

I am working on a Xamarin.Forms app, where I was using a FormsApplicationActivity as my main activity and was able to customize the ActionBar with a custom view inside it (I put a Spinner in it, for some page)
But since there was a few UI / look and feel issues I upgraded to FormsAppCompatActivity.
Since I did that I just CAN'T get my spinner in the toolbar / actionbar! No matter what I try!
This was basically the previous code, wroking with FormsApplicationActivity
var activity = (Activity)this.Context;
var bar = activityActionBar;
var dlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
bar.CustomView = new Android.Widget.Button(activity) {
Text = "Click",
LayoutParameters = dlp,
};
bar.DisplayOptions = ActionBarDisplayOptions.ShowCustom;
What should I write to support FormsAppCompatActivity please?
When using FormsAppCompatActivity the NavigationRenderer on android creates a new toolbar internally. It is a private field so far I can see and cannot be accessed.
here is the code : https://github.com/xamarin/Xamarin.Forms/blob/d1a8477233b28e6a20c6f5d4a75128ec2a05e6dc/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
See image for the specific code part. I am also trying now to get access to view. So just a note the action bar you are trying to edit is the wrong one. That one is created on activity startup.
UPDATE: maybe found a solution look here : https://forums.xamarin.com/discussion/69923/access-to-the-formsappcompatactivity-bar

c# customizing controls on a save dialog -- how to disable parent folder button?

I am working from the sample project here: http://www.codeproject.com/Articles/8086/Extending-the-save-file-dialog-class-in-NET
I have hidden the address/location bar at the top and made other modifications but I can't for the life of me manage to disable the button that lets you go up to the parent folder. Ist is in the ToolbarWindow32 class which is the problem. This is what I have at the moment but it is not working:
int parentFolderWindow = GetDlgItem(parent, 0x440);
//Doesn't work
//ShowWindow((IntPtr)parentFolderWindow, SW_HIDE);
//40961 gathered from Spy++ watching messages when clicking on the control
// doesn't work
//SendMessage(parentFolderWindow, TB_ENABLEBUTTON, 40961, 0);
// doesn't work
//SendMessage(parentFolderWindow, TB_SETSTATE, 40961, 0);
//Comes back as '{static}', am I working with the wrong control maybe?
GetClassName((IntPtr)parentFolderWindow, lpClassName, (int)nLength);
Alternatively, if they do use the parent folder button and go where I don't want them to, I'm able to look at the new directory they land in, is there a way I can force the navigation to go back?
Edit: Added screenshot
//Comes back as '{static}', am I working with the wrong control maybe?
You know you are using the wrong control, you expected to see "ToolbarWindow32" back. A very significant problem, a common one for Codeproject.com code, is that this code cannot work anymore as posted. Windows has changed too much since 2004. Vista was the first version since then that added a completely new set of shell dialogs, they are based on IFileDialog. Much improved over its predecessor, in particular customizing the dialog is a lot cleaner through the IFileDialogCustomize interface. Not actually what you want to do, and customizations do not include tinkering with the navigation bar.
The IFileDialogEvents interface delivers events, the one you are looking for is the OnFolderChanging event. Designed to stop the user from navigating away from the current folder, the thing you really want to do.
While this looks good on paper, I should caution you about actually trying to use these interfaces. A common problem with anything related to the Windows shell is that they only made it easy to use from C++. The COM interfaces are the "unfriendly" kind, interfaces based on IUnknown without a type library you can use the easily add a reference to your C# or VB.NET project. Microsoft published the "Vista bridge" to make these interfaces usable from C# as well, it looks like this. Yes, yuck. Double yuck when you discover you have to do this twice, this only works on later Windows versions and there's a strong hint that you are trying to do this on XP (judging from the control ID you found).
This is simply not something you want to have to support. Since the alternative is so simple, use the supported .NET FileOk event instead. A Winforms example:
private void SaveButton_Click(object sender, EventArgs e) {
string requiredDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using (var dlg = new SaveFileDialog()) {
dlg.InitialDirectory = requiredDir;
dlg.FileOk += (s, cea) => {
string selectedDir = System.IO.Path.GetDirectoryName(dlg.FileName);
if (string.Compare(requiredDir, selectedDir, StringComparison.OrdinalIgnoreCase) != 0) {
string msg = string.Format("Sorry, you cannot save to this directory.\r\nPlease select '{0}' instead", requiredDir);
MessageBox.Show(msg, "Invalid folder selection");
cea.Cancel = true;
}
};
if (dlg.ShowDialog() == DialogResult.OK) {
// etc...
}
}
}
I don't this is going to work. Even if you disable the button they can type ..\ and click save and it will take them up one level. You can't exactly disable the file name text box and maintain the functionality of the dialog.
You'd be better off either using the FolderBrowserDialog and setting it's RootFolder property and asking the user to type the filename in or auto generating it.
If the folder you are wanting to restrict the users to isn't an Environment.SpecialFolder Then you'll need to do some work to make the call to SHBrowseForFolder Manually using ILCreateFromPath to get a PIDLIST_ABSOLUTE for your path to pass to the BROWSEINFO.pidlRoot
You can reflect FolderBrowserDialog.RunDialog to see how to make that call.
Since you want such custom behaviors instead of developing low level code (that is likely yo break in the next versions of windows) you can try to develop your file picker form.
Basically it is a simple treeview + list view. Microsoft has a walk-through .
It will take you half a day but once you have your custom form you can define all behaviors you need without tricks and limits.

Categories

Resources