Use explicit Intent for bindService call

bindService no longer accepts implicit Intents.

Possibly caused #559, #558, #553
This commit is contained in:
daniel oeh 2014-12-02 12:11:10 +01:00
parent c49357c4d0
commit 604d04ae21
2 changed files with 35 additions and 1 deletions

View File

@ -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);
}
@ -109,6 +111,36 @@ public class MediaPlayer {
return list.size() > 0;
}
/**
* 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
*

View File

@ -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 {