{"id":26751567,"url":"https://github.com/sayed3li97/androidalarmclockapp-android","last_synced_at":"2025-03-28T12:18:40.236Z","repository":{"id":198676328,"uuid":"168216298","full_name":"sayed3li97/AndroidAlarmClockApp-Android","owner":"sayed3li97","description":"A Simple Alarm colock app that is used as an excrsise to teach begginers in Android how to create and use services in addtion it teachs them how to interact with diffrent view's and how to create a notification and finally how to interact with the phone to use the ringtone as an alarm. ","archived":false,"fork":false,"pushed_at":"2021-12-10T11:05:40.000Z","size":311,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-10-06T11:41:45.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayed3li97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-01-29T19:39:22.000Z","updated_at":"2023-10-06T11:41:47.324Z","dependencies_parsed_at":null,"dependency_job_id":"75af8697-b125-45fd-8203-81cd364e53cc","html_url":"https://github.com/sayed3li97/AndroidAlarmClockApp-Android","commit_stats":null,"previous_names":["sayed3li97/androidalarmclockapp-android"],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayed3li97%2FAndroidAlarmClockApp-Android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayed3li97%2FAndroidAlarmClockApp-Android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayed3li97%2FAndroidAlarmClockApp-Android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayed3li97%2FAndroidAlarmClockApp-Android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayed3li97","download_url":"https://codeload.github.com/sayed3li97/AndroidAlarmClockApp-Android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246026095,"owners_count":20711581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-28T12:18:38.637Z","updated_at":"2025-03-28T12:18:39.813Z","avatar_url":"https://github.com/sayed3li97.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AndroidAlarmClockApp\nA Simple Alarm clock app that is used as an exercise to teach beginners in Android how to create and use services in addition, it teaches them how to interact with different view's and how to create a notification and finally how to interact with the phone to use the ringtone as an alarm. \n\n# Screenshots \n\u003cimg src=\"/screenshots/screenshot1.png\" width=\"220\" height=\"400\"\u003e \u003cimg src=\"/screenshots/screenshot2.png\" width=\"220\" height=\"400\"\u003e \n\nNotification \n\u003cimg src=\"/screenshots/screenshot3_noti.png\" \u003e \n\n# Step to re-create \n\n1. Create a new project in Android Studio (Choose the Empty Activity)\n2. Navigate to app/res/layout/activity_main.xml\n3. Open the \"Text\" view and replace the XML code with the below code or Change the ConstraintLayout to RelativeLayout. Add TimePicker, ToggleButton, and a TextView into your layout\n\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    tools:context=\".MainActivity\"\u003e\n\n    \u003cTimePicker\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:id=\"@+id/alarmTimePicker\"\n        android:layout_alignParentTop=\"true\"\n        android:layout_centerHorizontal=\"true\" /\u003e\n\n\n    \u003cToggleButton\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Alarm On/Off\"\n        android:id=\"@+id/alarmToggle\"\n        android:layout_centerHorizontal=\"true\"\n        android:layout_below=\"@+id/alarmTimePicker\"\n        android:onClick=\"onToggleClicked\" /\u003e\n\n    \u003cTextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:textAppearance=\"?android:attr/textAppearanceLarge\"\n        android:text=\"\"\n        android:id=\"@+id/alarmText\"\n        android:layout_alignParentBottom=\"true\"\n        android:layout_centerHorizontal=\"true\"\n        android:layout_marginTop=\"20dp\"\n        android:layout_below=\"@+id/alarmToggle\" /\u003e\n\n\u003c/RelativeLayout\u003e\n```\n4. Create a new Java file named it **AlarmService.java** in the following path app/java/\"The first folder\"/\n5. Replace the code in that file with the below code (\"Don't remove the first line starting with the package\")\n\n```\nimport android.app.IntentService;\nimport android.app.NotificationManager;\nimport android.app.PendingIntent;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.support.v4.app.NotificationCompat;\nimport android.util.Log;\n\npublic class AlarmService extends IntentService {\n    private NotificationManager alarmNotificationManager;\n\n    public AlarmService() {\n        super(\"AlarmService\");\n    }\n\n    @Override\n    public void onHandleIntent(Intent intent) {\n        sendNotification(\"Wake Up! Wake Up!\");\n    }\n\n    private void sendNotification(String msg) {\n        Log.d(\"AlarmService\", \"Preparing to send notification...: \" + msg);\n        alarmNotificationManager = (NotificationManager) this\n                .getSystemService(Context.NOTIFICATION_SERVICE);\n\n        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,\n                new Intent(this, MainActivity.class), 0);\n\n        NotificationCompat.Builder alamNotificationBuilder = new NotificationCompat.Builder(\n                this).setContentTitle(\"Alarm\").setSmallIcon(R.mipmap.ic_launcher)\n                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))\n                .setContentText(msg);\n\n\n        alamNotificationBuilder.setContentIntent(contentIntent);\n        alarmNotificationManager.notify(1, alamNotificationBuilder.build());\n        Log.d(\"AlarmService\", \"Notification sent.\");\n    }\n}\n```\n6.  Create a new Java file named it **AlarmReceiver.java** in the following path app/java/\"The first folder\"/\n7.  Replace the code in that file with the below code (\"Don't remove the first line starting with the package\")\n```\nimport android.app.Activity;\nimport android.content.ComponentName;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.media.Ringtone;\nimport android.media.RingtoneManager;\nimport android.net.Uri;\nimport android.support.v4.content.WakefulBroadcastReceiver;\n\npublic class AlarmReceiver extends WakefulBroadcastReceiver {\n\n    @Override\n    public void onReceive(final Context context, Intent intent) {\n        //this will update the UI with message\n        MainActivity inst = MainActivity.instance();\n        inst.setAlarmText(\"Alarm! Wake up! Wake up!\");\n\n        //this will sound the alarm tone\n        //this will sound the alarm once, if you wish to\n        //raise alarm in loop continuously then use MediaPlayer and setLooping(true)\n        Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);\n        if (alarmUri == null) {\n            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);\n        }\n        Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);\n        ringtone.play();\n\n        //this will send a notification message\n        ComponentName comp = new ComponentName(context.getPackageName(),\n                AlarmService.class.getName());\n        startWakefulService(context, (intent.setComponent(comp)));\n        setResultCode(Activity.RESULT_OK);\n    }\n}\n```\n\n8. Open the java file for the main activity by opening the MainActivity.java from the following path app/java/\"The first folder\"/MainActivity.java\n9. Add the below code before the OnCreate Method \n```\n    AlarmManager alarmManager;\n    private PendingIntent pendingIntent;\n    private TimePicker alarmTimePicker;\n    private static MainActivity inst;\n    private TextView alarmTextView;\n\n    public static MainActivity instance() {\n        return inst;\n    }\n\n    @Override\n    public void onStart() {\n        super.onStart();\n        inst = this;\n    }\n```\n10. Inside of the OnCreate method add the following code \n```\n        alarmTimePicker = (TimePicker) findViewById(R.id.alarmTimePicker);\n        alarmTextView = (TextView) findViewById(R.id.alarmText);\n        ToggleButton alarmToggle = (ToggleButton) findViewById(R.id.alarmToggle);\n        alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);\n```\n11. After the OnCreate Method, add the following code \n```\n public void onToggleClicked(View view) {\n        if (((ToggleButton) view).isChecked()) {\n            Log.d(\"MyActivity\", \"Alarm On\");\n            Calendar calendar = Calendar.getInstance();\n            calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());\n            calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());\n            Intent myIntent = new Intent(MainActivity.this, AlarmReceiver.class);\n            pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);\n            alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);\n        } else {\n            alarmManager.cancel(pendingIntent);\n            setAlarmText(\"\");\n            Log.d(\"MyActivity\", \"Alarm Off\");\n        }\n    }\n\n    public void setAlarmText(String alarmText) {\n        alarmTextView.setText(alarmText);\n    }\n```\n\n12. Open the **AndroidManifest.xml** and add the following code before ```\u003capplication android:..... ```\nThe bellow is the permission that will allow the app to keep the screen awake. \n```\n    \u003cuses-permission android:name=\"android.permission.WAKE_LOCK\" /\u003e\n\n```\n13. In the same file **AndroidManifest.xml**  After the last ```\u003c/activity\u003e ``` and before ```\u003c/application\u003e``` add the code bellow \nThe code below is a Service that will run in the background.\n```\n          \u003cservice\n            android:name=\".AlarmService\"\n            android:enabled=\"true\" /\u003e\n        \u003creceiver android:name=\".AlarmReceiver\" /\u003e\n```\n\nThank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayed3li97%2Fandroidalarmclockapp-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayed3li97%2Fandroidalarmclockapp-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayed3li97%2Fandroidalarmclockapp-android/lists"}