I am new to Android Things, and I'm trying to power off the usb device that connected to the i.MX7 Dual.
After I read https://developer.android.com/guide/topics/connectivity/usb/host.html#api , I find that there is no result of the VID and PID of it.
My question is that I just want to control my device via power on and power off it, how can I do it? Thanks in advance.
You can try "software" solution like this or that, but seems, better way is to use MOSFET power switch, like in this answer of yo':
which connected to GPIO pin of Android Things board. In that case you can control your device via that GPIO pin:
...
gpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
gpio.setActiveType(Gpio.ACTIVE_HIGH);
// set your USB device ON
gpio.setValue(true);
...
Related
The Android Virtual Device is connected by defualt to a wifi network called "AndroidWifi". I am working with an app that expects to be connected to a wifi network with a particular name.
How can I change the name of the wifi network from "AndroidWifi"?
Try something more pragmatic:
String getExpectedId() {
String ssid = this.getResources().getString(R.string.default_ssid);
if(Build.FINGERPRINT.contains("generic")) {ssid = "AndroidWifi";}
return ssid;
}
because you won't change the SSID (service set identifier) of the emulator's WiFi.
Despite there's adb commands alike svc wifi enable and svc wifi disable, the password for the default network likely is unknown in /data/misc/wifi/wpa_supplicant.conf; see Connecting to WiFi using adb shell. Since the emulator is rooted, one can generally configure any network alike that, while it is accessible (which the regular WiFi, which is exists in reality, obviously isn't). I think the first one approach is better, because editing emulator images isn't too portable.
AVD manager doesn't provide any ways to customize the simulated Wi-Fi access point AndroidWifi .
You may have to disable it and use another wifi simulator such as this one. It does need the Xposed framework in order to function. Here is how you can configure it.
You can modify the hostapd.conf file in your device (/data/vendor/wifi/hostapd/hostapd.conf). It will allow you to set ssid (ssid=) or even to set a password (wpa_passphrase). You will need a root access to do that.
More details at https://wiki.gentoo.org/wiki/Hostapd#WiFi_Technology
I have been working on a project where our Android tablet has only 1 microUSB port.
Since we must communicate via serialUSB with an external device, it became a little fuzzy after we noticed that leaving the tablet powering the bus (Host Mode) drains it`s battery till death. Moreover, we still must supply enough energy to power the tablet.
After a lot of attempted fails, such as using a OTG-Y cable, modifying Kernel Battery Config and using a USB Hub, I need to discover a way to perform the communication and keep the tablet charging.
Thought about using the HDMI or even the audio/serial. Is there any solution I can look forward to solve this?
At this point, I'm getting out of ideas.
You can use an arduino, but not a normal one, you'll need a mega, i say this because the ardiono mega is the only arduino i know of with more than one serial UART. The Uno for example shares the RX/TX serial pins with the same UART as the USB interface.
If you DO have a mega, you can get a cheap USB to Serial module such as this: http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&_nkw=arduino+usb+to+serial&_sop=15
Now, you plug your PC into the mega's normal USB This will power the Mega from your PC.
Then you connect your tablet to the serial module.
All that's left to do is create a simple ino script for your mega to transfer data from serial (pc-USB) to serial2 (Tablet), and vice versa..
Example:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // PC <--> USB
Serial1.begin(115200); // Serial <--> Tablet
}
void loop() {
// put your main code here, to run repeatedly:
serialComs(); // Tells loop to execute the serialComs() function
}
// Serial Comunication function
void serialComs() {
// read from port 1 (Tablet), send to port 0 (PC):
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0 (PC), send to port 1 (Tablet):
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
NOTE: You may need to add #DEFINE entries before void setup to define which pins are which on your serial to USB module.
I think your way througt the HDMI will not work. And you have only one other option:
You could also load your battery directly. You could open the case and power your tabled instead your battery. This should also work. I think ther is no other way.
Also you could try a OTG hub: http://www.miniinthebox.com/de/3-in-1-micro-usb-otg-host-adapter-kabel-hub-fuer-samsung-smartphone-tablet-n9000_p1996674.html?currency=EUR&litb_from=paid_adwords_shopping&litb_from=&adword_mt=&adword_ct=73333307802&adword_kw=&adword_pos=1o1&adword_pl=&adword_net=g&adword_tar=&adw_src_id=4196617767_313342362_22461529362_kwd-140182704282&gclid=CJqW-Na8zMcCFc8aGwodznEIZA
But not all tables allow charging and using USB at the same time.
I need to access to programmatically turn ON & OFF Power Saving Mode in android.
Is there any API for this ? As I can see Power Saving mode option is not available
for all mobile devices, is there any code to check these settings availability and if available then turn it ON and OFF ?
Also is there any work around ?
If you want to test the Power Saving Mode (PSM):
The following works with Android Studio 3.4.1 and a Google Pixel 2 XL phone:
$ adb shell dumpsys battery unplug # a charging device cannot enter PSM
$ adb shell settings put global low_power 1 # enter Power Saving Mode (PSM)
This only works on devices that has the standard Power Saving Mode, like Samsung's, but not Huawei's, for example. On some Samsung devices, this setting is stored in global setting keyed psm_switch, as mentioned above.
You can leave PSM by setting low_power to 0 or by enabling charging again with:
$ adb shell dumpsys battery reset
Source: https://developer.android.com/training/monitoring-device-state/doze-standby#testing_doze_and_app_standby
It's bad practice to control the user's device settings from your app.
Rather consider suspending background services when battery levels are low.
Or to notify the user of low battery power and advising the user to switch of unnecessary settings like Bluetooth or WiFi.
Most devices won't have a built-in power-saver API, so you could try to make your own power-saver mode by turning off the bluetooth if it's on, the wi-fi, etc, deactivating location in settings, or checking for other power-eating options enabled.
There are no available API's to do this in android SDK. however You can control/save the power by Turning off Blutooth,Wi-Fi and other unused sevices inside your coding.
You can't set the power saving mode programmatically. Allowing this would be a bad idea.
On certain Samsung devices you can check if it is enabled:
final String result = Settings.System.getString(getContentResolver(), "psm_switch");
Log.v("Debug", "Powersaving active: " + TextUtils.equals(result, "1"));
See this for more info: https://stackoverflow.com/a/39296959/3600178
I want to connect a custom device with cp2102 to Android powered tablet. I connect it in VCP mode (using PID EA60) and use JavaComm to find it,
#SuppressWarnings("unchecked")
Enumeration <CommPortIdentifier> ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements())
{
final CommPortIdentifier port = ports.nextElement();
Log.d(null, port.toString());
}
but I never enter the loop.
I have an option to use FTDI instead of silabs. They have a variant of using their D2xx dll through JNI. I followed their guide but I have a memory crash (signal something and heap corrupted message in LogCat), when I connect ft232r and try to determine the number of connected devices. When I unplug the device from the tablet, the same code (their sample code) works just fine, returning zero, which is true.
When I use JavaComm with FTDI the result is the same as with cp2102: the loop is not entered.
I guess I miss something or do something wrong.
If I'm to use, say, usb-mode instead of VCP, I'm ready to start searching, I just need a hint.
Any help would be greatly appreciated.
The issue here is that the CP210x driver is not enabled in the Android kernel by default. So you will either need to build this driver in to your kernel to get the tty access and ability to use JavaComm.
The other option is to use the USB Host functionality and access your CP210x directly with it's API.
How could I programmatically set data roaming on/off in my android application ?
Apologies in advance for reopening a dead post but I have managed to achieve it by calling this executable:
su -c settings put global data_roaming0 1
Also to get the roaming setting for first SIM card:
su -c settings get global data_roaming0
If your app is signatureOrSystem/Privileged app (app resides in /system/priv-app) and your have valid android.permission.WRITE_SECURE_SETTINGS permission in system/etc/permissions. Then you can do it as below.
Enable :
Settings.Global.putInt(context.getContentResolver(), Settings.Global.DATA_ROAMING, 1)
Disable :
Settings.Global.putInt(context.getContentResolver(), Settings.Global.DATA_ROAMING, 0)
I hope that it's not possible to turn on data roaming programmatically as this would be a serious security issue from my point of view ...
Data roaming (i.e. UMTS data transfer via a foreign network) may result in a huge bill from your network provider - at least in europe.
If data roaming is currently on, then I think you can manipulate the Access Points Names in order to make it appear that a data service isn't available. See this post which also links to apndroid. You could browse their source and see the approach they have taken.
If data roaming has been set to off by the user, then this approach won't work. Though you could prompt users to turn it on as part of your install/setup process, which is the route apndroid take.
apndroid also provide an API for changing these kind of settings, which might be more convenient than reimplementing the same functionality.
On rooted devices when using su to enable data roaming, on multi sim devices the data roaming setting is sim specific.
So you need to get the sim number that is active for data calls
sim_num = settings get global multi_sim_data_call
and use this in the data_roaming + sim_num setting. EG sim_num 3
settings get global data_roaming3
if this is null then not multi sim device and use data_roaming otherwise use
settings put global data_roaming3
I was able to enable data roaming on my dual sim Motorola G8 without the need to root it via ADB. I'm posting here the procedure, because the phone has a bug that prevents data roaming from being enabled normally.
You need a computer and to install ADB installed
Enable developer mode and USB debugging in your phone
Connect the phone to the computer via USB and accept the debugging connection.
Start an "adb shell", be sure that it is correctly connected to your phone.
Issue the command
settings put global data_roaming1 1
to enable data roaming for SIM card 1, or
settings put global data_roaming2 1
to enable it for SIM 2
Note: if you do not have the USB cable, this can be done via wifi, but the pairing process is a bit complicated and version dependent.
If you do not have a computer, it may be possible to run the commands directly on the phone using a "local adb" app (there are a few on the play store), but I have not tested any.