From c3e7536423a3f21488e85aae54d87c66db64d558 Mon Sep 17 00:00:00 2001 From: alperengozum Date: Fri, 7 Oct 2022 21:16:05 +0300 Subject: [PATCH] Create Alarm / Set Alarm intent support added. && README.md changed. --- README.md | 12 ++++++++++++ .../burnweb/rnsendintent/RNSendIntentModule.java | 15 +++++++++++++++ index.d.ts | 1 + index.js | 3 +++ 4 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 403aa755..af9ee73e 100644 --- a/README.md +++ b/README.md @@ -438,6 +438,18 @@ SendIntentAndroid.getPhoneNumber().then(phoneNumber => { }); ``` +## Example / Create alarm + +Please add this line to your AndroidManifest.xml file before using next example: + +```xml + +``` + +```javascript +SendIntentAndroid.createAlarm(24, 60 ,"Your alarm message"); +``` + ## Example / Request 'ignore battery optimizations' Please add this line to your AndroidManifest.xml file before using next example: diff --git a/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java b/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java index fcbbcadd..4dcd5543 100644 --- a/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java +++ b/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java @@ -15,6 +15,7 @@ import android.provider.CalendarContract.Calendars; import android.provider.CalendarContract.Events; import android.provider.CalendarContract; +import android.provider.AlarmClock; import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.Log; @@ -853,6 +854,20 @@ public void openAppWithUri(String intentUri, ReadableMap extras, final Promise p } } + @ReactMethod + public void createAlarm( int hour, int minutes, String message) { + Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM) + .putExtra(AlarmClock.EXTRA_MESSAGE, message) + .putExtra(AlarmClock.EXTRA_HOUR, hour) + .putExtra(AlarmClock.EXTRA_MINUTES, minutes); + + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + if (intent.resolveActivity(this.reactContext.getPackageManager()) != null) { + this.reactContext.startActivity(intent); + } + } + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { @Override public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { diff --git a/index.d.ts b/index.d.ts index 21b65e59..889b1d49 100644 --- a/index.d.ts +++ b/index.d.ts @@ -73,6 +73,7 @@ declare namespace SendIntentAndroid { const requestIgnoreBatteryOptimizations: () => Promise const showIgnoreBatteryOptimizationsSettings: () => void const openAppWithUri: (intentUri: string, extras?: { [index: string]: string }) => Promise + const createAlarm: (hour: number, minutes: number, message?: string)=> void const TEXT_PLAIN: unique symbol const TEXT_HTML: unique symbol } diff --git a/index.js b/index.js index 4032064e..f418621e 100644 --- a/index.js +++ b/index.js @@ -126,6 +126,9 @@ var SendIntentAndroid = { openAppWithUri(intentUri, extras) { return RNSendIntentAndroid.openAppWithUri(intentUri, extras || {}); }, + createAlarm(hour, minutes, messages) { + return RNSendIntentAndroid.createAlarm(hour, minutes, messages || ""); + }, }; module.exports = SendIntentAndroid;