Service crash with "Bad notification for startForeground: java.lang.RuntimeException: invalid service notification:" in Android 6 with multi accounts

0

My app's foreground service crash when try to start then bind a foreground service.

The strange thing is it only happen if download and install using account other than the owner account. If first download from owner account, everything works perfectly. I use Nexus 7 Adnroid 6.0.1 for testing and the app is download from Google Play internal test.

Code snippet:

public void startAndBindBackendService{
    ....
    context.startService(buildBackendServiceIntent());
    context.bindService(buildBackendServiceIntent(), backendServiceConn , Service.BIND_AUTO_CREATE | Service.BIND_ABOVE_CLIENT);    
}

private Intent buildBackendServiceIntent(){
    Intent intent = new Intent(BACKEND_SERVICE_INTENT_ACTION);
    intent.setPackage(PKG_NAME);
    intent.putExtra("serverIp", "x.x.x.x");
    intent.putExtra("isAppInBackground", isAppInBackground);
    return intent;
}
public class BackendService extends Service {
 @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);        
    startForeground(FOREGROUND_SERVICE_NOTI_ID, new Notification.Builder(context)                
            .build());
    return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
   ....
    serviceStub = (BackendServiceInterface.Stub) buildServiceBinder(); // BackendServiceInterface is AIDL interface
    return serviceStub;
}
...
}

Manifest:

  <application
    android:name=".MainApp"
    android:allowBackup="false"
    android:icon="@mipmap/hippo_icon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    ....
    <service
        android:name=".service.***"
        android:process=":remote"
        android:stopWithTask="false"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="****"/>
        </intent-filter>
    </service>
    ....
</application>

Exception:

02-11 15:14:34.378 28390-28390/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.***.*****:remote, PID: 28390
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid service notification: Notification(pri=0 contentView=com.pc.*****/0x1090085 vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
android
asked on Stack Overflow Feb 11, 2019 by RedSIght • edited Feb 14, 2019 by RedSIght

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0