Error in building Alarm app from android source

2020-03-30 05:44发布

问题:

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