Skip to content

Instantly share code, notes, and snippets.

View januprasad's full-sized avatar
🎯
Focusing

Januprasad K januprasad

🎯
Focusing
View GitHub Profile
# Git Commit standards
## _For better understanding & reviews_
Here im suggesting a useful way for writing better commit messages. Set your commit message template to:
download this template and save as ~/.git_commit_msg.txt
https://gist.github.com/januprasad/76bbde852fd1f943eb486de2848a0772
then run this command in your terminal
git config --global commit.template ~/.git_commit_msg.txt
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="false" />
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
val notificationUtils = NotificationUtils(context)
val notification = notificationUtils.getNotificationBuilder().build()
notificationUtils.getManager().notify(150, notification)
}
}
class NotificationUtils(base: Context) : ContextWrapper(base) {
val MYCHANNEL_ID = "App Alert Notification ID"
val MYCHANNEL_NAME = "App Alert Notification"
private var manager: NotificationManager? = null
init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannels()
private fun startAlarm(calendar: Calendar) {
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = Intent(this, AlarmReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0)
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, pendingIntent)
}
override fun onTimeSet(timePicker: TimePicker?, hour: Int, minute: Int) {
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, hour)
calendar.set(Calendar.MINUTE, minute)
calendar.set(Calendar.SECOND, 0)
startAlarm(calendar)
}
<!-- Button ~ set time for alarm -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set Alarm"
android:onClick="showTimerPickerFragment"
android:background="@color/colorAccent"
android:layout_marginTop="16dp"
android:textColor="#ffffff" />
/**
* On Click Button call for Time Set
*/
fun showTimerPickerFragment(view: View) {
val timePickerFragment = TimePickerFragment()
timePickerFragment.show(supportFragmentManager, "time_picker")
}
/**
* On Click Button for Cancel the previously set alarm
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
class TimePickerFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
// Use the current time as the default values for the picker
val calendar: Calendar = Calendar.getInstance()
val hour = calendar.get(Calendar.HOUR)
val minute = calendar.get(Calendar.MINUTE)
/** Create a new instance of TimePickerDialog and return it