Categories
Allgemein

Check permissions before your Android app uses BLE

If you want to implement an android app that use BLE,  the app must get the ACCESS_COARSE_LOCATION permissions. Android will then automatically ask the user if he/she agrees when using a bluetooth function for the first time.(for example at startScan). But if the app has no permissions to use the location, your bluetooth call will fail. Therefore, an early check is better to avoid this problem. 

My approach looks like this:

1) Add to your AndroidManifest.xml:

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

If you only use BLE it es sufficient to request the coarse location permission (location without GPS). If you need a GPS position for your app, you can replace ACCESS_COARSE_LOCATION with ACCESS_FINE_LOCATION. You don’t need both.

2) Then add the permission check to place before the first called bluetooth method.  For example directly after starting the app.

private boolean hasLocationPermission() {

  if (ContextCompat.checkSelfPermission(
    context, 
    Manifest.permission.ACCESS_COARSE_LOCATION
    ) != PackageManager.PERMISSION_GRANTED) {

    ActivityCompat.requestPermissions(
      getCurrentActivity(),
      new String[] {
        Manifest.permission.ACCESS_COARSE_LOCATION
      },
      REQUEST_COARSE_LOCATION_PERMISSIONS);
    return false;
  } else {
    doWhatEverYouWillDoWithBluetooth();
    return true;
  }
}

3) Finally, the callback must be implemented in your activity class to react to the user’s decision

public void onRequestPermissionsResult(
  int requestCode, 
  String permissions[], 
  int[] grantResults) {

  if (requestCode == REQUEST_COARSE_LOCATION_PERMISSIONS) {
    if (grantResults.length > 0 && grantResults[0] ==  
      PackageManager.PERMISSION_GRANTED) {
      
      doWhatEverYouWillDoWithBluetooth();
    } else {
      doWhatEverYouWillDoWithoutBluetooth();
    }
  }
}

That’s it.

Categories
Allgemein

Pause an Azure App Service-Plan

Do you have an Azure App Service Plan and you pay even though you don’t currently need the app.

The problem: Azure offers no way to change or stop an App Service-Plan to save money.

But in some cases there is a possibility to save money. If you don’t need more then 1 GB storage, then you can migrate the app to a free App Service-Plan and remove your chargeable App Service-Plan.

Microsoft has documented how to create an App Service-Plan and how to move an app between two service plan here:  https://docs.microsoft.com/en-us/azure/app-service/app-service-plan-manage

Categories
Allgemein

Cordova android build fails with gradle wrapper error

After updating Android Studio I got the following error message:

could not find gradle wrapper within android sdk. might need to update your android sdk

After some research on the internet I found the following solution: https://stackoverflow.com/questions/31310182/error-could-not-find-gradle-wrapper-within-android-sdk-might-need-to-update-yo

cp -r /Applications/Android\ Studio.app/Contents/plugins/android/lib/templates ~/Library/Android/sdk/tools
chmod a+x ~/Library/Android/sdk/tools/templates/gradle/wrapper/gradlew
Categories
arduino

Arduino and KTY81-210

You have a lot of possibilities to measure the temperature with an arduino. One simple solution is the usage of a KTY81 silicon temperature sensors.
Arduino describes on the playground the usage of KTY81-110. If you have an other type, you need to recalculate the temperature.


(Vcc 5+)--+-->2.7k--+-->kty81-210-->(GND)
          |         |
          +->100nF--+-----> ADC2 (Analog Port 2)

Here is my code to use KTY81-210 with the arduino:

// resistor value of voltage divider in ohm
float resistor = 2700;

void setup() {
  Serial.begin(9600); 
}

void loop() {  
  float temp = kty(2); 
  Serial.print("Temperature: ");
  Serial.println(temp,1); 
  delay (5000);  
}

float kty(unsigned int port) {
   float sensorValue = analogRead(port);  
   float resistance = sensorValue / (1023-sensorValue) * resistor;
   // resistor values from kty81-210 data sheet, written as polynomial trend line
   return -1.332e-11 * pow(resistance,4) + 6.621e-8 * pow(resistance,3) - 0.0002 * pow(resistance,2) + 0.2947 * resistance - 230.55;  
}
Categories
Allgemein

