I'm writting an app Screenserver not using dayDream.
ScreenSaverActivity I override ontouch:
@Override public boolean onTouch(View v, MotionEvent event) {
Long time = new GregorianCalendar().getTimeInMillis()+ 10*1000;
Intent intentAlarm = new Intent(this, AlarmReciever.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
startService(new Intent(this, MyService.class));
this.onBackPressed(); // turn off app
return false; }
AlrmService.class
public class AlarmReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Intent i = new Intent();
i.setClassName("edu.com.screensaver", "edu.com.screensaver.ScreenSaverActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i); // turn on again
}
}
I want update time for alrmActivity so I added MyService.class handle touch event
public class MyService extends Service implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(this, "MyService click", Toast.LENGTH_LONG).show();
if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP)
Log.i(TAG, "Action :" + event.getAction() + "\t X :" + event.getRawX() + "\t Y :"+ event.getRawY());
return true;
}
}
"MyService click" message is never call. When i touch in main activity after 10 seconds the app open again.
Any solution is welcome.
Thanks
Try this code:
boolean isTouchSupported = getPackageManager().hasSystemFeature("android.hardware.touchscreen");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.