안녕하세요, iam이 PHP 서버에 동영상을 업로드하는 안드로이드 응용 프로그램을 만들고 있습니다.
업로드를 수행하려면 HTTPURLConnection
을 사용하십시오. Iam은 알림 영역에 진행률 표시 줄을 표시하고 업데이트하는 데 큰 충격을 받았습니다. 이걸 그리고는 누군가가 알고있는 경우 hint.Please 내게 도움을받을 수 없다 할 거의 일주일에 검색
스피 :알림 영역에 진행률 표시 줄을 표시하는 방법은 무엇입니까?
내 코드 :
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead;
byte[] buffer;
String urlString = "http://xxxxx/My_path.php";
try {
long total = 0;
int count = 0;
// ------------------ CLIENT REQUEST
UUID uniqueKey = UUID.randomUUID();
fname = uniqueKey.toString();
Log.e("UNIQUE NAME", fname);
FileInputStream fileInputStream = new FileInputStream(
new File(selectedPath));
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
int length=selectedPath.length();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
+ fname + "" + lineEnd);
dos.writeBytes(lineEnd);
buffer = new byte[8192];
bytesRead = 0;
while ((bytesRead = fileInputStream.read(buffer)) > 0) {
dos.write(buffer, 0, bytesRead);
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
Log.e("Debug", "File is written");
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
Log.e("Debug", "error: " + ex.getMessage(), ex);
} catch (IOException ioe) {
Log.e("Debug", "error: " + ioe.getMessage(), ioe);
}
// ------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream(conn.getInputStream());
String str;
while ((str = inStream.readLine()) != null) {
Log.e("Debug", "Server Response " + str);
}
inStream.close();
} catch (IOException ioex) {
Log.e("Debug", "error: " + ioex.getMessage(), ioex);
}
저는이 문제를 해결하기위한 솔루션을 찾고있었습니다. 정확히 동일한 작업 (havent는 알림 영역 진행 표시 줄을 시도했습니다)을 생각하고있었습니다. 사용자가 화면 방향을 변경하거나 앱을 종료 할 때 스레드가 멈추는 것을 걱정하는 유일한 것. 그러나 ... 여기 문제가 아니며, 다른 누군가가 내가 생각하고있는 해결책을 사용하는 것을보고 싶습니다. :) 다른 사람이 더 좋은 해결책을 얻은 경우, 물론 알려 주시기 바랍니다 – Honnes
@Honnes 정확히 뭐죠? 필요한 것? – Manikandan