[Android] Set widgets broadcast explicits.
Geoffrey Métais
git at videolan.org
Wed Dec 20 17:10:12 CET 2017
vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 19 18:18:57 2017 +0100| [b3353dee8bb9d53be93d5b17b21a11e171e83ec8] | committer: Geoffrey Métais
Set widgets broadcast explicits.
Oreo refuses the subscription of implicit broadcasts via the app
manifest
(cherry picked from commit 3aaec78a4dd4197b6e3de008dcff2d131214235e)
> https://code.videolan.org/videolan/vlc-android/commit/b3353dee8bb9d53be93d5b17b21a11e171e83ec8
---
.../src/org/videolan/vlc/PlaybackService.java | 24 ++++++++++++++--------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index e79063192..531cea69e 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -207,7 +207,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
public static final int REPEAT_NONE = 0;
public static final int REPEAT_ONE = 1;
public static final int REPEAT_ALL = 2;
- private boolean mHasWidget;
+ private int mWidget = 0;
private boolean mShuffling = false;
private int mRepeating = REPEAT_NONE;
private Random mRandom = null; // Used in shuffling process
@@ -319,9 +319,10 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
}
private void updateHasWidget() {
- AppWidgetManager manager = AppWidgetManager.getInstance(this);
- mHasWidget = manager.getAppWidgetIds(new ComponentName(this, VLCAppWidgetProviderWhite.class)).length != 0
- || manager.getAppWidgetIds(new ComponentName(this, VLCAppWidgetProviderBlack.class)).length != 0;
+ final AppWidgetManager manager = AppWidgetManager.getInstance(this);
+ if (manager.getAppWidgetIds(new ComponentName(this, VLCAppWidgetProviderWhite.class)).length != 0) mWidget = 1;
+ else if (manager.getAppWidgetIds(new ComponentName(this, VLCAppWidgetProviderBlack.class)).length != 0) mWidget = 2;
+ else mWidget = 0;
}
@Override
@@ -1574,12 +1575,17 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
}
private void updateWidget() {
- if (mHasWidget && !isVideoPlaying()) {
+ if (mWidget != 0 && !isVideoPlaying()) {
updateWidgetState();
updateWidgetCover();
}
}
+ private void sendWidgetBroadcast(Intent intent) {
+ intent.setComponent(new ComponentName(PlaybackService.this, mWidget == 1 ? VLCAppWidgetProviderWhite.class : VLCAppWidgetProviderBlack.class));
+ sendBroadcast(intent);
+ }
+
private void updateWidgetState() {
final MediaWrapper media = getCurrentMedia();
final Intent widgetIntent = new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE);
@@ -1593,7 +1599,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
widgetIntent.putExtra("artist", "");
}
widgetIntent.putExtra("isplaying", isPlaying());
- sendBroadcast(widgetIntent);
+ sendWidgetBroadcast(widgetIntent);
}
private String mCurrentWidgetCover = null;
@@ -1601,20 +1607,20 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
String newWidgetCover = hasCurrentMedia() ? getCurrentMedia().getArtworkMrl() : null;
if (!TextUtils.equals(mCurrentWidgetCover, newWidgetCover)) {
mCurrentWidgetCover = newWidgetCover;
- sendBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_COVER)
+ sendWidgetBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_COVER)
.putExtra("artworkMrl", newWidgetCover));
}
}
private void updateWidgetPosition(final float pos) {
- if (!mHasWidget || isVideoPlaying())
+ if (mWidget == 0 || isVideoPlaying())
return;
// no more than one widget mUpdateMeta for each 1/50 of the song
long timestamp = System.currentTimeMillis();
if (!hasCurrentMedia() || timestamp - mWidgetPositionTimestamp < getCurrentMedia().getLength() / 50)
return;
mWidgetPositionTimestamp = timestamp;
- sendBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_POSITION)
+ sendWidgetBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_POSITION)
.putExtra("position", pos));
}
More information about the Android
mailing list