2020-11-12
Android Studio: “No tests were found” Error, Trying to Run Android Instrumented Tests (androidTest)
2020-09-26
Android Studio Complaining About Imports in "androidTest"
If you are trying to build an androidTest with Android Studio and it can not find the classes being imported. (For example Android Studio can not find AndroidJUnit4, InstrumentationRegistry, etc.)
Android Studio: "androidTest" Raising "java.lang.ClassNotFoundException: Didn't find class"
2020-09-07
Creating a SVG Embedded Icon
Here a very short summary (by example) from "Icon System with SVG Sprites" of how to create an embedded icon in a HTML page using svg.
2020-09-06
Localização / GPS e o consumo de bateria sob Android
A ativação da
"Localização" ou ("Local" em alguns modelos celulares)
no
Android controla a permissão geral dos aplicativos para consultar o local atual.
Isto é, ativar a "Localização" não causa necessariamente um consumo significante de bateria.
Se ativada, somente os aplicativos que receberam esta permissão podem consultar a localização.
O GPS só é ativado quando um aplicativo usa (consulta) o GPS. Isto depende das solicitações de localização do aplicativo correspondente e se o aplicativo tem permissão para executar solicitações com alta precisão (ou seja, com GPS) ou apenas com baixa precisão (ou seja, apenas com antenas de telefonia celular e estações WLAN).
O consumo da bateria depende apenas dos aplicativos que determinam a localização.
Se os aplicativos utilizam apenas as antenas de telefonia celular e estações WLAN para consultar a posição, o consumo é mínimo, pois são utilizados apenas dados que o celular está constantemente determinando de qualquer forma (para alguns modelos, mesmo independentemente de o celular estar em modo de vôo ou não).
Somente quando se utiliza o GPS para posicionamento, o consumo da bateria aumenta. A quantidade de consumo depende da freqüência com que o aplicativo utiliza o GPS.
Isso significa que é possível deixar a "Localização" ativada sem usar a bateria de forma significativa.
Para conseguir isso, é necessário selecionar "Configurações à Localização", você tem que conceder ou revogar a permissão "Localização" para os aplicativos (dependendo de suas próprias preferências e necessidades).
Com a versão 10 do Android foi introduzido, que após a instalação de um aplicativo,o usuário pode determinar como as consultas de localização podem ser feitas pelo aplicativo:
- "Permitir sempre" (mesmo que não visível)
- "Permitir apenas durante a utilização da aplicação" (somente se o aplicativo for visível)
- "Recusar" (o aplicativo nunca pode consultar o as funções de localisação)
Isto evita que os aplicativos consultem a localização sem se perceba e consumam rapidamente a bateria de maneira descontrolada.
Assim que uma das fontes de localização estiver em uso, o ícone marcado abaixo aparecerá na barra de informações na parte superior da tela.
Fontes:
- Gerenciar as configurações de localização do dispositivo Android
- Android 101: How to stop location tracking
Location / GPS And Battery Consumption With Android
Activating the
"Location"
in Android controls the general permission of apps to query the location.
I.e. activating "Location" does not necessarily cause a much higher battery consumption.
If activated, only apps that have received this permission can query the location.
The GPS is only activated when an app uses (queries) the GPS. This depends on the location requests of the corresponding app and whether the app is allowed to execute requests with high accuracy (i.e. with GPS) or only low accuracy (i.e. only with mobile phone antennas and WLAN stations).
The battery consumption depends only on the apps that determine the location.
If apps only use the mobile phone antennas and WLAN stations for positioning, the consumption is minimal, because only data is used that the cell phone is constantly determining anyway (for some models even independent of whether the cell phone is in flight mode or not).
Only when using the GPS for positioning, the battery consumption increases. The amount of consumption depends on how often the app uses the GPS.
That means it is possible to leave the "Location" activated without using the battery significantly.
To achieve this, you have to go to the Android "Settings à Location", where you can grant or revoke the "Location" permission to the apps (depending on your own preferences and needs).
With the Android version 10 it was introduced, that after the installation of an app, the user is asked on how location queries may be performed by the app:
- "Allow all the time" (even if not visible)
- "Allow only while using the app" (only if the app is visible)
- "Deny" (the app is never allowed to query the location.)
This prevents apps from querying the location undetected and quickly draining the battery without control.
As soon as one of the "Location" sources is in use, the icon marked below appears on the information bar at the top of the screen.
Sources:
Standort / GPS und Akkuverbrauch unter Android
Das Aktivieren des
"Standorts"
in Android steuert die allgemeine Berechtigung von Apps, den Standort abzufragen.
D.h. die "Standort" Aktivierung verursacht nicht zwingend einen wesentlich höheren Akkuverbrauch.
Wenn aktiviert, können nur Apps, die diese Berechtigung erhalten haben, den Standort abfragen.
Das GPS wird erst eingeschaltet, wenn eine App das GPS verwendet (abfragt). Dies hängt von den Ortungsanfragen der entsprechenden App ab und ob die App Anfragen mit hoher Genauigkeit (d.h. mit GPS) oder nur niedriger Genauigkeit (d.h. nur mit Mobilfunkantennen und WLAN Stationen) ausführen darf.
Der Akkuverbrauch hängt nur von den Apps ab, die den Standort ermitteln.
Wenn Apps nur die Mobilfunkantennen und WLAN Stationen für die Ortung verwenden, ist der Verbrauch minimal, weil somit nur Daten verwendet werden, die das Handy sowieso ständig ermittelt (bei einigen Modellen sogar unabhängig ob sich das Handy im Flugmodus befindet oder nicht).
Erst bei der Verwendung des GPS für die Ortung, erhöht sich der Akkuverbrauch. Die Höhe des Verbrauchs hängt davon ab, wie oft die App das GPS nutzt.
D.h. es ist möglich den "Standort" aktiviert zu lassen, ohne das Akku bedeutend zu beanspruchen.
Um dies zu realisieren, muss man unter den Android " Einstellungen à Standort", den einzelnen Apps die "Standort"-Berechtigung erteilen bzw. entziehen (je nach eigenem Ermessen und Bedarf).
Mit der Android-Version 10 wurde eingeführt, dass nach der Installation einer App der Benutzer gefragt wird, wie Standort-Abfragen durch diese App erfolgen dürfen:
- "immer zugelassen" (auch wenn nicht sichtbar)
- "nur während Nutzung der App zulassen" (nur wenn die App sichtbar ist)
- "ablehnen" (die App darf nie den Standort abfragen)
Somit kann verhindert werden, dass Apps unbemerkt den Standort abfragen und den Akku rasch unkontrolliert aufbrauchen.
Sobald eine der "Standort"-Quellen verwendet wird, erscheint das unten hervorgehobene Symbol auf der Informationsleiste am oberen Bildschirmrand.
Quellen:
2020-07-19
AutoSOS: O Android SOS Alarm App Para Emergências
Photo by Aaron Burden on Unsplash |
Funções básicas
- Alarme em caso de emergência (via telefonema e SMS com link para Google Maps)
- Não é necessária Internet, ou seja, não é necessário adquirir pacotes de dados para alertas, nem para uso doméstico ou internacional.
- A localização do celular funciona também sem GPS (sendo menos precisa)
- Discagem rápida e alarmes a partir da tela de bloqueio
- Sinalização da recepção de SMS de alarme com som de aviso mesmo que em modo mudo
-
Fazer o celular tocar via comando SMS, mesmo se estiver no modo mudo.
Facilita encontrar o seu celular na proximidade imediata. - Facilita a recuperação do telefone em caso de roubo, comunicando a posição actual do celular:
- em resposta um comando SMS
- na troca do cartão SIM
Acionamento de alarmes
- clicar no botão SOS
- puxar o plugue do fone de ouvido (Dica: encurte/corte o cabo de um fone de ouvido velho)
- quando não houver mais movimento perceptível
- pressionar o botão de energia do celular várias vezes
- pressionar um botão Flic (deve ser adquirido separadamente de www.flic.io)
- quando nível de carga da bateria ficar muito baixo
Detalhes
- Para mais informações, veja: AutoSOS - O aplicativo de alerta do Android
- Link para a Google Play Store: AutoSOS
2020-07-18
AutoSOS: The Android SOS Alarm App for Emergencies
Photo by Aaron Burden on Unsplash |
Basic Functionality
- Alarming in case of emergency (via phone call and SMS with a link to Google Maps)
- No Internet required, i.e. no need to purchase data packages for alerting (neither at home nor abroad).
- Locating the alarming mobile phone with and without GPS (less accurate)
- Speed dial and alarming from lock screen
- Alerting of incoming alarm SMS, even in silent mode
- Eases finding the mobile phone in close proximity, by making it ring through an SMS command, even in silent mode
- Facilitate the location of the mobile phone in case of theft by reporting its current position:
- in response to a SMS command
- when the SIM card is changed
Alarm triggering
- by clicking on the SOS button
- by pulling the earphone plug (Hint: Cut the cord of an old earphone and make a loop or knot.)
- by absence of significant motion
- by pressing the power button several times
- by pressing a Flic button (to be bought separately from www.flic.io)
- when the battery is low of charge
Details
- For further information see: AutoSOS - The Android Alarming App
- Link to Google's Play Store: AutoSOS
AutoSOS: Die Android SOS Alarm App für Notfälle
Photo by Aaron Burden on Unsplash |
Es freut uns verkünden zu dürfen, dass wir gerade eine neue Version unserer Android Alarmierungs-App AutoSOS in Google’s Play Store publiziert haben.
Grundfunktionen
- Alarmierung in Notsituation (mittels Tel. Anruf und SMS mit einem Link zu Google Maps)
- Kein Internet erforderlich, d.h. keinen Kauf von Datenpaketen zur Alarmierung nötig. (weder fürs Inland noch fürs Ausland.)
- Ortung des Handy's mit und ohne GPS (weniger genau)
- Schnellwahl und Alarmierung vom Sperrbildschirm aus
- Signalisierung eingehender Alarm-SMS mit Warnton auch wenn in Stumm-Modus
-
Handy via SMS Befehl läuten lassen, auch wenn in Stumm-Modus.
Erleichtert das Auffinden des Handy's in unmittelbarer Nähe. - Erleichterung der Auffindung des Handy's bei Diebstahl, durch Meldung der aktuellen Handy Position:
- als Antwort auf einen SMS Befehl
- bei wechsel der SIM Karte
Alarmauslösung
AutoSOS bietet viele Möglichkeiten Alarme auszulösen:
- SOS Knopf drücken
- Kopfhörer‐Stecker herausziehen
- ausbleiben spürbarer Bewegungen
- Handy Ein-/Aus-Knopf 3x drücken
- Drücken eines Flic Knopfes (muss separat bei www.flic.io erworben werden)
- bei niedrigem Akku-Ladestand
Details
- Weitere Informationen unter: AutoSOS - Die Android Alarmierungsapp
- Link zu Google’s Play Store: AutoSOS
2020-04-12
Bluetooth:Example How To Use "bluetoothctl" in Scripts
I needed a possibility to programmatically control the Bluetooth device on a raspberry pi.
(At least, list the discovered Bluetooth devices around.)
The only command line method/program I've found, that reliably works on Linux was "bluetoothctl".
But it is intended to be used interactively.
In order to overcome this challenge, I've used co-processes.
This script resets the Bluetooth local device and lists the discovered Bluetooth devices around.
(I've noticed that devices are easier discovered if one of the Bluetooth devices around is re-enabled.)
This script is intended to be only a starting point for the development of your own scripts.
#!/bin/bash #=============================================================================== # Uses "bluetoothctl" in order to query bluetooth devices around. # Starts "bluetoothctl" as coprocess, communicating with it simulating interative input. # See https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses # An alternative implementations would be: # - the usage of named pipes: # See https://en.wikipedia.org/wiki/Named_pipe # - or perhaps using expect: # See https://www.thegeekstuff.com/2010/10/expect-examples/ #=============================================================================== # ---- Constants ---- typeset -r C_MAX_TRIES=999 typeset -r C_WAIT_SECS=2 # ---- Global variables ---- typeset g_output="" typeset g_result="" typeset g_separator="" typeset g_device="" let g_count=0 #---------------------------------- # Functions #---------------------------------- sendToCOPROC () { local send_cmd="${1}" echo -e "I: Sending to COPROC\n-----\n${send_cmd}\n-----\n" # See https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses echo -e "${send_cmd}\n" >&"${COPROC[1]}" } showHedxump () { echo "D:Hexdump BEGIN ---------------------" echo -e "${1}" | hd echo "D:Hexdump END -----------------------" } #------------------------------------------------------------------------------ # The 1st parameter must be the name of a variable that will receive the output # of this function. # If 2nd parameter (regular expression pattern) is given, "receiveFromCOPROC()" # will return only the lines that match the given pattern. # # ATTENTION # This function must run in this same shell because of: # read -t 2 output <&"${COPROC[0]} # e.g. Do NOT call this function in this way: # outputVar="$(receiveFromCOPROC)" # This function must be called in this way: # receiveFromCOPROC outputVar [] #----------------------------------------------------------------------------------------------- receiveFromCOPROC () { if [[ -z "$1" ]]; then >&2 echo -e "\nE: receiveFromCOPROC() Missing first parameter" >&2 echo -e " This parameter is a variable that will 'receive' the output of this function\n" exit 1 fi local regexpPattern="" if [[ -n "$2" ]]; then regexpPattern="$2" fi echo "D: receiveFromCOPROC() Receiving COPROC output into variable '$1'" # "recFro_COPROC" is a reference to the variable given as 1st argument. # I am using such a complicated variable name, in order to avoid naming conflicts. # The output of "bluetoothctl" will be writen to "recFro_COPROC" and so also # to the referenced variable given as 1st parameter to this function. declare -n recFro_COPROC=$1 local output="" local lineQty=0 while [[ 1 -eq 1 ]]; do # See https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses read -t 2 output <&"${COPROC[0]}" # Remove color codes, carriage return characters and "[bluetooth]# " from bluetoothctl output output="$(sed 's/\x1B\[[0-9;]*[JKmsu]//g; s/\r//g; s/\[bluetooth\]# *//g' <<< "${output}")" if [[ -n "${regexpPattern}" ]]; then output="$(egrep -e "${regexpPattern}" <<< "${output}")" fi #echo -e "receiveFromCOPROC() output: ${output}" if [[ -z "${output}" ]]; then break fi if [[ ${lineQty} -eq 0 ]]; then recFro_COPROC="${output}" else recFro_COPROC="${recFro_COPROC}\n${output}" fi #echo "${output}" ((lineQty++)) done #if [[ ${lineQty} -gt 0 ]]; then # echo -e "D: receiveFromCOPROC() Received:\n####\n${recFro_COPROC}\n####\n" #fi } doSleep () { echo "I: Sleep ${1} secs ..." sleep ${1} } #--------------------------------------- # Echoes an empty string if Ok # Otherwise the error message #--------------------------------------- isBluetoothServiceOk () { systemctl status bluetooth | grep "Active: failed" } repairIfNeeded () { typeset res="$(isBluetoothServiceOk)" if [[ -n "${res}" ]]; then echo "I: Bluetooth service has a problem. Restarting bluetooth service" systemctl restart bluetooth res="$(isBluetoothServiceOk)" if [[ -n "${res}" ]]; then echo "I: Bluetooth service still has a problem. Abort" exit 1 else echo "I: Bluetooth service is OK now" fi else echo "I: Bluetooth service is OK" fi } isBluetoothCtlRunning () { pgrep -c "bluetoothctl" } killBluetooth () { echo "I: Killing bluetoothctl" pkill "bluetoothctl" } flushCOPROC () { local fl_output >&2 echo "D: flushCOPROC ()" receiveFromCOPROC fl_output echo -e "D: flushing\n++++" while [[ -n "$(egrep -e " Controller |Agent |power on|scan on|Discovery" <<< ${fl_output})" ]]; do receiveFromCOPROC fl_output echo "${fl_output}" done echo "++++" } listDevices () { local ld_output echo "D: listDevices ()" sendToCOPROC "devices" doSleep 1 receiveFromCOPROC ld_output echo -e "D: Listing devices\n*****" while [[ -n "$(egrep -e " Device " <<< ${ld_output})" ]]; do receiveFromCOPROC ld_output echo "${ld_output}" done echo "*****" } sendCmdWaitAndShowOutput () { local cmd="${1}" local sleepTime="${2}" local sCWASO_output sendToCOPROC "${cmd}" doSleep "${sleepTime}" receiveFromCOPROC sCWASO_output } #============= Main ============== if [[ "$(whoami)" != "root" ]]; then echo "E: Wrong user. This script must be started as root" exit 1 fi if [[ $(isBluetoothCtlRunning) -gt 0 ]]; then echo "I: bluetoothctl is already started" killBluetooth #echo "I: systemctl restart bluetooth" #systemctl restart bluetooth #else # repairIfNeeded fi echo "I: Restarting bluetooth to be sure that is works correctly" systemctl restart bluetooth doSleep 2 # See https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses echo "I: Starting 'bluetoothctl' as coprocess" coproc COPROC { bluetoothctl; } doSleep 1 # Cleanup on exit (whenever the exit occurs) trap ' echo "I: Exit trap called" sendToCOPROC "exit" doSleep 3 if [[ $(isBluetoothCtlRunning) -gt 0 ]]; then echo "E: NOK - bluetoothctl is still runnning" killBluetooth else echo "I: OK - bluetoothctl is stopped" fi ' EXIT if [[ $(isBluetoothCtlRunning) -gt 0 ]]; then echo "I: OK - bluetoothctl is started" else echo "E: NOK - bluetoothctl not started" exit 2 fi sendCmdWaitAndShowOutput "power on" 1 sendCmdWaitAndShowOutput "discoverable on" 1 sendCmdWaitAndShowOutput "scan on" 1 #sendCmdWaitAndShowOutput "show" 1 #doSleep 10 #flushCOPROC while [[ ${g_count} -lt ${C_MAX_TRIES} ]]; do ((g_count++)) sendToCOPROC "devices" doSleep 1 g_result="" g_separator="" while [[ 1 -eq 1 ]]; do g_output="" receiveFromCOPROC g_output "Device " if [[ -n "${g_output}" ]]; then g_result="${g_result}${g_separator}${g_output}" g_separator="\n" else break fi done if [[ -n "${g_result}" ]]; then echo -e "I: Found bluetooth device(s)\n-------\n${g_result}\n-------\n" g_result="$(echo -e "${g_result}" | sort -u)" echo -e "I: Found bluetooth device(s) after sort removing duplicates\n-------\n${g_result}\n-------\n" break else echo "E: No bluetooth devide found" fi done #listDevices sendToCOPROC 'scan off'
Output example:
# ./btscanWithCoproc.bash I: Restarting bluetooth to be sure that is works correctly I: Sleep 2 secs ... I: Starting 'bluetoothctl' as co-process I: Sleep 1 secs ... I: OK - bluetoothctl is started I: Sending to COPROC ----- power on ----- I: Sleep 1 secs ... D: receiveFromCOPROC() Receiving COPROC output into variable 'sCWASO_output' I: Sending to COPROC ----- discoverable on ----- I: Sleep 1 secs ... D: receiveFromCOPROC() Receiving COPROC output into variable 'sCWASO_output' I: Sending to COPROC ----- scan on ----- I: Sleep 1 secs ... D: receiveFromCOPROC() Receiving COPROC output into variable 'sCWASO_output' I: Sending to COPROC ----- devices ----- I: Sleep 1 secs ... D: receiveFromCOPROC() Receiving COPROC output into variable 'g_output' E: No bluetooth devide found I: Sending to COPROC ----- devices ----- I: Sleep 1 secs ... D: receiveFromCOPROC() Receiving COPROC output into variable 'g_output' D: receiveFromCOPROC() Receiving COPROC output into variable 'g_output' D: receiveFromCOPROC() Receiving COPROC output into variable 'g_output' I: Found bluetooth device(s) ------- Device 80:**:**:**:**:B9 Galaxy S9 Device 30:**:**:**:**:96 30-**-**-**-**-96 Device 80:**:**:**:**:B9 Galaxy S9 Device 30:**:**:**:**:96 30-**-**-**-**-96 ------- I: Found bluetooth device(s) after sort removing duplicates ------- Device 30:**:**:**:**:96 30-**-**-**-**-96 Device 80:**:**:**:**:B9 Galaxy S9 ------- I: Sending to COPROC ----- scan off ----- I: Exit trap called I: Sending to COPROC ----- exit ----- I: Sleep 3 secs ... I: OK - bluetoothctl is stoppedI hope this helps someone.
Andreas
2020-02-27
How to Copy File From Host to App Data Folder in the Android Emulator
(e.g. from the host the the emulator).
from the "public accessible folder" (i.e. /sdcard/)
to "your App folder" (here for example: /data/data/ch.my.app-name/files/):