how to simulate android emulator boot in AndroidStudio? - java

Hi every one I'm currently working on a project which i need to monitor app behavior on emulator boot (i have a broadcast receiver which is being triggered with boot complete) the problem is the logcat shows process is terminated when you restart the emulator.
any idea how can simulate the boot and see logs in logcat???

On your emulator, go to Settings -> System -> Developer Options. Under 'Debugging' go to "Select debug app" and find your app, then underneath that option enable "Wait for debugger". Now when you reboot the emulator, the dialog to attach the debugger will show asking you to manually attach your debugger. Once you do that, your app will start and the receiver will get triggered.
Android studio emulators restart by long-pressing the power button and choosing "Restart". If you want to simulate the request instead you can use the following command:
adb shell su root am broadcast -a android.intent.action.BOOT_COMPLETED

Related

Install and skip unverified app message using Appium

could you help me with a question? Currently I’m working in a project using react native and when I try to install this app using Appium, a message is shown indicating that there is some validation and it’s not possible to install unless it is from the official stores (App Store / Play Store).
Unverified App Message - Android
I’ve been trying to skip this message running the test scripts with some ‘adb’ commands like: adb install -i "com.android.example" but I believe that’s not the best approach.
I appreciate if someone can help me with that.
Thanks all.
If you will perform following steps manually or using script on android device. It will not show this message box.
Navigate to Setting > Security.
Check the option "Unknown sources".
Tap OK on the prompt message.
Select "Trust".

How to hard close/force close/kill the app from memory in Android using Appium in the same test

This is my scenario
Launch the app and perform some steps
Hardclose/Forceclose/Kill the app from memory/Should not run in background
Launch the app again
Perform some steps
Assertion step
How to achieve this?
I have tried the following methods
resetApp() - it uninstall the app and install app again.
closeApp() - it just close the app but app is still running in the background.
adb shell am force-stop <packagename> - it just close the app but app is still running in the background.
But for my scenario it should delete from the background and app should not uninstall in Android in the same test (middle of the test).
You can try it, I think it will serve your purpose, use below line from where you want to launch the app again
Activity activity = new Activity("appPackage", "appActivity");
driver.startActivity(activity);
Try below code and add this to the capability :
capabilities.setCapability(MobileCapabilityType.NO_RESET,"false");
It should work as per your requirements.

Android java back to activity

In my app I wrote mechanism which lets return to the activity whet the application is suddenly removed from the device memory. Sometimes it happens eg. when the phone rings and there is not enough memory for phone application and my app. After the phone app ends the system call quite new process for my app and opens this activity which was closed previously.
I hope the mechanism I wrote works fine but I don’t know how to test it. I work in android studio.
So the question is how to simulate the process of killing and removal the application from system, and calling back my app process and activity.
fire this by cmd
echo 'am broadcast -a com.android.vending.INSTALL_REFERRER -n "package name/path of reciver" --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; exit' | ./adb shell

Uninstalling addons when main app is uninstalled

I want to create an add-on for an app, which the user can download from the Play store separately, and it will function with the aforementioned app that i've created.
I am using service, as this is the only clean way that I've come across for this. It works well with the "Base App" which I've created but I have no way of having it get removed when the user uninstalls the "Base App". I do know that i can essentially "Throw a dialog" up if the user attempts to uninstall my app, but i feel that has a more malicious feeling to it than what I intend. I don't want to interfere with the uninstalling of my app, simply I want to have the secondary addon service be uninstalled too.
You can listen to the broadcast to see if your main app is being uninstalled. See this for more info:
Android: Listen for app installed / upgraded broadcast message
When you detect that your main app is removed, your add-on app can suggest/remind users to uninstall add-on app using Android notification.

Debug android app when it starts on device

I have an android app that is opened by a URL on my website. What I am looking to do is, attach Eclipse in debug mode when the app starts. I can start the app in debug mode from Eclipse, but I do not know how to get Eclipse to start when the user/another app starts the app on the device.
Add a call to android.os.Debug.waitforDebugger() on the onCreate of your launch activity. This will make you app wait for a debug to attach whenever it is launched.
If you look in detail, there's a moment when Eclipse tries to couple the runtime session with the debugger so it starts listening to it until the coupling is made. I guess you'll need to trigger that whenever you open your app.
My question would be, why do you need that? Which are the different conditions when you start the app from the web that make it necessary to debug from there? If there are some, is there any possibility to fake them with any constants or db data?

Categories