GeekTool calendar view

With this command you will see the calendar with first day monday.

echo `date "+%d %B %Y"` | cal | awk '{ getline; print " Mo Di Mi Do Fr Sa So"; getline; if (substr($0,1,2) == " 1") print " 1 "; do { prevline=$0; if (getline == 0) exit; print " " substr(prevline,4,17) " " substr($0,1,2) " "; } while (1) }' | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" "); a=$0; sub(" "fill int(cday)" ","("fill int(cday)")",a); print a }'

Update: I have changed the command to:

cal | awk '{ getline; print " Mo Di Mi Do Fr Sa So"; getline; if (substr($0,1,2) == " 1") print " 1 "; do { prevline=$0; if (getline == 0) exit; print " " substr(prevline,4,17) " " substr($0,1,2) " "; } while (1) }' | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" "); a=$0; sub(" "fill int(cday)" ","("fill int(cday)")",a); print a }'

Categories
Allgemein

Enable syntax highlighting in MacOS vi

Unfortunately the vi that ships with Mac OS X doesn’t have an optimized configuration file to allow for syntax highlighting
To enable the syntaxx highlighting do

cd /usr/share/vim 
sudo vim vimrc

and add

syntax on ” syntax highlighting

Thats all.

Categories
iOS

iPhone Simulator SpringBoard Crash

If SpringBoard crash, take a look to the details. If you see something about „timezone“, try to select an other city in your timezone. Before crash, I selected Berlin as default. The iPhoneSimulator don’t crash since I select Longyearbyen as nearest location.

Categories
Java JBoss Portal

Retrieving URL parameters from JBoss portlet

Problem:
Retrieving URL parameters from JBoss portlet.

Solution:

RenderRequest request;
or
ActionRequest request;

String value = ((PortletRequestImpl) request).getRealRequest().getParameter(URL_KEY);

Categories
Allgemein

MacBook Beschleunigungssensor

MacBooks sind mit einem(oder zwei) Beschleunigungssensor(en) ausgestattet. Dieser wird verwendet um den Lese/Schreib-Kopf der Festplatte rechtzeitig in die Parkposition zu versetzen, um Plattenfehler zu verhindern. Beschleunigungssensoren werden vor allem beim iPhone eingesetzt. Da kann man durch das Bewegen des iPhones z.B. im Brwoser die Seite hoch und runter scrollen.

Ein OpenSource-Projekt hat es sich zur Aufgabe gemacht, den Beschleunigungssensor der MacBooks für weitere Anwendungszwecke nutzbar zu machen. Das Projekt heisst AMS2HID. Es ermöglicht den Sensor direkt in Eingabebefehle umzusetzen (z.B. Mausbewegungen, Tasten). Der Anwendungsfall: Erdbebenvorwarnung wird sich in unseren Breiten eher nicht durchsetzen.

Sinnvoll finde ich das Tool z.B. bei Sites (nur Leopard) Siehe dazu das Video unten
Ich kann jedem MacUser nur empfehlen sich das kleine Tool mal zu installieren (Natürlich außerhalb der Arbeitszeit). Man hat viel Spaß. Vor allem nicht MacUser werden beeindruckt sein.

Download: http://www.osxbook.com/software/sms/ams2hid

Anwendungsfälle:
* Sites
* Neverball
* Autorennen
* Safari

Categories
Allgemein

VMware Fusion: Probleme mit Soundwiedergabe

Lässt sich in VMware Fusion 1.1 der Sound nicht verbinden, dann ist hier die Lösung:

    • Die VMX-Datei der VM mit einem Texteditor öffnen. (Vorher natürlich die VM beenden)
      Dann die Zeile mit sound.virtualDev = "sb16" suchen und sb16 durch es1371 ersetzen.
      Jetzt die VM neue starten und nach neuer Hardware suchen.
  • Jetzt sollte es gehen.