【发布时间】:2015-11-27 12:02:06
【问题描述】:
我正在尝试通过后台服务中的摄像头捕获图像,但是在执行此操作时,我的应用程序被挂起,有时它会给我“无法连接到摄像头服务”的错误,尽管我的图像每 20 秒后就会被存储一次我的应用程序 ui 要么被挂起,要么崩溃。
请查看我的服务类:-
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
captureImage();
}
private void captureImage() {
int count = 0;
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (IS_ACTIVITY_FINISHED) {
count++;
if (count == 20) {
// Start Activity here
Intent translucent = new Intent(getApplicationContext(),
HiddenCamera.class);
translucent.putExtra("FLASH", "off");
translucent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(translucent);
IS_ACTIVITY_FINISHED = false;
break;
}
}
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
这是我的 HiddenCamera 类:-
http://piratepad.net/ep/pad/view/ro.LgLDgdzewfJ/latest
我的清单文件:-
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<service android:name="com.example.services.CameraService" >
</service>
请提供有关此过程的任何有用信息。
谢谢
【问题讨论】:
标签: android service android-camera