I have 2 buttons in my app ( my app published by flash cs6 for android ). one button for exit app and one button for minimize app (send app to background and show homepage).what is code for 2nd button in as3?
b1.addEventListener(MOUSE_UP,exitapp);
b2.addEventListener(MOUSE_UP,minimizeapp);
function exitapp(e:mouseevent)
{
nativeapplication.nativeapplication.exit();
}
function minimizeapp(e:mouseevent)
{
//...what code I should write here?
}
NativeApplication has a property called activeWindow which is an instance of NativeWindow which has a minimize method:
function minimizeapp(e:mouseevent)
{
nativeapplication.activeWindow.minimize();
}
Finally I find this solution:
https://forums.adobe.com/message/5714697#5714697
Related
Is there any way to do the following process in android Automation using Appium with android driver?
Press home button from some specific screen.
Put app in background.
Open the app from same screen after some time interval.
Please help if anybody knows.
Both iOS and Android support the following methods :
(AppiumDriver)driver.runAppInBackground(10);//put app in background for 10 seconds
(AppiumDriver)driver.launchApp();//launch the app again
Hope it helps!
Try to focus on the current activity you were in :
(AppiumDriver)driver.runAppInBackground(10);
(AppiumDriver)driver.currentActivity();
or
Try to start the same activity you were in :
(AppiumDriver)driver.runAppInBackground(10);
(AppiumDriver)driver.startActivity("appPackage","com.example.android.apis", null, null);
Put App in background:
((AndroidDriver)driver).runAppInBackground(Duration.ofSeconds(20));
To start App from background:
driver.activateApp("app package name");
driver.runAppInBackground(Duration.ofSeconds(10));
appium_lib ruby client allows you to do this with
background_app 5 where 5 is the number of seconds you want the app to be in background. This will automatically, resume the application in the same screen.
Here it is how it works.
Code for Running the App in back ground
((AppiumDriver)driver).runAppInBackground(Duration.ofSeconds(10));
Get back back to the current activity again
((StartsActivity)driver).currentActivity();
public static void minimizeMaximize() {
try {
driver.runAppInBackground(10);
((AndroidDriver) driver).startActivity("appPackage", "appActivity");
} catch (Exception e) {
e.printStackTrace();
}
}
You have to enter your app package name and activity name to maximize the app.
For Eg:
public static void minimizeMaximize() {
try {
driver.runAppInBackground(10);
((AndroidDriver) driver).startActivity("com.example.test", "com.example.LaunchApp");
} catch (Exception e) {
e.printStackTrace();
}
}
This will definitely work.
Works for me: ((Appium 1.10, Android 8.1))
2 options:
1st solution:
driver.runAppInBackground(Duration.ofMillis(300));
After you close your popUp, you use this line and your app will go to background and back and you will get back the focus to your app.
2nd solution: better one :)
Add this line to settings:
capability.setCapability("noReset", true);
From now your app will start like normal app, without setting reset what means without pop-ups and you will not have problem with focus at all.
I hope it will work also for you! :)
This will navigate to the Gmail App while executing your Appium script. You Just Change the package name & activity of your app.
Activity activity = new Activity("com.google.android.gm", "com.google.android.gm.ConversationListActivityGmail");
activity.setStopApp(false);
((AndroidDriver<MobileElement>) driver).startActivity(activity);
You can use this snippet of code
((AppiumDriver)driver).runAppInBackground(Duration.ofSeconds(10));
((StartsActivity)driver).currentActivity();
If it is not working then please update your appium with the latest version and try with the same snippet of code.
Thanks
Basically, I use Stencyl engine to make games. The engine uses Haxe and doesn't support everything that Haxe supports.
I want to manipulate he android 'back button' press. Stencyl supports code mode where I can write a haxe code. I wanted to overwrite android's default back button press. When player is playing the game, if he press back button, the game goes to background. Instead, I want the level to restart when backbutton is pressed. Can this be accomplished with any available source for Haxe?
I tried searching for any code help but can't find one. That's why messaging here. Appreciate any help.
P.S: Stencyl developer may not be a real developer for you. If that's the case, I'm not a developer. I'm just someone who uses all the resources to achieve what I want. So please avoid such topics which isn't going to help anybody.
You could try below code
Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_UP, checkKeypress);
...
private function checkKeypress(e:openfl.events.KeyboardEvent):Void
{
switch (e.keyCode)
{
case openfl.ui.Keyboard.ESCAPE:
e.stopImmediatePropagation();
restartLevel();
}
}
private function restartLevel():Void
{
//your code to restart level here
}
I'm trying to control how the android hardware back button behaves in my app. I had it all working but now I can't reproduce it. The code I'm using is in app.js. I'm expecting the back button to do nothing but write to the console.
.run(function($ionicPlatform) {
$ionicPlatform.onHardwareBackButton(function() {
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!")
});
Can any one see what the problem is? I'm running ionic CLI v1.7.11. I'm running the code with ionic view on android
You can find full details, including a full working solution for both hard & soft back buttons at my related post:
Ionic override all BACK button behaviour for specific controller
To summarise how I handled the hardware back button, the trick is to register an action for the Back button, using code like this:
var doCustomBack= function() {
// do something interesting here
};
// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterHardBack= $ionicPlatform.registerBackButtonAction(
doCustomBack, 101
);
$scope.$on('$destroy', function() {
deregisterHardBack();
});
The actual setting is done in that second block calling $ionicPlatform.registerBackButtonAction().
This returns a method that can be called to deregister the action later on if you want to.
It was a ionic view problem. Seems it does not support this.
In my Phonegap app, created in a single html file using div as pages, I override the Back button to exit the app, only if the div that acts as the Home page is visible, otherwise to hide the others and show the home div. I use jQuery to attach the event handlers.
It works well at first app launch, but if the app is in the History list, the override is not working, the Back button exits the app without checking which div is visible. After deleting the app from the History list it works as expected again.
Tested on Nexus 4 with Android 4.2.
Here is the code:
$(document).on('backbutton', function (ev) {
ev.preventDefault();
if (!$('#divHomeScreen').is(':visible')) {
$('.screen').hide();
$('#divHomeScreen').show();
return false;
} else {
navigator.app.exitApp();
}
});
Thanks for your help.
What I have done is dynamically add and remove the backbutton handler as needed. For example...
function showScreen()
{
$("#divHomeScreen").hide();
$(".screen").show();
$(document).on("backbutton", onBackButton);
}
function hideScreen()
{
$(".screen").hide();
$("#divHomeScreen").show();
$(document).off("backbutton", onBackButton);
}
function onBackButton()
{
hideScreen();
}
This was tested on Galaxy S3 Android 4.3 and PhoneGap 3.3.0
If you press the Android back key when the keyboard is active, the keyboard will disappear. On the second press the application closes but it should fired the handleDeviceKeys function.
This is my code:
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleDeviceKeys, false, 0, true);
function handleDeviceKeys(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.BACK) {
trace("fired")
}
}
Is there a fix for this?
(I'm using Flash CS6, Air 3.6 and tested it on Android 2.2 and Android 4 devices)
Try listen stage: stage.addEventListener(KeyboardEvent.KEY_DOWN...
If it will not work and you using StageText, then you must listen an instance of StageText instead.