diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-12-02 12:11:10 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-12-02 12:11:10 +0100 |
commit | 604d04ae21ab0cbcca24cbbefabdaa443b064c37 (patch) | |
tree | 35f3a9986e53f8f87ca70ef4bcab833e317b94b7 /core/src/main/java | |
parent | c49357c4d00f025ef78a84c290512f240d88b586 (diff) | |
download | AntennaPod-604d04ae21ab0cbcca24cbbefabdaa443b064c37.zip |
Use explicit Intent for bindService call
bindService no longer accepts implicit Intents.
Possibly caused #559, #558, #553
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/com/aocate/media/MediaPlayer.java | 32 | ||||
-rw-r--r-- | core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java | 4 |
2 files changed, 35 insertions, 1 deletions
diff --git a/core/src/main/java/com/aocate/media/MediaPlayer.java b/core/src/main/java/com/aocate/media/MediaPlayer.java index c73c5219e..79e63d03d 100644 --- a/core/src/main/java/com/aocate/media/MediaPlayer.java +++ b/core/src/main/java/com/aocate/media/MediaPlayer.java @@ -35,6 +35,8 @@ import java.util.concurrent.locks.ReentrantLock; import de.danoeh.antennapod.core.BuildConfig; public class MediaPlayer { + public static final String TAG = "com.aocate.media.MediaPlayer"; + public interface OnBufferingUpdateListener { public abstract void onBufferingUpdate(MediaPlayer arg0, int percent); } @@ -110,6 +112,36 @@ public class MediaPlayer { } /** + * Returns an explicit Intent for a service that accepts the given Intent + * or null if no such service was found. + * + * @param context The application's environment. + * @param action The Intent action to check for availability. + * @return The explicit service Intent or null if no service was found. + */ + public static Intent getPrestoServiceIntent(Context context, String action) { + final PackageManager packageManager = context.getPackageManager(); + final Intent actionIntent = new Intent(action); + List<ResolveInfo> list = packageManager.queryIntentServices(actionIntent, + PackageManager.MATCH_DEFAULT_ONLY); + if (list.size() > 0) { + ResolveInfo first = list.get(0); + if (first.serviceInfo != null) { + Intent intent = new Intent(); + intent.setComponent(new ComponentName(first.serviceInfo.packageName, + first.serviceInfo.name)); + Log.i(TAG, "Returning intent:" + intent.toString()); + return intent; + } else { + Log.e(TAG, "Found service that accepts " + action + ", but serviceInfo was null"); + return null; + } + } else { + return null; + } + } + + /** * Indicates whether the Presto library is installed * * @param context The context to use to query the package manager. diff --git a/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java b/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java index 702a23b0f..0e27a8014 100644 --- a/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java +++ b/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java @@ -83,7 +83,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { super(owningMediaPlayer, context); Log.d(SBMP_TAG, "Instantiating ServiceBackedMediaPlayer 87"); this.playMediaServiceIntent = - new Intent(INTENT_NAME); + MediaPlayer.getPrestoServiceIntent(context, INTENT_NAME); this.mPlayMediaServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { IPlayMedia_0_8 tmpPlayMediaInterface = IPlayMedia_0_8.Stub.asInterface((IBinder) service); @@ -135,6 +135,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { Log.d(SBMP_TAG, "Connecting PlayMediaService 124"); if (!ConnectPlayMediaService()) { + Log.e(SBMP_TAG, "bindService failed"); ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0); } } @@ -149,6 +150,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { Log.d(SBMP_TAG, "Binding service"); return mContext.bindService(playMediaServiceIntent, mPlayMediaServiceConnection, Context.BIND_AUTO_CREATE); } catch (Exception e) { + Log.e(SBMP_TAG, "Could not bind with service", e); return false; } } else { |