在我看来,由于每个制造商都实现了自己的时钟应用程序,
因此,Android 的默认 AlarmClockApp 会根据每个制造商的不同而被替换,这使得如果 Android 操作系统被制造商修改过,您的代码将无法成功运行。
所以我认为我们不能处理这种情况下的所有设备,相反,我们应该由设备制造商处理它。
对于三星设备,它是 ClockPackage 和 androidManifest :
<provider
android:name=".alarm.AlarmProvider"
android:authorities="com.samsung.sec.android.clockpackage"
android:exported="true"
android:readPermission="com.sec.android.app.clockpackage.permission.READ_ALARM"
android:writePermission="com.sec.android.app.clockpackage.permission.WRITE_ALARM" >
</provider>
因此我们可以通过以下方式读取三星设备中的警报数据:
在清单中添加权限:
<uses-permission android:name="com.sec.android.app.clockpackage.permission.READ_ALARM" />
然后通过以下方式获取 Uri:
Uri uri = Uri.parse("content://com.samsung.sec.android.clockpackage/alarm");
使用 Uri :
Cursor c = getContentResolver().query(uri, null, null, null, null);
if (c == null) { // that mean devices is not belong to Samsung manufacturer,
// we should use an other uri (don't for get to add permission)
AlarmLog.w("Can not read cursor");
}
AlarmLog.i(tag_alarm, "no of records are " + c.getCount());
AlarmLog.i(tag_alarm, "no of columns are " + c.getColumnCount());
if (c != null) {
String names[] = c.getColumnNames();
for (String temp : names) {
AlarmLog.d(tag_alarm, temp);
}
if (c.moveToFirst()) {
do {
for (int j = 0; j < c.getColumnCount(); j++) {
AlarmLog.i(tag_alarm, c.getColumnName(j)
+ " which has value " + c.getString(j));
}
} while (c.moveToNext());
}
}
希望它有帮助并接收其他制造商的代码。