Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Created May 3, 2020 20:18
Show Gist options
  • Save TarasOsiris/b7ffe4af5f1e3a775df495821ae0d814 to your computer and use it in GitHub Desktop.
Save TarasOsiris/b7ffe4af5f1e3a775df495821ae0d814 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class AlarmClock : MonoBehaviour
{
const string ACTION_SET_ALARM = "android.intent.action.SET_ALARM";
const string EXTRA_HOUR = "android.intent.extra.alarm.HOUR";
const string EXTRA_MINUTES = "android.intent.extra.alarm.MINUTES";
const string EXTRA_MESSAGE = "android.intent.extra.alarm.MESSAGE";
public void OnClick()
{
print("Hello!");
CreateAlarm("My alarm!", 8, 52);
}
public void CreateAlarm(string message, int hour, int minutes)
{
var intentAJO = new AndroidJavaObject("android.content.Intent", ACTION_SET_ALARM);
intentAJO
.Call<AndroidJavaObject>("putExtra", EXTRA_MESSAGE, message)
.Call<AndroidJavaObject>("putExtra", EXTRA_HOUR, hour)
.Call<AndroidJavaObject>("putExtra", EXTRA_MINUTES, minutes);
GetUnityActivity().Call("startActivity", intentAJO);
}
AndroidJavaObject GetUnityActivity()
{
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
return unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment