PackageManager packageManager = getPackageManager();
Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// Verify clock implementation
String clockImpls[][] = {
{"HTC Alarm Clock","com.htc.android.worldclock","com.htc.android.worldclock.WorldClockTabControl" },
{"Standar Alarm Clock","com.android.deskclock","com.android.deskclock.AlarmClock"},
{"Standar Alarm Clock2","com.android.deskclock","com.android.deskclock.DeskClock"},
{"Froyo Nexus Alarm Clock","com.google.android.deskclock","com.android.deskclock.DeskClock"},
{"Moto Blur Alarm Clock","com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"},
{"Samsung Galaxy Clock","com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"},
{"Google Galaxy Nexus Clock","com.google.android.deskclock","com.android.deskclock.AlarmClock"}
};
boolean foundClockImpl =false;
for(int i=0; i<clockImpls.length; i++) {
String vendor = clockImpls[i][0];
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
ActivityInfo aInfo = packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
alarmClockIntent.setComponent(cn);
System.out.println("Found " + vendor +" --> " + packageName +"/" + className);
foundClockImpl = true;
} catch (NameNotFoundException e) {
System.out.println(vendor +" does not exists");
}
}
if (foundClockImpl) {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, alarmClockIntent, 0);
// add pending intent to your component
remoteViews.setOnClickPendingIntent(R.id.TimeLeftHotArea,
pendingIntent);
}
不同生产商调用的包名类名的查看:
android-sdk\tools\hierarchyviewer.bat,打开这个工具,手机连接电脑,启动对应界面,就能看到包名 类名