I used Android Things on Raspberry PI 3 with touch screen. And i need configure wifi connection, for example. Call WiFi settings via intent, after configure i need return to my application, but i have only one button, which connect to pin. This button must be work as Back button on android device.
When button press executed this code:
Runtime.getRuntime().exec("adb shell input keyevent 4");
But i get exception:
java.io.IOException: error=13, Permission denied
When i send command via command line from PC - all work good, but on device - Permission denied
What wrong? This is because my android not rooted?
Also tried call OnBackPress in main activity, but this work only in my application and not back from settings.
If you don't have root, you will not be able to execute direct key presses on your device with a shell command. You would need to use an InputDriver to have your button send an event to the system (though I'm unsure if it would support the BACK button).
Additionally, if you are running a shell command on the device, you don't need adb shell. You're already in the shell.
With the latest version of AndroidThings (DP6) you can setup the Wifi Connection through the launcher (before you install your app).
This launcher is visible when no other developer-provided IOT_LAUNCHER Activity is present.
Once you have setup the wifi (using your touchscreen) you can then install your app.
If you wanted a more programmatic approach, you could install your app but disable the activity that has IOT_LAUNCHER intent. This will let the Launcher show. Meanwhile you have registered to monitor for connectivity changes, when the wifi is connected you re-enable your launcher activity. (This is just theoretical I haven't tried this).
With the latest version DP8 , you now need:
<category android:name="android.intent.category.HOME"/>
In your intent, which replaces IOT_LAUNCHER (https://developer.android.com/things/preview/releases.html)
Related
I would like to be able to type commands on my development machine (macOS/zsh) and have them do things on my Android app. This will require custom code in my Android app. What I'm trying to do is something similar to automating certain settings, so that I don't have to navigate to the settings screen of my Android app manually. This is to help me save time while I'm developing my app.
How can I get started? I'd love to see some examples of this being done but have been having trouble finding them.
Are there any libraries that can help me with this?
Also, for bonus points, I'd love to be able to have some sort of autocomplete on my Mac command line. How might I build that?
There's a few ways to do this:
1)Just write a Linux app, move it to your device, set the executable bit, and run it from adb shell (adb shell opens up a shell on an attached device with debugging enabled).
2)If you really need to access the app while its running, you can send intents to your app via the shell via adb shell am <options> This allows you to send an intent to the system. Then just write a custom Activity, Service, or BroadcastReceiver to receive that Intent and act upon it.
The next command enables phone call recording in OnePlus phones (may be others too):
adb shell settings put global op_voice_recording_supported_by_mcc 1
But after reboot its effect is disabled. My phone is OnePlus 6T.
How to make this setting persistent?
jOnePlus Tools is an answer. This application sets settings up on every reboot.
https://forum.xda-developers.com/oneplus-5/themes/app-enable-call-recording-boot-t3634292
This link has other root-required methods you might want to try.
Unfortunately, I am also trying to find a way without root. As the setting automatically turns off, sometimes before reboot, when you have an active some-country sim card, my hypothesis is that there is a "checking" program going on under the hood. If there is an adb command to turn off that "checking", the result should be permanent.
I also have a 6T, and what I could see about what causes recording to be disabled, is any application installation made by PlayStore.
If you keep the automatic update function of the applications deactivated, the recording remains activated, but anytime you do any installation on the PlayStore, the recording will be disabled and you will need to enable it with the command again.
I have a rooted phone and i want to assign my application to access notifications without user interaction like open settings and toggle from there but not find any proper way(Not programatically OR visa ADB command).
I have actually seen an old post where someone share a link:
So i have tried like this:
adb shell settings put secure enabled_notification_listeners %nlisteners:mypackageName/com.company.app.service.CallNotificationListener
Command run without any error on shell but when i open Notification Access from phone settings, my application still not mark as a notification receiver. Is there any way to do that?
Since Android 9 Your command is not working anymore. What worked for me was to use :
adb shell cmd notification allow_listener com.mypackage.app/com.mypackage.app.mylistener
It doesn't need root permission even in my case.
I need to automatically click on a specific button on an app. Is there a way to do this on a completely controlled environment?
By controlled environment, I mean the phone could be rooted, it could be connected to a desktop machine, any external app could be installed, and any other requirement.
Note: the button is NOT on an exposed activity.
Yes, if the phone is connected to a desktop machine, you can install adb on the machine, connect the phone to the machine with a USB cable, and authorize the machine to access the phone by clicking "OK" on the prompt displayed on the phone. Having ensured that the path variable (assuming you're on Windows) contains the location of adb.exe, all you need to do is type the following in the terminal:
adb usb
adb shell input tap X Y
Where X and Y are the coordinates of the button. This should work if by "not exposed" you meant that "other applications are not allowed to start the button activity".
In general: No it is not possible even from a rooted phone.
On special cases, when previously the original app developer published a part of the code be callable from other app than that part of the code can be called, but you don't know if is equivalent or not with the button pressing. When you have this option and the luck to have it than you can call it. You can read more here
is it possible to have a service (A) which will launch an activity (B) and then periodically capture B's screen?
also, is it possible to send onTouch events from A to B?
basically, i'd like to make a bot which would use an application so i don't have to.
i guess it's not possible but had to ask.
You can't do that across Activitys but you could create a view that held the Activity that you want to automate. Then periodically you can grab the ViewDecorator and do some processing on it and then inject touch events.
Screen captures of apps which are not the current app are prevented in Android devices due to security considerations.
As far as I know up until Android 4.3 you can only do this in these scenarios:
Your device is rooted
Your app is signed with the same signature of the system (Google apps)
With adb (debug environment): your device is connected via USB to a PC which is running adb shell commands, or either the USB is disconnected but you have started the native adb service in your device after each device reboot.
Some useful links:
How to programmatically take a screenshot in Android?
How to make a capture screen app on Android
http://code.google.com/p/android-screenshot-library/wiki/UserGuide