Android onStartCommand无法启动

时间:2015-11-30 15:24:16

标签: android

我想在移动设备启动时调用一个意图,但由于某种原因,除了AutoStart中的日志之外,日志不会输出

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AutoStart extends BroadcastReceiver
{
    public void onReceive(Context arg0, Intent arg1)
    {
        Intent intent = new Intent(arg0,NotificationScheduler.class);
        arg0.startService(intent);
        Log.i("Autostart", "started");
    }
}

其日志未输出的警报处理程序

public class NotificationScheduler extends Service {

    public NotificationScheduler() {
    }



    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.i("ALARMMAGNAGER", "started");
        AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        Calendar calendar = Calendar.getInstance();

        Log.i("ALARMMAGNAGER", "started");
        calendar.set(Calendar.HOUR_OF_DAY, 17);
        calendar.set(Calendar.MINUTE, 9);

        Intent targetIntent = new Intent(this, NotificationService.class);
        PendingIntent pi = PendingIntent.getService(this, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), /*AlarmManager.INTERVAL_DAY*/20000, pi);

        return Service.START_STICKY;
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}

我做错了什么?

0 个答案:

没有答案