I'm trying to set a timer on the phone (not in the app I created) using ACTION_SET_TIMER intent and I'm not sure why it's not working when I click the button it either restarts the app or crashes it. Thanks for the help!
<Button
android:id="@+id/timer_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:onClick="startTimer"
android:text="@string/timer_note"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/camera_button"
/>
public void startTimer(View view) {
String searchFor = ((EditText) findViewById(R.id.share_edittext)).getText().toString();
String strNew = searchFor.replaceFirst("You ordered a ", "");
int seconds = 10;
Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER)
.putExtra(AlarmClock.EXTRA_MESSAGE, strNew)
.putExtra(AlarmClock.EXTRA_LENGTH, seconds)
.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}