10

Can I somehow detect if my app is running on HTC Sense?

More generally, the problem is, that I have a Button with custom drawable. It's something very similar to the account switcher in the top right of Gmail app. When pressed or focused, the button has orange highlight. But that doesn't look nice on HTC Sense - because the standard highlight color there is green.

fhucho
  • 34,062
  • 40
  • 136
  • 186

5 Answers5

3

Lets see android.os.Build strings I am not sure what the HTC folks use a combination to indicate a HTC sense device..

Fred Grott
  • 3,505
  • 1
  • 23
  • 18
3

Here's a link suggesting a way to detect HTC Sense on the device, about 1/3 the way down the discussion. I've tested on Desire and Desire Z.

Code is below (from a user: David):

private static final String SENSE_UI_LAUNCHER_NAME = 
          "com.htc.launcher.Launcher"; 
    private static Boolean senseUI; 

    public static final boolean isSenseUI(Context context) {
        if (senseUI == null) {
            senseUI = false;
            PackageManager packageManager = context.getPackageManager();

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            List<ResolveInfo> list = packageManager.queryIntentActivities(
                    intent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo info : list) {
                if (info.activityInfo != null
                        && SENSE_UI_LAUNCHER_NAME
                                .equals(info.activityInfo.name)) {
                    senseUI = true;
                    break;
                }
            }
        }
        return senseUI;
    }
scottyab
  • 23,621
  • 16
  • 94
  • 105
1

I think that Android has provided a better way for you to solve this than doing a check for Sense, and it will work for every device manufacturer. HTC isn't the only one who has changed the colors on the selectors. I think Sony Ericsson has a transparent white/blue, Motorola changed it to red in their MotoBlur UI, and Garmin-Asus changed it to blue in theirs just to name a few.

What you should do is override the android:background attribute on your image button and use a drawable of your own instead of relying on the framework's background drawable. If you're not already familiar with them, you'll probably also want to take a look at Selectors when you create your custom background, so you still get the pressed/selected/not-selected color cues.

If you have multiple buttons that you want to do this on, you may want to use styles and themes to help out with this. The two primary places you'll want to reference from the Android documentation are "Applying Styles and Themes" and "Style Resources"

Hope that helps!

John
  • 810
  • 6
  • 3
  • In the question I am saying that I do use a custom drawable. The highlight color is orange which doesn't look "native" in HTC Sense. There's no easy way to solve this in Android, because every manufacturer can have its own UI style... :( All I can do is detect if I'm on Sense and set the green drawable. I know that there are other UI customization apart from Sense, but I want to deal with Sense only, because it's so widespread. – fhucho Sep 12 '10 at 13:20
0

This is a bit late, but I think this solution might work on some people cases.

I tried to use Build.MANUFACTURER to check if it is a HTC device. This solution doesnt work on some devices and we can ensure that that devices is running Sense anyway

If you notice, you may see Play Store needs to check what features available on the phone to display correct apps, and HTC Sense is one of the features!

To get all available features:

public FeatureInfo[] getSystemAvailableFeatures(Context context) {
        FeatureInfo[] features = context.getPackageManager().getSystemAvailableFeatures();
        for (FeatureInfo f : features) {
            Log.d("Features", "feature " + f.name);
        }
        return features;
}

This will return something like these:

com.example D/Features﹕ Feature android.hardware.wifi
com.example D/Features﹕ Feature android.hardware.location.network
com.example D/Features﹕ Feature com.sec.android.mdm
com.example D/Features﹕ Feature android.hardware.location
com.example D/Features﹕ Feature android.hardware.sensor.gyroscope
com.example D/Features﹕ Feature android.hardware.screen.landscape
com.example D/Features﹕ Feature com.htc.software.Sense5.0

Notice the last line! You can use it to check HTC sense version

Hope it helps

Cuong Thai
  • 1,165
  • 1
  • 11
  • 24
0

I think the following approach should be followed - we define android:background, something like

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
    <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/focused_application_background" />
    <item android:state_focused="true" android:state_window_focused="false" android:drawable="@android:color/transparent" />
</selector>

But here we should refer to some standard resources, not to the images of our application. Just need to find out which ids they have.

LA_
  • 19,823
  • 58
  • 172
  • 308