How to fix “Package not in whitelist” when binding a Service?

17
February 12, 2019, at 02:50 AM

I have created two different Android applications. One contains a Service and the other one the Activity which binds the Service. This works well on all devices expected one. On the problematic device runs Android 6.0.1. On all other tested devices running Android 6 there are no problems. Same for devices with newer and older versions.

With packageManager.getPackageInfo("com.example.myexampleservice", 0) I checked that the service APK is installed.

My Activity class, which binds the Service (MainActivity.java, 1. project):

package com.example.myexampleactivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    final static int MSG_SAY_HELLO = 1;
    Messenger mService = null;
    boolean mBound;
    TextView textView;
    Button button;
    private ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            mService = new Messenger(service);
            mBound = true;
            button.setText("Send Message");
            textView.setText("Everything is fine. You can press the button to send a message.");
        }
        @Override
        public void onServiceDisconnected(ComponentName className) {
            mService = null;
            mBound = false;
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        textView = findViewById(R.id.text_view);
        button = findViewById(R.id.button);
        textView.setText("Press the button to bind the service.");
        button.setText("Bind service");
    }
    @Override
    protected void onStop() {
        super.onStop();
        if (mBound) {
            unbindService(mConnection);
            mBound = false;
            button.setText("Bind service");
        }
    }
    public void onClickButton(View v) {
        if (!mBound) {
            Intent intent = new Intent("com.example.myexampleservice.SERVICE");
            intent.setPackage("com.example.myexampleservice");
            if (getApplicationContext().bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) {
                textView.setText("Everything is fine.");
            } else {
                // This happens only on one device. Why???
                textView.setText("bindService(...) returns false. The following message is probably shown in the logcat:\n\n" +
                        "I BackgroundManagerService package not in whitelist com.example.myexampleservice\n" +
                        "I BackgroundManagerService not whitelist service Intent { act=com.example.myexampleservice.SERVICE pkg=com.example.myexampleservice }\n" +
                        "I BackgroundManagerService skipService Intent { act=com.example.myexampleservice.SERVICE pkg=com.example.myexampleservice } because of activity not started!");
            }
        } else {
            Message msg = Message.obtain(null, MSG_SAY_HELLO, 0, 0);
            try {
                mService.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }
}

My Service (MyExampleService.java, 2. project):

package com.example.myexampleservice;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.widget.Toast;
public class MyExampleService extends Service {
    static final int MSG_SAY_HELLO = 1;
    static class IncomingHandler extends Handler {
        private Context applicationContext;
        IncomingHandler(Context context) {
            applicationContext = context.getApplicationContext();
        }
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_SAY_HELLO:
                    Toast.makeText(applicationContext, "hello!", Toast.LENGTH_SHORT).show();
                    break;
                default:
                    super.handleMessage(msg);
            }
        }
    }
    Messenger mMessenger;
    @Override
    public IBinder onBind(Intent intent) {
        Toast.makeText(getApplicationContext(), "binding", Toast.LENGTH_SHORT).show();
        mMessenger = new Messenger(new IncomingHandler(this));
        return mMessenger.getBinder();
    }
}

And the AndroidManifest of the Service application (AndroidManifest, 2. project):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myexampleservice">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <service android:name=".MyExampleService">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="com.example.myexampleservice.SERVICE" />
            </intent-filter>
        </service>
    </application>
</manifest>

Only on the one device that doesn't work the method bindService(...) returns false. For this device, the Logcat shows the followoing:

I BackgroundManagerService package not in whitelist com.example.myexampleservice
I BackgroundManagerService not whitelist service Intent { act=com.example.myexampleservice.SERVICE pkg=com.example.myexampleservice }
I BackgroundManagerService skipService Intent { act=com.example.myexampleservice.SERVICE pkg=com.example.myexampleservice } because of activity not started!

I am helpless, because the application on all other devices runs without problems. The Google search does not return any results for these log messages. Has anyone seen these log messages before and knows what to do here? Does anyone have any idea how to fix this problem?

READ ALSO
React Native expo push notification with firebase not working?

React Native expo push notification with firebase not working?

I am using expo with firebase as a database and I want push notification I have tried the following thing but did not get successful to push notification for both Android and IOS

30
Hello please I&#39;m trying to create an android chatbot for autoresponse to users input

Hello please I'm trying to create an android chatbot for autoresponse to users input

![It is pretty much static right nowas I could only achieve click an display instead of type an autoresponse] It is pretty much static right now

19
How to randomize a RadioButton?

How to randomize a RadioButton?

I'm trying to make a multiple choice quizI have a problem when I want to get a multiple choice button randomly

44