Nice n Simple! Great!
Very nice! Simple solution that I sought for
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.razormist.simplealarmapplication.MainActivity"> <TextView android:id="@+id/tv_display" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Alarm not set" android:textSize="20sp" android:layout_marginTop="20dp" android:layout_centerHorizontal="true"/> <TimePicker android:layout_below="@+id/tv_display" android:id="@+id/tp_time" android:layout_height="wrap_content" android:layout_width="match_parent" /> android:id="@+id/btn_set" android:layout_below="@+id/tp_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Set Alarm"/> android:id="@+id/btn_reset" android:layout_below="@+id/btn_set" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Reset Alarm"/> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.razormist.simplealarmapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:configChanges="orientation" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".AlarmAdapter" android:enabled="true" android:exported="true" /> </application> </manifest>
package com.razormist.simplealarmapplication; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.media.MediaPlayer; import android.provider.Settings; /** * Created by Arvin on 5/5/2018. */ public class AlarmAdapter extends BroadcastReceiver { @Override mediaPlayer.start(); } }
TimePicker tp_time; TextView tv_display; Button btn_set, btn_reset;
tv_display = (TextView)findViewById(R.id.tv_display); tp_time = (TimePicker)findViewById(R.id.tp_time); @Override if(Build.VERSION.SDK_INT >= 23) { calendar.set( tp_time.getHour(), tp_time.getMinute(), 0 ); }else{ calendar.set( tp_time.getCurrentHour(), tp_time.getCurrentMinute(), 0 ); } setAlarm(calendar.getTimeInMillis(), calendar); } Intent intent = new Intent(MainActivity.this, AlarmAdapter.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); alarmManager.setRepeating(AlarmManager.RTC, timeInMillis, AlarmManager.INTERVAL_DAY, pendingIntent); Toast.makeText(MainActivity.this, "Alarm Set", Toast.LENGTH_SHORT).show(); day = "AM"; day = "PM"; } timeText += hour +": " + minute + " " + day; tv_display.setText(timeText); } }); @Override Intent intent = new Intent(MainActivity.this, AlarmAdapter.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); alarmManager.cancel(pendingIntent); tv_display.setText("Alarm not set"); } });
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.