I am making a simple GUI program to change bootanimation of a android phone but from last 4 days I am facing a problem and I don't know whats is reason, here is my code
void MainWindow::bootanim1()
{
QProcess rootboot;
QStringList path6,boottarget;
path6<<ui->lineEdit_6->text();
boottarget<<path6<<" /system/media";
ui->textBrowser->clear();
ui->textBrowser->setText("Remounting partitions...");
rootboot.start("bbin\\adb shell su -c \"busybox mount -o remount,rw /system\"");
rootboot.waitForFinished();
ui->textBrowser->setText("\nInstalling bootanimation.zip");
rootboot.start("bbin\\adb push ",boottarget);
rootboot.waitForFinished();
ui->textBrowser->setText("\nBootanimation has been changed! Try shutting down your phone to see new bootanimation");
}
This function is launched when a button is clicked but my problem is, this is not working! Secondly you can see in the code that to be more informative I have used a textBrowser to show user whats going on like Remounting partitions etc and the lineEdit_6 is the lineEdit widget where user will paste the path of the bootanimation.zip. So my problem is when I click the button only this is shown
Bootanimation has been changed! Try shutting down your phone to see new bootanimation
And everything above it I think is getting skipped, I don't know why? can anyone give me some hint on what I am missing?
Here you are mixing two different methods to give arguments to QProcess:
boottarget<<path6<<" /system/media";
rootboot.start("bbin\\adb push ",boottarget);
First method gives the program name and arguments in one QString.
Second method gives the arguments in a QStringList.
You are trying to give one argument ("push") in the program name string. It doesn't work, when the other arguments are given in a QStringList. The last argument also contains suspicious looking space in the beginning, although I don't know if it causes problems. Try this instead:
QStringList args;
args << "push" << path6 << "/system/media";
rootboot.start("bbin\\adb", args);
And path6 variable probably should be QString instead of QStringList.
Ui requires eventloop to refresh itself. When you do all changes in one function call, then only internal property change, and gui itself doesn't repaint. Use QCoreApplication::processEvents(); right after each ui->textBrowser->setText(...);
Related
I am new to app development and have come across an issue my course hasn't yet covered but requires.
I have created a simple app that generates a log entry using Log.i after clicking a button - see screenshot below.
link to screenshot
As you may well see, no logs have been generated at all for the running emulator. This happened on an earlier app and after searching for an answer, found that going to the terminal and finding the appropriate directory, I could restart the adb using the 'kill-server' and 'start-server' commands. As this didn't work, I found the file in windows explorer and double clicked the adb.exe file. This seemed to fix the problem.
Having started another project (the one linked in the screenshot), the same problem has arisen but the same steps do not correct the issue and as such have nothing being generated in the logcat.
*beneath the emulator you see, I have nothing in the search box, the logcat is set to verbose and regex(?) is ticked.
Any help with this would be greatly appreciated as i'm reluctant to proceed with the course material before sorting out this issue.
Thanks.
some additional information I have found in the 'AVD' section of the 'Run' Window :
libpng warnings
adb successful start?
EDIT - requested code
EDIT 2 - It's a bit of a bodge but it seems the adb operator command 'logcat' used in the Terminal, turns the terminal into the logcat i.e. c:..\sdk\adb logcat' - all my missing logs, including the ones generated by the buttonClicked function appear in the terminal and new logs also appear there.
Terminal as logcat
Thank you for your responses but maybe someone knows a way to fix the logcat itself, i'd appreciate the answer. Thanks again.
I have managed to resolve the issue by closing all related software, rebooting my laptop and running the adb.exe file in the ..\android\sdk\platform-tools\ directory before launching the android studio.
Hope this helps if anyone else has the same issue.
Stitches S, I think you are not calling the buttonclicked method anywhere as I haven't seen it calling in the screenshot. But if you are calling it somewhere else then try log.d() to print that. It always works for me.
if you want to see log on button click set the buttonClick method inside the oncreate(), may be its doing nothing that's why not showing any log
this code is working in my case:
public class About_us extends AppCompatActivity {
TextView header, address;
private String Info="Info";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
header=findViewById(R.id.head);
address= findViewById(R.id.tv_address);
}
public void buttonClick(View view){
Log.d( Info,"button is clickd" );
}
}
and this is my xml view
<TextView android:id="#+id/head"
android:onClick="buttonClick"
android:layout_width="match_parent"
android:background="#color/third"
android:text="#string/app_name"
android:gravity="center"
android:textSize="20sp"
android:textColor="#color/first"
android:layout_height="30dp"/>
I'm unable to find an element (UiObject2) using UiAutomator within my androidTest. I obtained UiDevice instance and try to find the object with this:
MY_UI_DEVICE.findObject(By.res(CURRENT_PACKAGE, id));
CURRENT_PACKAGE is the package of my app MY_UI_DEVICE.getCurrentPackageName(). I tried also with this one:
MY_UI_DEVICE.wait(Until.findObject(By.res(CURRENT_PACKAGE, id)), 10000);
I can see the app is waiting for 10 seconds on the right screen (where the desired object persists), but after timeout it fails to find it and test fails. It always fails on emulator (API 23), but rarely works good on a real device (API 25).
When I debug the code I could see that manually I could obtain the right element by calling sequence of getChild(index) methods on AccessibilityNodeInfo but in the runtime it still fails even the app is waiting on the right screen where I expect the specific element.
I was playing with different UiDevice's functions, but none of the helped and I'm out of ideas, so any help will be appreciated.
There were 2 issues with my tests:
The first problem was in getting / initialising UiDevice instance in static block (as a static field in util class). I moved it into #Beforeand it helped to resolve the issue partially.
Another problem was occurring while searching for an element using a package name obtained from the UiDevice. I replaced getting package with InstrumentationRegistry.getTargetContext().getPackageName(); as it's done in google samples.
Make sure that your Test method is throwing the UiObjectNotFoundException. I had this issue with UiObject2 as well until I started forcing the error throw
#Test
public void clockTest() throws UiObjectNotFoundException, InterruptedException {
mDevice.click(1146,37); //click on clock top right corner
Thread.sleep(1500);//wait 1.5 seconds for screen to load
mDevice.click(1138,135);//clicks in shell
Thread.sleep(1500);//wait 1.5s for screen to load
UiObject2 dTSettingsButton = mDevice.findObject(By.text("Date & Time Settings"));
//assertNotNull(dTSettingsButton);//find and assert the settings button
dTSettingsButton.clickAndWait(Until.newWindow(), LAUNCH_TIMEOUT);//clicks the settings button
UiObject2 timeFormatButton = mDevice.findObject(By.text("Select Time Format"));
assertNotNull(timeFormatButton);//find and assert timeformat button
timeFormatButton.clickAndWait(Until.newWindow(), LAUNCH_TIMEOUT);//click timeformat button
UiObject2 twelveHourButton = mDevice.findObject(By.res("com.REDACTED.settings:id/first_btn"));
assertNotNull(twelveHourButton);//find and assert twelvehour button
twelveHourButton.clickAndWait(Until.newWindow(), LAUNCH_TIMEOUT);//click twelvehour button
}
Try use UiSelector methods. That worked for me much better than By selectors
I am running osx and installed oh-my-zsh as well, if that's relevant.
Anyway, if I type in something like "andr" and hit tab to complete it, it autocompletes to _xrandr instead of doing nothing (android isn't in my path). I'm not really sure why.
Any idea why that might be the case?
oh-my-zsh sets up completion to look for completions on the left side of the typed word if there are none on the right side.
This happens in ~/.oh-my-zsh/lib/completion.zsh:
## case-insensitive (all),partial-word and then substring completion
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
unset CASE_SENSITIVE
else
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
fi
The important part here is 'l:|=* r:|=*'. If you dislike this behavior, you just have to remove this from zstyle ':completion:*' matcher-list. The best way to do this, is to create a file in ~/.oh-my-zsh/custom with extension .zsh, for example own-completion.zsh:
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*'
This is for case insensitive completion, if you do not want this either, also remove 'm:{a-zA-Z}={A-Za-z}'.
You could change it in ~/.oh-my-zsh/lib/completion.zsh directly, but it will probably be overwritten once you update oh-my-zsh.
Ok so I've finally cobbled enough working parts into my app that its just plain old refusing to do anything now. I understand how to use logcat, but that is about it.
The main problem at the moment is that I get the error
Activity Idle Timeout for HistoryRecord then my package
I need to learn how to do better debugging. Plus if anyone can suggest things I should do for this error please let me know.
I think its something to do with the interactions with the database.
Cheers
EDIT:
What IDE are you using, if any?
Eclipse with Android tool has
moderately good debugging facilities;
set a breakpoint and debug away.
I am using Eclipse
And I know of breakpoints, but not their real use. Where would I set them for this error?
I am used to PHP where errors tell you a specific line to look at is there a way to do this in Eclipse?
In Eclipse if you right click in the margin next to your code - easy place to start is probably in your onCreate method - you can choose to Toggle Breakpoint. This will set a breakpoint at that location.
Now, in Eclipse choose Run->Debug As->Android Application.
This will run your app in the emulator and your app with stop running at your breakpoint. At this point you can step thru your code line by line using F6 I believe.
Once you've hit the breakpoint and your code is paused, use a guide like this http://www.ibm.com/developerworks/library/os-ecbug/ which will highlight all the different things you can do at that point.
Max... If you can wrap the offending line of code in try catch you can log the exception or set a breakpoint at the exception. So for the code below that will throw an exception:
String test= null;
try {
test.length();
}
catch (Exception e) {
Log.d(TAG,"test",e);
}
LogCat will display test,java.lang.NullPointerException blah, blah, blah
OR you can set a breakpoint at the Log.d line and if hit in DEBUG mode the app will pause and the variable window in the DEBUG view will show:
this:MyApp e:NullPointerException
BUT it does not sound like your app is throwing an exception, rather it is timing out on a database call. I would stub out the call to the database and see if the timeout goes away. Then slowly add back code until it times out.
JAL
Since LogCat truncates long strings, I work around this using FileOutputStream to inspect the contents of very long strings.
It works but it forces me to 'adb pull' that file, which is not very convenient, compare to watching it on LogCat.
Is there any other way in Eclipse to watch very long strings?
For the record, the answer was found here.
when you stop in debug on the variable
do the following and past it to a text file
I think it will be easier to use the eclipse debugging view.
Set a break point at the line where you call Log.* and run your app in debug mode.
When execution reaches the break point the app will ... yes, it will halt.
In the Variables window you may now browse your data and display whatever you need. Copy and paste it at a safe place as well and don't forget to smile :)
What I do, is in "Variables->Change value".
That will show you a Windows with the full text. Then just Copy&paste to notepad.
try this:
public void logLargeString(String str) {
if(str.length() > 3000) {
Log.i(TAG, str.substring(0, 3000));
logLargeString(str.substring(3000));
} else
Log.i(TAG, str);
}
}