First of all say that I don't have much experience programming and that these are my first steps in Android.
I've developed an app for android, with minSdkVersion 8 and targetSdkVersion 16.
The application is like a photographic gallery that when you touch one of the pictures, shows a screen with a picture, a text, and play two sounds. You can view the previous or next screen sliding with your finger, or make it automatically sliding with some intervals.
I've tested the app in the emulator with android 2.2, and in some devices with android 2.3.5 and android 4.0.x.
With android 2.2 and 2.3.5 the app works correctly, but with android 4.0.x I've detected that the "manual" way works correctly, but the "automatic image sliding" doesn't work.
The problem is that you select one of the pictures and the first activity runs correctly, but after the first one, the sounds of the next activity are heard before the layout of this activity is on the screen. If you exit to the main menu and choose other picture, the problem is the same. You see correctly the first activity and after that, the sounds advance the image of the activity.
I haven't found nothing similar to my problem searching here. Can anyone help me?
EDITED to show some code.
The onCompletion code:
public void onCompletion(MediaPlayer mp) {
if(mp.equals(mpNom)){
try {
Thread.sleep (mpNom.getDuration()+500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(mp.equals(mpSo)){
try {
Thread.sleep (mpSo.getDuration());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The application does't show any error and neither crash, but the UI is shown when the sounds are already reproducing.
Any idea? Thanks in advance.
Finally I've solved the problem.
It seems that the problem was in the OnCompletion method or in the code inside this method.
I rewrite the code making the app do the same but in a different way (programmaticaly talking), avoiding the OnCompletion method and now the app works perfect in android 4.0.x
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
I have developed an application using SAPUI5. The spinner has to appear when navigating from one page to other. The spinner works fine on jelly bean android version. But fails on higher versions. Can anyone help me with this?
sap.ui.getCore().byId('loadingIndicator').setText("Loading...");
sap.ui.getCore().byId('loadingIndicator').open();
use sap.m.BusyDialog
var oBusyDialog = new sap.m.BusyDialog();
oBusyDialog.open();// will work when DOMis already there
oBusyDialog.close();//else it throws error and page completely fails in IE.
hence put it in try catch
try{
oBusyDialog.open();
}catch(e){
//Error handler
console.log("Busy dialog couldn't be loaded:"+e);
}
Check Preview here
Note: On Page refresh, DOM will not loaded before you call open() or
close() method, hence put it in try catch.
how to clear text edit field? android python appium?
I tried that way:
el = driver.find_element_by_id('text edit field id').clear()
el.click()
el.clear()
however, it actually deletes only one symbol.
I think may by call an el.click() twice and send keycode to delete highlighted text area but how to highlight the text?
Interestingly, such problem reproduces in Sony Xperia z3 compact, android 5.0.1.
In lg, nexus android 4.4,5.1 accordingly, the above code works well
i had faced same issue with my android application but i am doing automation in java , so for the solution i am performing tap Action twice near the location of the element so it will select all the text which already written in text field and after that click on that "cut" symbol so it will clear text field.
i have written a method for sendkeys in android device.
public void typeForAndroid(AppiumDriver appiumDriver,WebElement ele,String text)
{
if(ele.getText().isEmpty())
{
ele.sendKeys(text);
}
else
{
TouchAction action=new TouchAction(appiumDriver);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
appiumDriver.performTouchAction(action);
pause(2);
try{
appiumDriver.findElementById("android:id/cut").click();
}
catch(Exception e)
{
appiumDriver.sendKeyEvent(67);
}
pause(2);
ele.sendKeys(text);
}
}
this is working for me. I hope this might works for you.
in this i have used appiumdriver but you can also use androiddriver.
Thanks
I am going to explain the problem i have exactly, in an app i am developing for android i have an activity where i am showing a video that comes from youtube, to show that video i am using a VideoView . Also i have a progressSeekBar to be able to change the current position of the video and to be able to see what is left.
To do that i have done the next:
new Thread(new Runnable() {
public void run() {
try {
Log.d("Voizee", "Vengo al runnable.");
vSeekBarProgress.setProgress(getMediaPlayer()
.getCurrentPosition());
if (getMediaPlayer().getCurrentPosition() < getMediaPlayer()
.getDuration()) {
vSeekBarProgress.postDelayed(this, 1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
This code it is working and it is moving perfectly the seekbar when the video plays, but the performance of the video is quite bad and it is shown slowly and jumping through the diferent scenes.
So please could you help me with this problem i have. One more thing to add, it is that if i remove this thread the video it is working well without any performance issue so it is something to do with the thread.
Thank you very much in advance for the help.
I already have a good understanding of the OrientationEventListener, and detecting screen orientation. But, how do I rotate or adjust the actual content (buttons, images, tabs, any objects)? Right now, when the user rotates the phone, the content doesn't move or rotate, and it appears sideways to the user.
NOTE: I am using the Droid 2 for testing, and I have noticed that if i I slide out the keyboard, the screen DOES rotate, which is kind of strange in my opinion.
Any help is greatly appreciated!
EDIT: Here is my code:
OrientationEventListener ole = new OrientationEventListener(this) {
#Override
public void onOrientationChanged(int arg0) {
TabHost ll = (TabHost) findViewById(android.R.id.tabhost);
try {
ll.forceLayout();
} catch (NullPointerException e) {
System.exit(0);
e.printStackTrace();
}
}
};
ole.enable();
Unfortunately, when the program reaches ll.forceLayout(), it throws a NullPointerException and causes the system to shut down.
SOLVED: I had to edit the manifest such that android:screenOrientation="sensor". Thanks for all your help!
but I have no idea of how to tell android to switch to the second view
when the screen rotates
You don't have to tell it to. If you just create a layout-land folder in your project the system will know to pull layout files from that folder if the device goes in to landscape mode.
Try to call forceLayout () for your root view in the onOrientationChanged.
Just leave that android:screenOrientation="sensor" out of your manifest. It's the default.