8

定期的なworkmanagerスクリプトを作成しようとしていますが、アプリを開いたときに実行され、1回だけ実行されます(定期的ではありません)!

ここに私の主な活動があります:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_work);

    Intent intent = new Intent();
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0);
    NotifyWorker.pendingIntent = pendingIntent;
    NotifyWorker.context = this;

    PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(NotifyWorker.class, 1, TimeUnit.MINUTES).build();
    WorkManager.getInstance().enqueue(periodicWorkRequest);
}

}

これは私のdoworkメソッドです:

public Result doWork() {
    Log.i("wd","wd");

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,"ctx")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Title")
            .setContentText("Desc")
            .setContentIntent(pendingIntent);

    android.app.NotificationManager notificationManager =
            (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 , notificationBuilder.build());

    return Result.SUCCESS;
}

なぜ1分ごとに実行しないのですか? 私は何が恋しいですか?

4

2 に答える 2