-2

I want create in java alarm clock app and when alarm it's turned on I want connect to video (specific url) on you tube (video must be start automatically). How I can do it at all or it's impossible?

Thanks for the answers :)

Marta
  • 1
  • 2
  • Yes, it's possible - you can use an `AlarmManager` to set an alarm, and when it's triggered open `YouTube` with an `Intent` (assuming the app is installed on the user's phone) [see here](https://stackoverflow.com/questions/574195/android-youtube-app-play-video-intent) – PPartisan Oct 16 '19 at 19:58

1 Answers1

0

Give this a try - it's untested, but should launch a YouTube video using whatever browser is installed on a user's device.

public static void setYouTubeAlarm(String videoId, long alarmTime) {
    final Intent launchYoutube = new Intent(Intent.ACTION_VIEW, 
    Uri.parse("http://www.youtube.com/watch?v=" + videoId));
    final PendingIntent pi = PendingIntent.getActivity(context, 0, launchYouTube, 0);
    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setExact(AlarmManager.RTC_WAKEUP, time, pi);
}

PPartisan
  • 8,173
  • 4
  • 29
  • 48