SecurityException: Unable to start service Intent

Keywords: Android SDK Java Mobile

If you encounter the following error:
java.lang.SecurityException: Unable to start service Intent { flg=0x20 cmp=com.ucar.app/cn.jpush.android.service.DaemonService }: Unable to launch app com.ucar.app/10101 for service Intent { cmp=com.ucar.app/cn.jpush.android.service.DaemonService }: user 0 is restricted
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1769)
at android.app.ContextImpl.startService(ContextImpl.java:1742)
at android.content.ContextWrapper.startService(ContextWrapper.java:527)
at cn.jpush.android.service.l.run(Unknown Source)
at java.lang.Thread.run(Thread.java:818)

The current version of the aurora push SDK does not support the startup service in the current mobile phone system. This is the problem that the old Aurora push SDK does not adapt to Android 8.0 mobile phones. At present, the new version of the aurora SDK does not have that problem, so the solution is to replace it with the latest Aurora SDK

Go to the official website to download the latest version of Aurora push SDK. Download address:
https://docs.jiguang.cn/jpush/resources/

Copy everything in the downloaded lib to the corresponding lib file of your project and rely on it,


Copy the file in res to the corresponding project res file (please check that the file in res of your project does not have the same name as it, otherwise it will be replaced, resulting in the loss of your project resource file)

Then configure the following code in Android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Package = "package name of your app"
android:versionCode="316"
android:versionName="3.1.6"

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />

<!-- Required -->
<permission
    android:name="Package name you applied.permission.JPUSH_MESSAGE"
    android:protectionLevel="signature" />

<!-- Required -->
<uses-permission android:name="Package name you applied.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!-- Optional. Required for location feature -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- For opening debug Version 6.0 Cascade window permissions on the system -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:name="Your Application Name">

    <!-- Required SDK Core functions-->
    <!-- Configurable android:process Parameter will PushService Put in another process -->
    <service
        android:name="cn.jpush.android.service.PushService"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="cn.jpush.android.intent.REGISTER" />
            <action android:name="cn.jpush.android.intent.REPORT" />
            <action android:name="cn.jpush.android.intent.PushService" />
            <action android:name="cn.jpush.android.intent.PUSH_TIME" />
        </intent-filter>
    </service>

<!-- since 3.0.9 Required SDK Core functions-->
    <provider
        android:authorities="Package name you applied.DataProvider"
        android:name="cn.jpush.android.service.DataProvider"
        android:exported="true"
    />

    <!-- since 1.8.0 option Optional. For different applications in the same device JPush The function that services pull each other up. -->
    <!-- If you do not enable this function, you can delete this component, or enabled Set up false ;App Not by others App Pull up, but you'll pull up the others App.  -->
     <service
         android:name="cn.jpush.android.service.DaemonService"
         android:enabled="true"
         android:exported="true">
         <intent-filter >
             <action android:name="cn.jpush.android.intent.DaemonService" />
             <category android:name="Package name you applied"/>
         </intent-filter>
     </service>

     <!-- since 3.1.0 Required SDK Core functions-->
      <provider
           android:authorities="Package name you applied.DownloadProvider"
           android:name="cn.jpush.android.service.DownloadProvider"
           android:exported="true"
       />

    <!-- Required SDK Core functions-->
    <receiver
        android:name="cn.jpush.android.service.PushReceiver"
        android:enabled="true" >
      <intent-filter android:priority="1000">
            <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
            <category android:name="Package name you applied"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
        <!-- Optional -->
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>

    <!-- Required SDK Core functions-->
    <activity
        android:name="cn.jpush.android.ui.PushActivity"
        android:configChanges="orientation|keyboardHidden"
        android:theme="@android:style/Theme.NoTitleBar"
        android:exported="false" >
        <intent-filter>
            <action android:name="cn.jpush.android.ui.PushActivity" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="Package name you applied" />
        </intent-filter>
    </activity>
    <!-- SDK Core functions-->
    <activity
        android:name="cn.jpush.android.ui.PopWinActivity"
        android:configChanges="orientation|keyboardHidden"
        android:exported="false"
        android:theme="@style/MyDialogStyle">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="Package name you applied" />
        </intent-filter>
    </activity>

    <!-- Required SDK Core functions-->
    <service
        android:name="cn.jpush.android.service.DownloadService"
        android:enabled="true"
        android:exported="false" >
    </service>

    <!-- Required SDK Core functions-->
    <receiver android:name="cn.jpush.android.service.AlarmReceiver" />

    <!-- Required since 3.0.7 -->
    <!-- New tag/alias The interface result return requires the developer to configure a customized broadcast -->
    <!-- The broadcast needs to inherit JPush Provided JPushMessageReceiver class, And add a new one as follows Intent-Filter -->
    <receiver
        android:name="custom Receiver"
        android:enabled="true" 
        android:exported="false" >
        <intent-filter>
            <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
            <category android:name="Package name you applied" />
        </intent-filter>
    </receiver>

    <!-- User defined. User defined broadcast receiver-->
     <receiver
         android:name="Your own definition Receiver"
         android:enabled="true"
         android:exported="false">
         <intent-filter>
             <!--Required User registration SDK Of intent-->
             <action android:name="cn.jpush.android.intent.REGISTRATION" />
             <!--Required User reception SDK News intent-->
             <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
             <!--Required User reception SDK Of notification bar information intent-->
             <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
             <!--Required User opens the intent-->
             <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
             <!-- Receive network change connection/To break off since 1.6.3 -->
             <action android:name="cn.jpush.android.intent.CONNECTION" />
             <category android:name="Package name you applied" />
         </intent-filter>
     </receiver>

    <!-- User defined. User defined Receiver Receive pulled callback-->
    <!-- custom Receiver Components, inheriting cn.jpush.android.service.WakedResultReceiver class,Make carbon copies onWake(int wakeType)or onWake(Context context, int wakeType)Method to monitor pulled -->
     <receiver android:name="xx.xx.xx.MyWakedResultReceiver">
        <intent-filter>
            <action android:name="cn.jpush.android.intent.WakedReceiver" />
            <category android:name="${applicationId}" />
        </intent-filter>
      </receiver>

    <!-- Required. For publish channel feature -->
    <!-- JPUSH_CHANNEL To facilitate developer statistics APK Distribution channels.-->
    <!-- for example: -->
    <!-- Send to Google Play Of APK Can be set to google-play; -->
    <!-- Sent to other markets APK Can be set to xxx-market.  -->
    <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
    <!-- Required. AppKey copied from Portal -->
    <meta-data android:name="JPUSH_APPKEY" android:value="Your application Appkey"/>
</application>

</manifest>

Finally, configure the initialization Aurora push JPushInterface.init(this) in the Application of your own project;
as
public class ExampleApplication extends Application {br/>@Override
public void onCreate() {
super.onCreate();
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
}
}

Posted by TimR on Tue, 19 Nov 2019 12:45:50 -0800