Fix crash on boot and widgets not responding
This commit is contained in:
parent
ba444dfb46
commit
241380e80f
2 changed files with 11 additions and 3 deletions
|
|
@ -5,12 +5,13 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.service.MusicService;
|
import com.kabouzeid.gramophone.service.MusicService;
|
||||||
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class BootReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(final Context context, Intent intent) {
|
||||||
final AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
|
final AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
|
||||||
// Start music service if there are any existing widgets
|
// Start music service if there are any existing widgets
|
||||||
|
|
@ -19,7 +20,9 @@ public class BootReceiver extends BroadcastReceiver {
|
||||||
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetSmall.class)).length > 0 ||
|
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetSmall.class)).length > 0 ||
|
||||||
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetCard.class)).length > 0) {
|
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetCard.class)).length > 0) {
|
||||||
final Intent serviceIntent = new Intent(context, MusicService.class);
|
final Intent serviceIntent = new Intent(context, MusicService.class);
|
||||||
context.startService(serviceIntent);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { // not allowed on Oreo
|
||||||
|
context.startService(serviceIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import android.graphics.Path;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
|
@ -74,7 +75,11 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
||||||
Intent intent = new Intent(action);
|
Intent intent = new Intent(action);
|
||||||
intent.setComponent(serviceName);
|
intent.setComponent(serviceName);
|
||||||
return PendingIntent.getService(context, 0, intent, 0);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
return PendingIntent.getForegroundService(context, 0, intent, 0);
|
||||||
|
} else {
|
||||||
|
return PendingIntent.getService(context, 0, intent, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Bitmap createBitmap(Drawable drawable, float sizeMultiplier) {
|
protected static Bitmap createBitmap(Drawable drawable, float sizeMultiplier) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue