有没有人为印象笔记的android-job https://github.com/evernote/android-job做了绑定?
有趣的是,Xamarin文档在一个示例中提到了这一点:
我尝试遵循https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-an-aar/,但它没有生成JobManager类
发布于 2018-06-22 11:08:33
GitHub上用于android-job的Xamarin绑定
这是什么?
Xamarin Android-Job binding允许你使用Evernote's android-job library for Android,在后台高效而健壮地运行作业。该库检查客户端设备上的Android版本,以确定执行预定后台工作的最佳方法。它将使用最适合操作系统的方法,如JobScheduler、GcmNetworkManager、AlarmManager或WorkManager。
使用方法:
第1步:
下载Xamarin binding for Evernote's android-job library。
第2步:
在发布模式下构建绑定项目,然后从bin/release文件夹中获取android-job.dll文件。将此dll添加到您自己的项目中并引用它。
第3步:
在您的Android Manifest中,在Application节点中添加以下内容,以使服务和接收器正常工作。
<service android:name="com.evernote.android.job.v21.PlatformJobService" android:exported="false" android:permission="android.permission.BIND_JOB_SERVICE"/>
<service android:name="com.evernote.android.job.v14.PlatformAlarmService" android:exported="false" android:permission="android.permission.BIND_JOB_SERVICE"/>
<service android:name="com.evernote.android.job.v14.PlatformAlarmServiceExact" android:exported="false"/>
<receiver android:name="com.evernote.android.job.v14.PlatformAlarmReceiver" android:exported="false">
<intent-filter>
<!-- Keep the filter for legacy intents -->
<action android:name="com.evernote.android.job.v14.RUN_JOB"/>
<action android:name="net.vrallev.android.job.v14.RUN_JOB"/>
</intent-filter>
</receiver>
<receiver android:name="com.evernote.android.job.JobBootReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<service android:name="com.evernote.android.job.gcm.PlatformGcmService" android:enabled="false" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE">
<intent-filter>
<action android:name="com.google.android.gms.gcm.ACTION_TASK_READY"/>
</intent-filter>
</service>
<service android:name="com.evernote.android.job.JobRescheduleService" android:exported="false" android:permission="android.permission.BIND_JOB_SERVICE"/>此外,请确保您具有以下权限:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>第4步:
确保您的项目中有以下引用(可以通过Nuget安装):
步骤5:
为要排定的作业创建类:
提示:有关配置不同类型作业的示例,如定期作业、一次性作业等,请参阅。
using Com.Evernote.Android.Job;
namespace MyNamespace
{
public class MyJob : Job
{
public const String TAG = "job_myjob_tag";
protected override Result OnRunJob(Params parameters)
{
// run your job here
return Result.Success;
}
public static void ScheduleJob()
{
new JobRequest.Builder(MyJob.TAG)
.SetRequiresDeviceIdle(false)
.SetRequiredNetworkType(JobRequest.NetworkType.Connected)
.SetPeriodic(900000, 300000)
.SetUpdateCurrent(true)
.Build()
.Schedule();
}
private void CancelJob(int jobId)
{
JobManager.Instance().Cancel(jobId);
}
}
}第6步:
为您的作业创建工厂方法:
using Com.Evernote.Android.Job;
namespace MyNamespace
{
public class MyJobCreator : Java.Lang.Object, IJobCreator
{
public Job Create(string tag)
{
switch (tag)
{
case MyJob.TAG:
return new MyJob();
default:
return null;
}
}
}
}步骤7:
最好在GlobalApplication.OnCreate方法中初始化JobManager单例。如果你不能,有一个alternative。
JobManager.Create(this).AddJobCreator(new MyJobCreator());第8步:
计划您的作业!您可以从启动activity OnCreate方法或您喜欢的任何地方执行此操作。例如:
MyNamespace.MyJob.ScheduleJob();提示:
OnRunJob(...)方法中完成的工作应该是同步的,否则在所有工作完成之前不会返回Result。SetUpdateCurrent,或通过调用JobManager.Instance().GetAllJobRequestsForFlag(MyJob.TAG).检查作业是否已存在
贷方推荐人:
https://stackoverflow.com/questions/42567248
复制相似问题