我已经尝试过在stackoverflow上给出的所有可能解决方案,但仍达不到我想要的。我想使用带有服务的Camera API拍照。当用户点亮屏幕时应拍照,但屏幕仍处于锁定状态。我看到了有关虚拟表面等的不同文章...但是它们都不起作用,当然,因为我是Camera API的新手,所以我肯定在代码中犯了错误。我的应用程序是这样进行的:我安排AlarmManager启动服务:
public int onStartCommand(Intent intent,int flags,int startId) {
Log.i("service","start");
Calendar finServ=Calendar.getInstance();
String all=intent.getStringExtra("all");
nomevt=all.split(Pattern.quote("**"))[3];
Scanner sc;
String str="";
try {
sc = new Scanner(new File(getFilesDir(),"Event.evt"));
while(sc.hasNext()) {
str=sc.next();
if(all.equals(str)) break;
}
sc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(!all.equals(str)) stopSelf();
else {
finServ.setTimeInMillis(toMillis(str.split(Pattern.quote("**"))[1]));
Calendar now=Calendar.getInstance();
now.setTime(new Date());
while(finServ.after(now)) {
PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
if(pm.isScreenOn()) {
//AsyncCapture ac=new AsyncCapture(this);
//ac.execute("nomevt");
photo();
Log.i("screen","on");
while(pm.isScreenOn()) {
pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
}
}
now.setTime(new Date());
}
stopSelf();
}
return super.onStartCommand(intent, flags, startId);
}`
<br>The service will …Run Code Online (Sandbox Code Playgroud)