Skip to content

Create Alarm / Set Alarm intent support #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<uses-permission android:name="android.alarm.permission.SET_ALARM" />
```

```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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ declare namespace SendIntentAndroid {
const requestIgnoreBatteryOptimizations: () => Promise<boolean>
const showIgnoreBatteryOptimizationsSettings: () => void
const openAppWithUri: (intentUri: string, extras?: { [index: string]: string }) => Promise<boolean>
const createAlarm: (hour: number, minutes: number, message?: string)=> void
const TEXT_PLAIN: unique symbol
const TEXT_HTML: unique symbol
}
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;