在android中不需要android.permission.BIND_JOB_服务权限

在android中不需要android.permission.BIND_JOB_服务权限,android,service,jobservice,jobintentservice,Android,Service,Jobservice,Jobintentservice,尽管这已经得到了回答。我已经试过了,但是运气不好。在我的例子中,我在同一个项目中使用JobService和JobIntentService来测试和学习东西。JobService工作正常,但在我尝试JobIntentService时,它在我的情况下不工作,我面临以下错误: IllegalArgumentException: Scheduled service ComponentInfo{com.abdul_waheed.serviceandbackgroundtask/com.abdul_wahe

尽管这已经得到了回答。我已经试过了,但是运气不好。在我的例子中,我在同一个项目中使用JobService和JobIntentService来测试和学习东西。JobService工作正常,但在我尝试JobIntentService时,它在我的情况下不工作,我面临以下错误:

IllegalArgumentException: Scheduled service ComponentInfo{com.abdul_waheed.serviceandbackgroundtask/com.abdul_waheed.serviceandbackgroundtask.ExampleIntentService} does not require android.permission.BIND_JOB_SERVICE permission
尽管在其他答案中建议,我需要在清单中添加权限,我已经给出了权限,但仍然无法使其运行。下面是清单代码

  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<!--If you don,t add this permission on PIE, foreground service exception will be thrown-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>


<application
    android:name=".App"
    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">
    <activity android:name=".JobIntentServiceActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".ExampleJobService"
        android:permission="android.permission.BIND_JOB_SERVICE"/>
    <service android:name=".ExampleService"/>
    <service android:name=".ExampleIntentService"/>

    <service android:name=".ExampleJobIntentService"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="false"/>

</application>

任何帮助都将不胜感激。

我刚刚注意到,您在
排队工作
中调用的是
ExampleIntentService.class
而不是
ExampleJobIntentService.class
,这可能是问题吗?

问题出在您的
ExampleIntentService
中,而不是
ExampleJobIntentService
。什么是问题?我的意思是,您得到的日志错误来自
exampleententservice
,但您正在显示
exampleentservice
的代码。你能出示正确的密码吗?是的,你是对的。这才是真正的问题。
public class ExampleJobIntentService extends JobIntentService {

private static final String TAG = ExampleIntentService.class.getSimpleName();
/*
* Below method is like onHandleIntent of IntentService Class. This method runs on background thread
* automatically. We do not need to write wake lock code. It handled it automatically
* */

static void enqueuWork(Context context, Intent work) {
    enqueueWork(context,ExampleIntentService.class, 123, work);
}
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate");

}

@Override
protected void onHandleWork(@NonNull Intent intent) {
    Log.d(TAG, "onHandleWork");

    String input = intent.getStringExtra("input_extra");

    for (int i = 0; i < 10; i++) {
        Log.d(TAG, input + " - " + i);
        if (isStopped())
            return;
        SystemClock.sleep(1000);
    }
}

/*
* this will called when the has been stopped this will be called when it is using JobSchedular.
* This method is called when device requires memory or simple when it has been running since too long as Job has time limits
* which is around 10 minutes and after that they stop and defered
* */

@Override
public boolean onStopCurrentWork() {
    Log.d(TAG, "onStopCurrentWork");
    /*
    * default value is true==> that means when this methid is called should be resumed and yes it should in case of false not
    * to resume. If it started again it will start with same intent as it was passed in first attempt
    * */
    return super.onStopCurrentWork();
}

@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "onDestroy");
}
 public void enqueueWork(View view) {
    String input = etInput.getText().toString();
    Intent serviveIntent = new Intent(this, ExampleJobIntentService.class);
    serviveIntent.putExtra("input_extra", input);

    /*
    * If constraints needs to be set then it is not a suitable solution because it mimics as if it were IntentService class.
    * If constraints are required then JobSchedular is a better approach
    * */
    ExampleJobIntentService.enqueuWork(this, serviveIntent);


}