Android L (API 21) - Java.Lang.Illegalargumentexception: Service Intent Must Be Explicit

Android L Youtube API - IllegalArgumentException: Service Intent must be explicit

It is available a new version of the Youtube API (1.2.1) that fixes this issue. It can be downloaded from here.

If you need to use the old version for some reason keep reading:

There is a bug in the Youtube API v1.0.0 in Lollipop. More info here and here.

As a workaround you can use android:targetSdkVersion="19" in the manifest while maintaining API 21 as build target (You still will be able to make use of the Lollipop API in your project).

Service Intent must be explicit

In your activity do the following:

Intent i = new Intent(this,PlayMusicService.class);
i.putExtra("action","com.example.neotavraham.PLAY");
startService(i);

In your service do the following:

package com.example.neotavraham;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;

public class PlayMusicService extends Service {
public static final String ACTION_PLAY = "com.example.neotavraham.PLAY";
MediaPlayer mMediaPlayer = null;

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getStringExtra("action").equals(ACTION_PLAY)) {
mMediaPlayer = MediaPlayer.create(this, R.raw.yedid_nefesh);
mMediaPlayer = MediaPlayer.create(this, R.raw.idil);
mMediaPlayer.setLooping(true); // Set looping
mMediaPlayer.setVolume(100,100);
mMediaPlayer.start();
}
return flags;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onDestroy() {
mMediaPlayer.stop();
mMediaPlayer.release();
}
}

In your manifiest do the following:

<service
android:name="com.example.neotavraham.PlayMusicService"
/>

This is the perfect code for your app. Hope this will work finally....

Service Intent must be explicit: Intent

any intent you make to a service, activity etc. in your app should always follow this format

Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);

or

Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");

implicit intents (what you have in your code currently) are considered a security risk

Android 5.0 (L) Service Intent must be explicit in Google analytics

Migration from Google Analytics v2 to v3 solve the problem for me.

Android Lollipop - Service Intent must be explicit

Your onReceive() method does this:

public void onReceive(Context context, Intent intent) {
context.unregisterReceiver(intentReciever);
context.stopService(intent); // If I remove this, I get multiple returns, but if I leave it - it crashes :(
}

This calls stopService() using the Intent that the BroadcastReceiver is started with (the broadcast Intent). If you look at your code that creates the broadcast Intent, it looks like this:

Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ExampleClass.PRINT_ACTION);
broadcastIntent.putExtras(ReceivedBundle);

This Intent has only an ACTION and EXTRAS. It is an implicit Intent, not an explicit Intent.

NOTE: This "works" on other platforms because it isn't actually stopping your Service at all. The code that calls stopService() is just doing nothing because there is no Service that responds to the Intent.

On Android 5, the call to stopService() is throwing an exception due to the tightening of security regarding implicit Intent for Services.

Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview

I had the same problem and explicitly setting the package solved it. Similar to Aleksey's answer, but simpler:

Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
// This is the key line that fixed everything for me
intent.setPackage("com.android.vending");

getContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);


Related Topics



Leave a reply



Submit