Friday, April 18, 2014

Great God seeking advice! Urgent!


[Align = left] I want to be a reminder alarm clock, set the time to start the service in EssayActivity, gets the system time, the two are equal the alarm. But the service has been wrong (abnormal) 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
Debugging has been off from timer.scheduleAtFixedRate (new TimerTask () {Skip to end}, 0,1000 * 60);
Attach the source code line and plane, the ball great God enlighten!
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 ;/ / sensor
private Vibrator vibrator ;/ / vibration motor
private SoundPool soundPool ;/ / audio player object
private int streamID = 0 ;/ / audio stream
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 ();
/ / Initialize audio
soundPool = new SoundPool (10, AudioManager.STREAM_SYSTEM, 5);
soundPool.load (this, R.raw.kid, 1);
/ / Get the sensor
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
Audio playback
/ / Service stop at the end ofif (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
Log.i (TAG, "Service started");
/ / Start the service
if (timer! = null) {
timer.cancel ();
}
timer = new Timer ();
timer.scheduleAtFixedRate (new TimerTask () {

@ Override
public void run () {
/ / TODO Auto-generated method stub

/ / Get the current system at the same time
Time t = new Time ();
t.setToNow ();
double tYear = t.year;
double tMonth = t.month;
double tDay = t.monthDay;
double tHour = t.hour;
double tMinute = t.minute;
if (year == tYear && month == tMonth && day == tDay
&& Hour == tHour && minute == tMinute) {
/ / Vibration, play a sound
vibrator.vibrate (1000);
if (streamID == 0) {
streamID = soundPool.play (1, 1, 1, 0, -1, 1);
}
new AlertDialog.Builder (EssayService.this)
. SetTitle ("whether to cancel?")
. SetNegativeButton ("yes", new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
/ / TODO Auto-generated method stub
if (timer! = null) {
timer.cancel ();
timer.purge ();
}
}
})
. SetNegativeButton ("Cancel", new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
/ / TODO Auto-generated method stub

}
})
. Show ();
}
}
}, 0,1000 * 60);
return super.onStartCommand (intent, flags, startId);
}




@ Override
public IBinder onBind (Intent intent) {
/ / TODO Auto-generated method stub
return null;
}

}
Here is the code from EssayActivity to service
case R.id.btnClock:
LayoutInflater inflater = getLayoutInflater ();
final View layout = inflater.inflate (R.layout.timeset,
(ViewGroup) findViewById (R.id.dialog));
final EditText passText = new EditText (this);
passText.setInputType (InputType.TYPE_CLASS_TEXT);
new AlertDialog.Builder (EssayActivity.this)
. SetTitle ("Please enter the prompt date:")
. SetView (layout)
. SetPositiveButton ("OK", new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
LayoutInflater factory = LayoutInflater.from (log.this);
final View textEntryView = factory.inflate (R.layout.dialog, null);


EditText editYear = (EditText) layout.findViewById (R.id.editYear);
EditText editMonth = (EditText) layout.findViewById (R.id.editMonth);
EditText editDay = (EditText) layout.findViewById (R.id.editDay);
EditText editHour = (EditText) layout.findViewById (R.id.editHour);
EditText editMinite = (EditText) layout.findViewById (R.id.editMinite);
try {
year = Double.parseDouble (editYear.getText () toString ().);
month = Double.parseDouble (editMonth.getText () toString ().);
day = Double.parseDouble (editDay.getText () toString ().);
hour = Double.parseDouble (editHour.getText () toString ().);
minute = Double.parseDouble (editMinite.getText () toString ().);
} Catch (Exception e) {
e.printStackTrace ();
} [Align = left]
saveEssayPassword ();
Intent intent = new Intent (EssayActivity.this, EssayService.class);
startService (intent);

}
})
. SetNegativeButton ("Cancel", [/ align] new DialogInterface.OnClickListener () {
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Slightly Diao look!

No comments:

Post a Comment