Alarm Clock from GIT - Gives error - Android

余生颓废 提交于 2019-12-24 17:16:38

问题


I downloaded the alarm clock example from the below link:

https://github.com/android/platform_packages_apps_alarmclock

I fixed most of the except the following:

Alarms.java: Line 463: Intent alarmChanged = new Intent(Intent.ACTION_ALARM_CHANGED); Error: ACTION_ALARM_CHANGED cannot be resolved or is not a field.

Not able to get this fixed. searched most of SO and Google group. No perfect solution.

I am running minSDK for 9 and target of 18.

Can somebody help me out fix this up?

Thanks!


回答1:


What you downloaded isn't really an 'example', but rather the source of a system application. As such, it has access to certain parts of the SDK that you can't normally access yourself, because the app gets built directly against the source code of Android.

If you look at the Intent source code, you'll find the following snippet:

/**
 * Alarm Changed Action: This is broadcast when the AlarmClock
 * application's alarm is set or unset.  It is used by the
 * AlarmClock application and the StatusBar service.
 * @hide
 */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";

Note the @hide annotation at the last line of the Javadoc. This indicates that the constant is not part of the public Android SDK. The part of the build process that creates the Android SDK will not include this member in the stub edition of android.content.Intent that is in the android.jar file that you are compiling against.

The @hide annotation is used for things that for internal purposes needed to be public or protected but are not considered something SDK developers should be using.

Also refer to @CommonWare's answer on this matter, or Romain Guy's over at Google Groups.

In short: you can't use that constant. You could try replacing it with its string value ("android.intent.action.ALARM_CHANGED"), but remember that there's probably a good reason for it not being available to developers. Knowing that, you should really not be attempting to use it at all.




回答2:


I think that maybe it's a problem of the imports. Try checking the imports of your class. Sometimes Eclipse imports the R.java class from the android package and stop using yours. Remove imports like import android.R



来源:https://stackoverflow.com/questions/18201666/alarm-clock-from-git-gives-error-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!