Error in building Alarm app from android source

不问归期 提交于 2019-12-04 01:54:47

问题


I want to build an app which extends basic alarm clock functionality. Since I am not inventing any wheel in the alarm functionality, I would like to use the android default alarm which is available openly.

However I have tried to build it many times but there are just too many errors (mentioned here also):

I tried this approach also but I am still not able to build it.

Can anyone please guide on how to build the android application provided in git android tree.

Links I referred to:

  1. Alarm clock code: mContext variable cant be resolved

  2. Alarm Clock from GIT - Gives error - Android

Updates:

1.)

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

Solved this error but replacing the line with (Thanks to @shayanpourvatan ):

final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED"; Intent alarmChanged = new Intent(ACTION_ALARM_CHANGED);

2.)

    AlarmKlaxon.java
    Line 89: mVibrator = new Vibrator();
    Error: Cannot instantiate the type Vibrator

    -----------------------------------

Solved by replacing the line with:

mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

3.)

SetAlarm.java
    Line 115: FrameLayout content = (FrameLayout) getWindow().getDecorView()
                .findViewById(com.android.internal.R.id.content);
    Error:com.android.internal.R cannot be resolved to a variable

Solved by replacing :

 com.android.internal.R.id.content into android.R.id.content

回答1:


Solved all the error and was able to compile and run on device. Need to do testing and check for deprecations. Here is how I solved them:

1.)

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

Solved this error but replacing the line with (Thanks to @shayanpourvatan ):

final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED"; Intent alarmChanged = new Intent(ACTION_ALARM_CHANGED);

2.)

AlarmKlaxon.java
Line 89: mVibrator = new Vibrator();
Error: Cannot instantiate the type Vibrator

-----------------------------------

Solved by replacing the line with:

mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

3.)

SetAlarm.java
    Line 115: FrameLayout content = (FrameLayout) getWindow().getDecorView()
                .findViewById(com.android.internal.R.id.content);
    Error:com.android.internal.R cannot be resolved to a variable

Solved by replacing :

com.android.internal.R.id.content into android.R.id.content

And the lastly:

The specified child already has a parent

error is fixed as mentioned below:

The specified child already has a parent in google alarmclock code



来源:https://stackoverflow.com/questions/22864856/error-in-building-alarm-app-from-android-source

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