[align=left]我想做个闹钟提醒,在EssayActivity中设置时间,启动服务,获取系统时间,两者相等闹钟响。但是service中一直有错(异常)Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1140 android.content.ContextWrapper.sendBroadcast:345 com.android.settings.batterywarning.ReadCodeTask.sendWarningMessage:59 com.android.settings.batterywarning.ReadCodeTask.run:41 java.util.Timer$TimerImpl.run:284
断电调试一直从timer.scheduleAtFixedRate(new TimerTask() {跳到最后 }, 0,1000*60);
线面附上源代码,球大神指教!
package com.example.notepad;
import java.util.Timer;
import java.util.TimerTask;
import android.app.AlertDialog;
import android.app.Service;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.IBinder;
import android.os.Vibrator;
import android.text.format.Time;
import android.util.Log;
public class EssayService extends Service{
private static final String TAG="EssayService";
private SensorManager mgr;//传感器
private Vibrator vibrator;//震动马达
private SoundPool soundPool;//声音播放对象
private int streamID =0;//音效流
private Timer timer;
public static double year=0;
public static double month=0;
public static double day=0;
public static double hour=0;
public static double minute=0;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
//初始化音效
soundPool=new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
soundPool.load(this, R.raw.kid, 1);
//获得传感器
mgr=(SensorManager)getSystemService(SENSOR_SERVICE);
vibrator=(Vibrator)getSystemService(VIBRATOR_SERVICE);
year=EssayActivity.year;
month=EssayActivity.month;
day=EssayActivity.day;
hour=EssayActivity.hour;
minute=EssayActivity.minute;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
//Service结束时停止音效播放
if(streamID!=0){
soundPool.stop(streamID);
}
if(timer!=null){
timer.cancel();
}
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub