2013-02-08 10:09:55 +01:00
|
|
|
/*
|
|
|
|
This file is part of Subsonic.
|
|
|
|
|
|
|
|
Subsonic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Subsonic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2010 (C) Sindre Mehus
|
|
|
|
*/
|
2015-07-26 18:15:07 +02:00
|
|
|
package org.moire.ultrasonic.receiver;
|
2013-02-08 10:09:55 +01:00
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2020-06-17 15:08:30 +02:00
|
|
|
import android.os.Build;
|
2013-06-07 04:27:45 +02:00
|
|
|
import android.os.Bundle;
|
2013-12-30 09:33:39 +01:00
|
|
|
import android.os.Parcelable;
|
2013-02-08 10:09:55 +01:00
|
|
|
import android.util.Log;
|
2013-12-04 07:36:02 +01:00
|
|
|
|
2015-07-26 18:15:07 +02:00
|
|
|
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
|
|
|
import org.moire.ultrasonic.util.Util;
|
2013-02-08 10:09:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Sindre Mehus
|
|
|
|
*/
|
2013-12-04 07:36:02 +01:00
|
|
|
public class MediaButtonIntentReceiver extends BroadcastReceiver
|
|
|
|
{
|
2013-02-08 10:09:55 +01:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
|
2013-02-08 10:09:55 +01:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent)
|
|
|
|
{
|
|
|
|
if (Util.getMediaButtonsPreference(context))
|
|
|
|
{
|
|
|
|
String intentAction = intent.getAction();
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) return;
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
Bundle extras = intent.getExtras();
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
if (extras == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-30 09:33:39 +01:00
|
|
|
Parcelable event = (Parcelable) extras.get(Intent.EXTRA_KEY_EVENT);
|
2013-12-04 07:36:02 +01:00
|
|
|
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
Intent serviceIntent = new Intent(context, DownloadServiceImpl.class);
|
|
|
|
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
2020-06-17 15:08:30 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
context.startForegroundService(serviceIntent);
|
|
|
|
} else {
|
|
|
|
context.startService(serviceIntent);
|
|
|
|
}
|
2013-06-07 04:27:45 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (isOrderedBroadcast())
|
|
|
|
{
|
|
|
|
abortBroadcast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception x)
|
|
|
|
{
|
|
|
|
// Ignored.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-08 10:09:55 +01:00
|
|
|
}
|