Tuesday, March 26, 2013

Missed placed your installation MSI and need to move Application to another machine?

I was working away from my home office and my library of MSIs was not accessible. I wanted to install some software on a new machine NOW, instead of waiting until I got home in a few weeks.

 

I remembered that everything that is installed has a copy of the installation MSI copied to C:\Windows\Installer (so programs can be uninstalled later). looking in this folder, I saw {temp file names}.msi and not the original MSI names – rats!  Wait a minute, the MSI’s likely contains information on what it is in its properties.

  1. Left clicking on the file list allows you to select what is displayed.

image

Clicking More… gives you “Subject” which is what I am looking for:

image

Now I see what all of the MSI are!
image

Now, I just copy (NOT move) the desired MSI’s to another folder, and renamed them appropriately.  If you move them, then you will cause problems if you wish to adjust features at a later time.

 

I can now install the stuff that I want, now!

Wednesday, March 13, 2013

Android Low Energy Bluetooth or a feature that I would love to see in C#

Recently I have been playing with BLE on Android (Samsung S3). One of the issues is no exposed BLE API in the current version of Android. I said, exposed, because by reflection you can find them! Or at least some of them, in some cases, you need to access the BLE library that was supplied to the phone (but not connected to the Android OS.

 

The process is very simple to identified the library:

 

First, add the following to the manifest:

 

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library
        android:name="com.broadcom.bt.le"
        android:required="false" />
    <uses-library
        android:name="com.csr.bluetooth.BluetoothExt"
        android:required="false" />
    <uses-library
        android:name="com.htc.android.bluetooth.le"
        android:required="false" />
    <uses-library
        android:name="android.server.BluetoothGattService"
        android:required="false" />
    <uses-library
        android:name="com.samsung.bluetoothle.BluetoothLEClientProfile"
        android:required="false" />

 

Then create an enumeration. This is very much a Java enumeration (you don’t see this in C#)

 

public enum HardwareEnum {
    Motorola("android.server.BluetoothGattService"), Broadcom(
            "com.broadcom.bt.le.api.BleAdapter"), Csr(
            "com.csr.bluetooth.BluetoothExt"), Htc(
            "com.htc.android.bluetooth.le"), Samsung(
            "com.samsung.bluetoothle.BluetoothLEClientProfile"), None("");
    private final String value;

    HardwareEnum(String value) {
        this.value = value;
    }

    public String getClassName() {
        return value;
    }
}

Next you need to write a detector, which is very simple with the above enumeration.

 

public class HardwareDetector {
    /*
     * Each of the class names MUST be in the Manifest. as <uses-library
     * android:name="com.broadcom.bt.le" android:required="false" />
     */
    private static final String TAG = "HardwareDetector";

    public static HardwareEnum detectHardware() {

        HardwareEnum result = HardwareEnum.None;
        for (HardwareEnum item : HardwareEnum.values())
            try {
                Log.i(TAG, "testing:" + item);
                Class.forName(item.getClassName());// , false, null);
                result = item;
                Log.i(TAG, "found:" + item);
                return result;
            } catch (Exception exc) {
                Log.w(TAG, exc.toString());
            }
        return result;
    }
}

Now, you know the library that talks to the BLE on your phone. You may wish to use reflection to explore what is in the library and develop code from there.

 

What is the missing feature from C#?

Simple, being able to do enumerations consisting of objects. While working with Android code, I found that this pattern allowed massive simplification of code and much improved clarity…   Microsoft folks, please add something like this!