Android - Simple Alarm Application

View: 70    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

9 point/1 review File has been tested

Download  android-simple-alarm.zip (540.99 KB)

You need to Sign In to download the file android-simple-alarm.zip
If you do not have an account then Sign up for free here

In this tutorial we will try to create a Simple Alarm Application using Android. This simple application can be used to make a schedule of your meeting, birthday, etc, just to make on time with it. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc. So now let's do the coding.....

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html.

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> xmlns:app="<a href="http://schemas.android.com/apk/res-auto"
  5. " rel="nofollow">http://schemas.android.com/apk/res-auto"
  6. </a> xmlns:tools="<a href="http://schemas.android.com/tools"
  7. " rel="nofollow">http://schemas.android.com/tools"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simplealarmapplication.MainActivity">
  11.  
  12.  
  13. <TextView
  14. android:id="@+id/tv_display"
  15. android:layout_height="wrap_content"
  16. android:layout_width="wrap_content"
  17. android:text="Alarm not set"
  18. android:textSize="20sp"
  19. android:layout_marginTop="20dp"
  20. android:layout_centerHorizontal="true"/>
  21.  
  22. <TimePicker
  23. android:layout_below="@+id/tv_display"
  24. android:id="@+id/tp_time"
  25. android:layout_height="wrap_content"
  26. android:layout_width="match_parent" />
  27.  
  28. android:id="@+id/btn_set"
  29. android:layout_below="@+id/tp_time"
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. android:text="Set Alarm"/>
  33.  
  34. android:id="@+id/btn_reset"
  35. android:layout_below="@+id/btn_set"
  36. android:layout_width="match_parent"
  37. android:layout_height="wrap_content"
  38. android:text="Reset Alarm"/>
  39. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> package="com.razormist.simplealarmapplication">
  5.  
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:roundIcon="@mipmap/ic_launcher_round"
  11. android:supportsRtl="true"
  12. android:theme="@style/AppTheme">
  13. <activity android:name=".MainActivity"
  14. android:configChanges="orientation"
  15. android:screenOrientation="portrait">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  18.  
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22.  
  23. <receiver android:name=".AlarmAdapter"
  24. android:enabled="true"
  25. android:exported="true" />
  26. </application>
  27. </manifest>

Creating the Alarm Adapter

This code contains the script for the alarm. This will try to receive the request from the context to trigger the sound for the alarm. To do that create a new java class called AlarmAdapter then write these block of codes inside of it.

  1. package com.razormist.simplealarmapplication;
  2.  
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.media.MediaPlayer;
  7. import android.provider.Settings;
  8.  
  9. /**
  10.  * Created by Arvin on 5/5/2018.
  11.  */
  12.  
  13. public class AlarmAdapter extends BroadcastReceiver {
  14.  
  15. @Override
  16. public void onReceive(Context context, Intent intent) {
  17. MediaPlayer mediaPlayer = MediaPlayer.create(context, Settings.System.DEFAULT_RINGTONE_URI);
  18. mediaPlayer.start();
  19. }
  20. }

The Main Function

This code contains the main function of the application. This code will set the alarm then call the receiver to start the alarm base on the time given. To start with first locate your MainActivity java file and open it, then write these variable inside the MainActivity class.

  1. TimePicker tp_time;
  2. TextView tv_display;
  3. Button btn_set, btn_reset;

