我一直在試圖開發一個Android應用程序,它可以讓用戶拍照並通過HTTP發送圖像。我正在使用本機相機。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();
}
}
你或許應該做你的相機處理的'AsyncTask'。放在主線程意味着你的應用程序不會移動,直到該代碼行完成。 – 2012-08-02 18:56:21