我需要在后台使用工作服务下载一些文件。当我尝试在android设备7.0版中部署应用程序时,发生错误,提示“解析程序包时出现问题”。这是我的代码
public class RegisterJobService:Activity
{
public static void SchelduleJob(Context context)
{
try
{
long REFRESH_INTERVAL = 90 * 1000;
JobInfo.Builder builder;
JobInfo jobInfo;
Java.Lang.Class javaClass = Java.Lang.Class.FromType(typeof(BackgroundAgentService));
ComponentName component = new ComponentName(context, javaClass);
builder = new JobInfo.Builder(0, component).SetPeriodic(REFRESH_INTERVAL);
jobInfo = builder.Build();
JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(JobSchedulerService);
jobScheduler.Schedule(builder.Build());
}
catch (System.Exception ex)
{
}
}
}
//后台作业服务代码
[Service(Name = "SampleTestApp.Helper.BackgroundAgent", Permission =
"android.permission.BIND_JOB_SERVICE")]
public class BackgroundAgentService : JobService
{
public override bool OnStartJob(JobParameters @params)
{
Log.Debug("BATest", "BackgroundAgentService-2/---------OnStartJob////clas");
return true;
}
public override bool OnStopJob(JobParameters @params)
{
//throw new NotImplementedException();
Log.Debug("BATest", "BackgroundAgentService/////++++++++++++OnStopJob/////2/////clas");
return true;
}
}
我发现删除以下代码时,没有解析器错误,但是'SchelduleJob'方法转到异常处,提示'Java.Lang.IllegalArgumentException:没有此类服务ComponentInfo'。
[Service(Name =“ SampleTestApp.Helper.BackgroundAgent”,Permission = “ android.permission.BIND_JOB_SERVICE”)]
我也试图在清单文件中添加权限,但该文件不起作用。
<application >
<service android:Name="SampleTestApp.Helper.BackgroundAgentService" android:enabled="true" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true" />
</application>
有人对此有想法吗?