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
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 : Has Extras
You can set the package id of your intent:
intent.SetPackage(PackageName);
Or use the current context and the Java class (or C# type):
var intent = new Intent(Application.Context, typeof(MediaService));
Android 5.0 (L) Service Intent must be explicit in Google analytics
Migration from Google Analytics v2 to v3 solve the problem for me.
Why Service Intent Needs to be Explicit Intent
When you start a service with implicit intent unlike Activity, no user interface
is involved. When multiple Services can handle an Intent,
Android selects one at random; the user is not prompted to
select a Service.
In case the malicious Service is bound to the calling application, then the attacker can return arbitrary malicious data
or simply return a successful result without taking the requested action. The
malicious Service can steal data and lie about completing
requested actions.
OpenCV Service Intent must be explicit, Android 5.0 Lollipop
I think changing the android:targetSdkVersion is not a solution for very long ;) So instead I added the package name to make the intent explicit:
public static boolean initOpenCV(String Version, final Context AppContext,
final LoaderCallbackInterface Callback) {
AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext,
Callback);
Intent intent = new Intent("org.opencv.engine.BIND");
intent.setPackage("org.opencv.engine");
if (AppContext.bindService(intent, helper.mServiceConnection,
Context.BIND_AUTO_CREATE)) {
return true;
} else {
AppContext.unbindService(helper.mServiceConnection);
InstallService(AppContext, Callback);
return false;
}
}
Maybe someone can tell an opencv comitter about this, to push a hotfix.
EDIT: From a comment below: For anyone else wondering the location of this function, it's in src/main/java/org/opencv/android/AsyncServiceHelper.java
Related Topics
Mediarecorder Issue on Android Lollipop
Designing Android Apps for Tablets
Error: Error Parsing Xml: Not Well-Formed (Invalid Token) ...
Invalid Heap Address and Fatal Signal 11
Android: Why Does Long Click Also Trigger a Normal Click
Flutter Insecure Http Is Not Allowed by Platform
Android 4.4.2 - Java.Lang.Runtimeexception: Performing Stop of Activity That Is Not Resumed
Sqlite Insert into Table Select * From
Android Httpsurlconnection Eofexception
How to Check Database on Not Rooted Android Device
Inform Activity from a Broadcastreceiver Only If It Is in The Foreground
How to Hide The Soft-Key Bar on Android Phone
How to Change System Navigation Bar Color
Replace Fragment with Another Fragment Inside Viewpager
Android Studio Could Not Find Any Version That Matches Com.Android.Support:Appcompat-V7:+
Change Progressbar Color Through Code Only in Android