Finally, initialize the require methods inside the onCreate method to run the application.

  1. tv_display = (TextView)findViewById(R.id.tv_display);
  2. tp_time = (TimePicker)findViewById(R.id.tp_time);
  3. btn_set = (Button)findViewById(R.id.btn_set);
  4. btn_reset = (Button)findViewById(R.id.btn_reset);
  5.  
  6. btn_set.setOnClickListener(new View.OnClickListener() {
  7. @Override
  8. public void onClick(View v) {
  9. Calendar calendar = Calendar.getInstance();
  10.  
  11. if(Build.VERSION.SDK_INT >= 23) {
  12.  
  13. calendar.set(
  14. calendar.get(Calendar.YEAR),
  15. calendar.get(Calendar.MONTH),
  16. calendar.get(Calendar.DAY_OF_MONTH),
  17. tp_time.getHour(),
  18. tp_time.getMinute(),
  19. 0
  20. );
  21.  
  22.  
  23.  
  24. }else{
  25. calendar.set(
  26. calendar.get(Calendar.YEAR),
  27. calendar.get(Calendar.MONTH),
  28. calendar.get(Calendar.DAY_OF_MONTH),
  29. tp_time.getCurrentHour(),
  30. tp_time.getCurrentMinute(),
  31. 0
  32. );
  33. }
  34.  
  35.  
  36. setAlarm(calendar.getTimeInMillis(), calendar);
  37. }
  38.  
  39.  
  40. private void setAlarm(long timeInMillis, Calendar c) {
  41. AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  42.  
  43. Intent intent = new Intent(MainActivity.this, AlarmAdapter.class);
  44.  
  45. PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
  46.  
  47. alarmManager.setRepeating(AlarmManager.RTC, timeInMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
  48.  
  49. Toast.makeText(MainActivity.this, "Alarm Set", Toast.LENGTH_SHORT).show();
  50. int hour = c.get(Calendar.HOUR_OF_DAY);
  51. int minute = c.get(Calendar.MINUTE);
  52. int ampm = c.get(Calendar.AM_PM);
  53. String day = "";
  54. if(ampm == Calendar.AM){
  55. day = "AM";
  56. }else if(ampm == Calendar.PM){
  57. day = "PM";
  58. }
  59. String timeText = "Alarm set for: ";
  60. timeText += hour +": " + minute + " " + day;
  61. tv_display.setText(timeText);
  62.  
  63. }
  64.  
  65.  
  66. });
  67.  
  68.  
  69.  
  70.  
  71. btn_reset.setOnClickListener(new View.OnClickListener() {
  72. @Override
  73. public void onClick(View v) {
  74.  
  75. AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  76.  
  77. Intent intent = new Intent(MainActivity.this, AlarmAdapter.class);
  78.  
  79. PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
  80.  
  81. alarmManager.cancel(pendingIntent);
  82.  
  83. tv_display.setText("Alarm not set");
  84.  
  85. }
  86. });

Try to run the app and see if it worked.

There you have it we have created a Simple Alarm Application using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Android - Simple Alarm Application

Android - Simple Alarm Application Posted on 07-05-2018  Learn on how to create a Simple Alarm Application using Android. This simple application can be used to make a schedule of your meeting, birthday, etc, just to make on time with it. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc. 9/10 70

Comment:

To comment you must be logged in members.

Files with category

  • Simple Calculator

    Simple Calculator

    View: 10    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is my simple calculator application for android mobile phone. It performs basic operations such as addition, multiplication, subtraction and division of two integers. Languages: Java and XML IDE: Eclipse - ADT Username: skywalker Password:...

  • Electronic Lock Android App (All-In-One Lock)

    Electronic Lock Android App (All-In-One Lock)

    View: 21    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is one of android apps named Electronic Lock. As you can see, you can customized your android phone in any lock/unlock app that what you want. This is also one of the capstone projects that I have made for a particular school. This app Features:...

  • Menstrual Period Calendar App

    Menstrual Period Calendar App

    View: 49    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is one of the capstone/thesis projects that I have made for a particular school. This app is entitled Menstrual Period Calendar App that helps women to be aware of their ovulation, fertility, and pregnancy date. This app has the following...

  • Connect To PHP Server Using Android

    Connect To PHP Server Using Android

    View: 302    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Connect To PHP Server using Android. Android is an open source so that developer find it easy to develop and expand new features. It used in several gadget like smartphone, tablet, and even television. It also provide an...

  • Dynamic Table w/ Pagination

    Dynamic Table w/ Pagination

    View: 23    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This project is Dynamic Table w/ Pagination in android. A very simple and easy to understand project especially for beginners in android. Hope you'll like it. IDE: Android Studio Credits to Simon Brown the author of Pageable Class.

  • Android - Simple Alarm Application

    Android - Simple Alarm Application

    View: 70    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Alarm Application using Android. This simple application can be used to make a schedule of your meeting, birthday, etc, just to make on time with it. The android is an open source operating system it's free and user...

  • Android Car and Taxi Booking App

    Android Car and Taxi Booking App

    View: 28    Download: 2   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    The android car and taxi booking app is a source code specially created for students and beginners android developers who will like to learn or build upon this source code to create their own android project Android Car and Taxi Booking App has the...

  • Android - Simple Image Capture

    Android - Simple Image Capture

    View: 392    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Image Capture using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to...

 
File suggestion for you
File top downloads
Codetitle.net - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.net Develope by Vinagon .Ltd