0

i write a plugin for Unity, but i get this error when start a JobService, here the codes:

Baslangic.java

package com.alptugrul.background;

import android.app.Activity;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.widget.Toast;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;


public class Baslangic extends UnityPlayerActivity{

    public static Context contextAna;
    public static Activity activity;
    private static final int jobId = 1;
    private static JobScheduler jobScheduler;
    private static JobInfo jobInfo;


    public static void setContext () {
        contextAna = UnityPlayer.currentActivity.getApplicationContext();
        activity = UnityPlayer.currentActivity;
        ComponentName componentName = new ComponentName(contextAna,MJobScheduler.class);
        JobInfo.Builder builder = new JobInfo.Builder(jobId,componentName);
        builder.setPeriodic(5000);
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        builder.setPersisted(true);

        jobInfo = builder.build();
        jobScheduler = (JobScheduler) contextAna.getSystemService(JOB_SCHEDULER_SERVICE);

    }
    public static void mesajVer (String mesaj) {
        Toast.makeText(contextAna,mesaj,Toast.LENGTH_LONG).show();
    }

    public static void baslat() {
        jobScheduler.schedule(jobInfo);
        Toast.makeText(contextAna,"Görev Planlandı",Toast.LENGTH_SHORT).show();
    }

}

MJobScheduler.java:

package com.alptugrul.background;

import android.app.Activity;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;
import android.widget.Toast;

import com.unity3d.player.UnityPlayer;

/**
 * Created by Alpaslan on 15.3.2018.
 */

public class MJobScheduler extends JobService {
    private MJobExecuter mJobExecuter;
    public static Context contextAna;
    public static Activity activity;

    public static void setContext () {
        contextAna = UnityPlayer.currentActivity.getApplicationContext();
        activity = UnityPlayer.currentActivity;

    }
    @Override
    public boolean onStartJob(final JobParameters jobParameters) {
        mJobExecuter = new MJobExecuter(){

            @Override
            protected void onPostExecute(String s) {
                Toast.makeText(contextAna,"Arkaplan yeni Mesaj",Toast.LENGTH_SHORT).show();
                jobFinished(jobParameters,false);

            }
        };
        mJobExecuter.execute();

        return true;
    }

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
        mJobExecuter.cancel(true);

        return false;
    }
}

And the MJobExecuter.java:

package com.alptugrul.background;

import android.os.AsyncTask;


public class MJobExecuter extends AsyncTask<Void,Void,String> {
    @Override
    protected String doInBackground(Void... voids) {
        return "Arkaplandan sa";
    }
}

And my code in Unity:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deneme : MonoBehaviour {
 private static string fullClassName = "com.alptugrul.background.Baslangic";
 AndroidJavaClass pluginClass;
 void Start () {
  pluginClass = new AndroidJavaClass(fullClassName);
  pluginClass.CallStatic ("setContext");
  pluginClass.CallStatic ("mesajVer","Projen Çalışmaya Başladı!");
  pluginClass.CallStatic ("baslat");
 }
}

and my Manifest File:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.alptugrul.background"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="25" />

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

    <application
  android:theme="@style/UnityThemeSelector"
  android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:debuggable="true">
        <service
            android:name="com.alptugrul.background.MJobScheduler"
            android:exported="true"
            android:permission="android.permission.BIND_JOB_SERVICE" />
    </application>

</manifest>

EDIT; I build my apk but this apk won't install. I drop my apk to AVD but after install there is no application which is mine.

alp
  • 51
  • 10
  • And my manifest file have this service and permissions like this: – alp Mar 15 '18 at 21:52
  • Where did you put the manifest file? By the way, there is no Javascript in your code. All all I see is Java and C# code.... – Programmer Mar 15 '18 at 22:00
  • Sorry for wrong tag, my Unity code is c#, and i put the AndroidManifest.xml in my unity project file: Assets\Plugins\Android\libs\AndroidManifest.xml – alp Mar 15 '18 at 22:08
  • Put the Manifest file inside Assets/Plugins/Android. – Programmer Mar 15 '18 at 22:09
  • and the classes.jar? – alp Mar 15 '18 at 22:11
  • ---- EDIT: i delete android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme" lines in manifest and build successfully – alp Mar 15 '18 at 22:13
  • There is something wrong with your Manifest. The #1 step from [this](https://stackoverflow.com/questions/43293173/use-custom-manifest-file-and-permission-in-unity/43293396#43293396) post shows how to obtain original compatible Manifest from Unity. Once you obtain it, add the `"android.permission.BIND_JOB_SERVICE"` permission to it then use it as your Manifest. The error should be gone – Programmer Mar 15 '18 at 22:18
  • Hey, yes my manifest is wrong as you say, im add new comment for my manifest file... – alp Mar 15 '18 at 22:30
  • Edit that into your question not as an answer. Is your problem solved now? – Programmer Mar 15 '18 at 22:49
  • no my problem not solved, my apk cant installing – alp Mar 15 '18 at 23:59
  • Please look the post @Programmer – alp Mar 16 '18 at 19:02
  • How can I help if your APK is not installing? Also, if you are making a plugin and testing it with an emulator, you are wasting your time. Get a cheap physical Android device and test your plugin there. A plugin test should be done on a physical device. I've said this in your other question before – Programmer Mar 16 '18 at 19:34
  • Sorry, i couldn't tell, before moving manifest and classes.jar file, my apk installed succesfuly but now i cant install. – alp Mar 16 '18 at 19:52
  • And i try in my physical android device, won't install too... when i put android manifest file in /libs folder, it can be installed – alp Mar 16 '18 at 20:42

0 Answers0