开发者

Determining if a device is using HTC SenseUI

How can I tell if a device is using HTC's SenseUI?

I thought about using android.os.Build information, but they seem inconsistent.. is there a more defin开发者_运维百科itive way?

I need to be able to tell if I can launch the calendar by using com.android.calendar or com.htc.calendar.

I welcome any suggestions!!


You are welcome to use PackageManager to see if com.htc.calendar exists on the device. And you can use PackageManager to derive an Intent useful for opening that package. Whether that will "launch the (HTC) calendar" is up to HTC and Android, not you.

Also, as Marya suggests, what you are doing is not a good idea, because there is no rule that HTC will use com.htc.calendar on every Sense device, now and in the future.


Based on CommonsWare's suggestion, the following is what I ended up using. I hope this is helpful to others.

    PendingIntent pendingIntent = null;
    Intent defineIntent = null;

    String thePackage = "com.android.calendar";
    String theClassName = "com.android.calendar.LaunchActivity";

    try {
        PackageManager thePackageManager = context.getPackageManager();
        thePackageManager.getPackageInfo(thePackage,PackageManager.GET_ACTIVITIES);
    } catch (PackageManager.NameNotFoundException e){
        // regular android calendar doesn't exist

        // so try the htc sense one
        thePackage = "com.htc.calendar";
        theClassName = "com.htc.calendar.LaunchActivity";               
    }

    defineIntent = new Intent(Intent.ACTION_MAIN)
        .addCategory(Intent.CATEGORY_LAUNCHER)
        .setComponent(new ComponentName(thePackage, theClassName));

    pendingIntent = PendingIntent.getActivity(context,
        0 /* no requestCode */, defineIntent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.widget, pendingIntent);


String thePackage = "com.android.calendar";
String theClassName = "com.android.calendar.LaunchActivity";
Intent defineIntent = null;

try {
    PackageManager PACKAGE_NAME = getApplicationContext().getPackageManager();
    PACKAGE_NAME.getPackageInfo(thePackage,PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e){
    // regular android calendar doesn't exist
    // so try the htc sense one
    thePackage = "com.sonyericsson.calendar";
    theClassName = "com.sonyericsson.calendar.MonthActivity";               
}

defineIntent = new Intent(Intent.ACTION_MAIN); 
defineIntent.setComponent(new ComponentName(thePackage, theClassName)); 
startActivity(defineIntent); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