如何判断设备是否使用HTC的SenseUI?确定设备是否使用HTC SenseUI
我想过使用android.os.Build的信息,但他们似乎不一致..有没有更确定的方式?
我需要能够通过使用com.android.calendar或com.htc.calendar来判断我是否可以启动日历。
我欢迎任何建议!
如何判断设备是否使用HTC的SenseUI?确定设备是否使用HTC SenseUI
我想过使用android.os.Build的信息,但他们似乎不一致..有没有更确定的方式?
我需要能够通过使用com.android.calendar或com.htc.calendar来判断我是否可以启动日历。
我欢迎任何建议!
欢迎使用PackageManager
来查看设备上是否存在com.htc.calendar
。您可以使用PackageManager
来派生出一个可用于打开该包的Intent
。是否会推出(HTC)日历“取决于HTC和Android,而不是你。
另外,正如玛丽亚所说,您所做的并不是一个好主意,因为没有规定HTC在每个Sense设备上现在和将来都会使用com.htc.calendar
。
然后启动日历意向的更好方法是什么? – 2010-08-26 01:31:49
@atolar:Calendar应用程序不是Android SDK的一部分。对于HTC或“普通”Android而言,没有记录和支持的方式来“发布日历意图”。 – CommonsWare 2010-08-26 04:14:04
根据CommonsWare的建议,以下是我最终使用的。我希望这对他人有帮助。
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);
我知道这不是你的问题,但是写这取决于无证的API这样的应用程序之前,我会三思而后行。新手机出来后,你的应用必然会崩溃。请参阅Commonsware有关此文章的文章:http://www.androidguys.com/2009/12/14/code-pollution-reaching-past-the-sdk/ – 2010-08-25 22:20:19