我一直在尝试开发一个 Android 应用程序,它可以让用户拍照,然后通过 HTTP 发送图像。我正在使用本机相机。
用户拍照并点击保存按钮后,我在应用程序发送信息并等待响应时出现黑屏。我宁愿显示一个进度对话框,但无论我尝试什么,黑屏都会停留在那里,并且只有在获得响应并点击后退按钮后才能看到进度对话框。我尝试使用 setContentView() 无济于事。线程用于 HTTP 请求。
这是相机开始和结束的代码:
protected void startCameraActivity()
{
File file = new File( _path );
Uri out = Uri.fromFile( file );
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, out );
startActivityForResult( intent, 0 );
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( resultCode )
{
case 0:
break;
case -1:
m_ProgressDialog = ProgressDialog.show(MainActivity.this, "Please wait...", "Uploading data ...", true, true);
onPhoto();
break;
}
}
protected void onPhoto()
{
taken = true;
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = null;
try {
pis = new PipedInputStream(pos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Sender sender = new Sender(pos);
Receiver receiver = new Receiver(pis);
sender.start();
receiver.start();
try {
sender.join();
receiver.join();
try {
field.setText(receiver.getIn().readUTF());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pis.close();
pos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}