在我的应用程序中,我创建了小部件以模拟时钟格式显示时间。当单击小部件实际显示警报类以设置该小部件的警报时,它也可以正常工作。
为此,我使用了以下代码:
当单击小部件时,我将其称为更新并从中获取警报类:
PendingIntent pendingIntent = PendingIntent.getActivity(
context, 0, getAlarmPackage(context), 0);
rv_ana.setOnClickPendingIntent(R.id.clock, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, rv_ana);
及报警功能方法:
public Intent getAlarmPackage(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER);
String clockImpls[][] = {
{ "Standard Alarm", "com.android.alarmclock",
"com.android.alarmclock.AlarmClock" },
{ "HTC Alarm ClockDT", "com.htc.android.worldclock",
"com.htc.android.worldclock.WorldClockTabControl" },
{ "Standard Alarm ClockDT", "com.android.deskclock",
"com.android.deskclock.AlarmClock" },
{ "Froyo Nexus Alarm ClockDT", "com.google.android.deskclock",
"com.android.deskclock.DeskClock" },
{ "Moto Blur Alarm ClockDT", "com.motorola.blur.alarmclock",
"com.motorola.blur.alarmclock.AlarmClock" },
{ "Samsung Galaxy S", "com.sec.android.app.clockpackage",
"com.sec.android.app.clockpackage.ClockPackage" }
};
boolean foundClockImpl = false;
for (int i = 0; i < clockImpls.length; i++) {
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
packageManager.getActivityInfo(
cn, PackageManager.GET_META_DATA);
AlarmClockIntent.setComponent(cn);
foundClockImpl = true;
} catch (NameNotFoundException nf) {
}
}
if (foundClockImpl) {
return AlarmClockIntent;
} else {
return null;
}
}
但我的要求是从这个闹钟功能中我如何才能得到小时和分钟的时间。实际上该功能会自动显示警报,但我想知道时间。有没有可能?帮我?