SlideShare a Scribd company logo
1 of 13
Download to read offline
Android Studio Assignment Help
Can someone who is familiar with Android Studio help me create (in Java) a code in an app page
that lets the user upload any picture and saves it into the app after its uploaded.
Can you please post the Java code, XML code, and screenshots if possible?
Solution
AndroidManifest.xml
-----
---------
activity_upload_to_server.xml
----------------
---------------------
Upload.java
---------------------
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Upload extends Activity {
TextView messageText;
Button uploadButton;
int serverResponseCode = 0;
ProgressDialog dialog = null;
String upLoadServerUri = null;
/********** File Path *************/
final String uploadFilePath = "/mnt/sdcard/";
final String uploadFileName = "123.png";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_to_server);
uploadButton = (Button)findViewById(R.id.uploadButton);
messageText = (TextView)findViewById(R.id.messageText);
messageText.setText("Uploading file path :- '/mnt/sdcard/"+uploadFileName+"'");
/************* Php script path ****************/
upLoadServerUri = "http://www.abc.com/media/UploadToServer.php";
uploadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true);
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});
uploadFile(uploadFilePath + "" + uploadFileName);
}
}).start();
}
});
}
public int uploadFile(String sourceFileUri) {
String fileName = sourceFileUri;
HttpURLConnection conn = null;
DataOutputStream dos = null;
String lineEnd = "  ";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
File sourceFile = new File(sourceFileUri);
if (!sourceFile.isFile()) {
dialog.dismiss();
Log.e("uploadFile", "Source File not exist :"
+uploadFilePath + "" + uploadFileName);
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("Source File not exist :"
+uploadFilePath + "" + uploadFileName);
}
});
return 0;
}
else
{
try {
// open a URL connection to the Servlet
FileInputStream fileInputStream = new FileInputStream(sourceFile);
URL url = new URL(upLoadServerUri);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" +
boundary);
conn.setRequestProperty("uploaded_file", fileName);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data;
name="uploaded_file";filename=""
+ fileName + """ + lineEnd);
dos.writeBytes(lineEnd);
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// Responses from the server (code and message)
serverResponseCode = conn.getResponseCode();
String serverResponseMessage = conn.getResponseMessage();
Log.i("uploadFile", "HTTP Response is : "
+ serverResponseMessage + ": " + serverResponseCode);
if(serverResponseCode == 200){
runOnUiThread(new Runnable() {
public void run() {
String msg = "File Upload Completed.  See uploaded file here :   "
+" xyz.com"
+uploadFileName;
messageText.setText(msg);
Toast.makeText(UploadToServer.this, "File Upload Complete.",
Toast.LENGTH_SHORT).show();
}
});
}
//close the streams //
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
dialog.dismiss();
ex.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("MalformedURLException Exception : check script
url.");
Toast.makeText(UploadToServer.this, "MalformedURLException",
Toast.LENGTH_SHORT).show();
}
});
Log.e("Upload file to server", "error: " + ex.getMessage(), ex);
} catch (Exception e) {
dialog.dismiss();
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("Got Exception : see logcat ");
Toast.makeText(UploadToServer.this, "Got Exception : see logcat ",
Toast.LENGTH_SHORT).show();
}
});
Log.e("Upload file to server Exception", "Exception : "
+ e.getMessage(), e);
}
dialog.dismiss();
return serverResponseCode;
} // End else block
}
}
---------
activity_upload_to_server.xml
----------------
---------------------
Upload.java
---------------------
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Upload extends Activity {
TextView messageText;
Button uploadButton;
int serverResponseCode = 0;
ProgressDialog dialog = null;
String upLoadServerUri = null;
/********** File Path *************/
final String uploadFilePath = "/mnt/sdcard/";
final String uploadFileName = "123.png";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_to_server);
uploadButton = (Button)findViewById(R.id.uploadButton);
messageText = (TextView)findViewById(R.id.messageText);
messageText.setText("Uploading file path :- '/mnt/sdcard/"+uploadFileName+"'");
/************* Php script path ****************/
upLoadServerUri = "http://www.abc.com/media/UploadToServer.php";
uploadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true);
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});
uploadFile(uploadFilePath + "" + uploadFileName);
}
}).start();
}
});
}
public int uploadFile(String sourceFileUri) {
String fileName = sourceFileUri;
HttpURLConnection conn = null;
DataOutputStream dos = null;
String lineEnd = "  ";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
File sourceFile = new File(sourceFileUri);
if (!sourceFile.isFile()) {
dialog.dismiss();
Log.e("uploadFile", "Source File not exist :"
+uploadFilePath + "" + uploadFileName);
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("Source File not exist :"
+uploadFilePath + "" + uploadFileName);
}
});
return 0;
}
else
{
try {
// open a URL connection to the Servlet
FileInputStream fileInputStream = new FileInputStream(sourceFile);
URL url = new URL(upLoadServerUri);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" +
boundary);
conn.setRequestProperty("uploaded_file", fileName);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data;
name="uploaded_file";filename=""
+ fileName + """ + lineEnd);
dos.writeBytes(lineEnd);
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// Responses from the server (code and message)
serverResponseCode = conn.getResponseCode();
String serverResponseMessage = conn.getResponseMessage();
Log.i("uploadFile", "HTTP Response is : "
+ serverResponseMessage + ": " + serverResponseCode);
if(serverResponseCode == 200){
runOnUiThread(new Runnable() {
public void run() {
String msg = "File Upload Completed.  See uploaded file here :   "
+" xyz.com"
+uploadFileName;
messageText.setText(msg);
Toast.makeText(UploadToServer.this, "File Upload Complete.",
Toast.LENGTH_SHORT).show();
}
});
}
//close the streams //
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
dialog.dismiss();
ex.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("MalformedURLException Exception : check script
url.");
Toast.makeText(UploadToServer.this, "MalformedURLException",
Toast.LENGTH_SHORT).show();
}
});
Log.e("Upload file to server", "error: " + ex.getMessage(), ex);
} catch (Exception e) {
dialog.dismiss();
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("Got Exception : see logcat ");
Toast.makeText(UploadToServer.this, "Got Exception : see logcat ",
Toast.LENGTH_SHORT).show();
}
});
Log.e("Upload file to server Exception", "Exception : "
+ e.getMessage(), e);
}
dialog.dismiss();
return serverResponseCode;
} // End else block
}
}

More Related Content

Similar to Android Studio Assignment HelpCan someone who is familiar with And.pdf

HTML5 APIs - Where No Man Has Gone Before! - Paris Web
HTML5 APIs -  Where No Man Has Gone Before! - Paris WebHTML5 APIs -  Where No Man Has Gone Before! - Paris Web
HTML5 APIs - Where No Man Has Gone Before! - Paris WebRobert Nyman
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLaurence Svekis ✔
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.Nerd Tzanetopoulos
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranRobert Nyman
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
 
file-transfer-using-tcp.pdf
file-transfer-using-tcp.pdffile-transfer-using-tcp.pdf
file-transfer-using-tcp.pdfJayaprasanna4
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxvishal choudhary
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageESUG
 
Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"Fwdays
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxhamblymarta
 

Similar to Android Studio Assignment HelpCan someone who is familiar with And.pdf (20)

HTML5 APIs - Where No Man Has Gone Before! - Paris Web
HTML5 APIs -  Where No Man Has Gone Before! - Paris WebHTML5 APIs -  Where No Man Has Gone Before! - Paris Web
HTML5 APIs - Where No Man Has Gone Before! - Paris Web
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
Deep dive into new ASP.NET MVC 4 Features
Deep dive into new ASP.NET MVC 4 Features Deep dive into new ASP.NET MVC 4 Features
Deep dive into new ASP.NET MVC 4 Features
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
file-transfer-using-tcp.pdf
file-transfer-using-tcp.pdffile-transfer-using-tcp.pdf
file-transfer-using-tcp.pdf
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptx
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docx
 

More from feelinggift

A) Which of the following element is seen in all organic molecules Si.pdf
A) Which of the following element is seen in all organic molecules Si.pdfA) Which of the following element is seen in all organic molecules Si.pdf
A) Which of the following element is seen in all organic molecules Si.pdffeelinggift
 
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdfGiven an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdffeelinggift
 
Write an MSP430g2553 C program to drive a continually scrolling mess.pdf
Write an MSP430g2553 C program to drive a continually scrolling mess.pdfWrite an MSP430g2553 C program to drive a continually scrolling mess.pdf
Write an MSP430g2553 C program to drive a continually scrolling mess.pdffeelinggift
 
Which of the following is NOT a financial measurement needed to see .pdf
Which of the following is NOT a financial measurement needed to see .pdfWhich of the following is NOT a financial measurement needed to see .pdf
Which of the following is NOT a financial measurement needed to see .pdffeelinggift
 
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdf
Which process uses chemiosmosis  A. Pyruvate oxidation  B. Electron .pdfWhich process uses chemiosmosis  A. Pyruvate oxidation  B. Electron .pdf
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdffeelinggift
 
What motives do corporate executives have that force them to embrace.pdf
What motives do corporate executives have that force them to embrace.pdfWhat motives do corporate executives have that force them to embrace.pdf
What motives do corporate executives have that force them to embrace.pdffeelinggift
 
when are business cases or project charters overkillSolutionP.pdf
when are business cases or project charters overkillSolutionP.pdfwhen are business cases or project charters overkillSolutionP.pdf
when are business cases or project charters overkillSolutionP.pdffeelinggift
 
True or False The Congressional Budget Office projects that approxi.pdf
True or False The Congressional Budget Office projects that approxi.pdfTrue or False The Congressional Budget Office projects that approxi.pdf
True or False The Congressional Budget Office projects that approxi.pdffeelinggift
 
Using the space provided compose an ESSAY concerning the following qu.pdf
Using the space provided compose an ESSAY concerning the following qu.pdfUsing the space provided compose an ESSAY concerning the following qu.pdf
Using the space provided compose an ESSAY concerning the following qu.pdffeelinggift
 
We continually hear about interest groups in the news. Understanding.pdf
We continually hear about interest groups in the news. Understanding.pdfWe continually hear about interest groups in the news. Understanding.pdf
We continually hear about interest groups in the news. Understanding.pdffeelinggift
 
View transaction list Journal entry worksheet 6 9 The company receive.pdf
View transaction list Journal entry worksheet 6 9 The company receive.pdfView transaction list Journal entry worksheet 6 9 The company receive.pdf
View transaction list Journal entry worksheet 6 9 The company receive.pdffeelinggift
 
Physical security is a fundamental component of any secure infrastru.pdf
Physical security is a fundamental component of any secure infrastru.pdfPhysical security is a fundamental component of any secure infrastru.pdf
Physical security is a fundamental component of any secure infrastru.pdffeelinggift
 
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdfTrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdffeelinggift
 
This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdffeelinggift
 
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdfThe Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdffeelinggift
 
The first thermodynamic law for a system of charged molecules in elec.pdf
The first thermodynamic law for a system of charged molecules in elec.pdfThe first thermodynamic law for a system of charged molecules in elec.pdf
The first thermodynamic law for a system of charged molecules in elec.pdffeelinggift
 
show all of your work to arrive a final result Simple Interest Simpl.pdf
show all of your work to arrive a final result Simple Interest Simpl.pdfshow all of your work to arrive a final result Simple Interest Simpl.pdf
show all of your work to arrive a final result Simple Interest Simpl.pdffeelinggift
 
Terms from which students can chooseMacrophages; •Only one.pdf
Terms from which students can chooseMacrophages; •Only one.pdfTerms from which students can chooseMacrophages; •Only one.pdf
Terms from which students can chooseMacrophages; •Only one.pdffeelinggift
 
Simulate the Stakeholder deliverable for the development of an onlin.pdf
Simulate the Stakeholder deliverable for the development of an onlin.pdfSimulate the Stakeholder deliverable for the development of an onlin.pdf
Simulate the Stakeholder deliverable for the development of an onlin.pdffeelinggift
 
I want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdfI want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdffeelinggift
 

More from feelinggift (20)

A) Which of the following element is seen in all organic molecules Si.pdf
A) Which of the following element is seen in all organic molecules Si.pdfA) Which of the following element is seen in all organic molecules Si.pdf
A) Which of the following element is seen in all organic molecules Si.pdf
 
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdfGiven an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
 
Write an MSP430g2553 C program to drive a continually scrolling mess.pdf
Write an MSP430g2553 C program to drive a continually scrolling mess.pdfWrite an MSP430g2553 C program to drive a continually scrolling mess.pdf
Write an MSP430g2553 C program to drive a continually scrolling mess.pdf
 
Which of the following is NOT a financial measurement needed to see .pdf
Which of the following is NOT a financial measurement needed to see .pdfWhich of the following is NOT a financial measurement needed to see .pdf
Which of the following is NOT a financial measurement needed to see .pdf
 
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdf
Which process uses chemiosmosis  A. Pyruvate oxidation  B. Electron .pdfWhich process uses chemiosmosis  A. Pyruvate oxidation  B. Electron .pdf
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdf
 
What motives do corporate executives have that force them to embrace.pdf
What motives do corporate executives have that force them to embrace.pdfWhat motives do corporate executives have that force them to embrace.pdf
What motives do corporate executives have that force them to embrace.pdf
 
when are business cases or project charters overkillSolutionP.pdf
when are business cases or project charters overkillSolutionP.pdfwhen are business cases or project charters overkillSolutionP.pdf
when are business cases or project charters overkillSolutionP.pdf
 
True or False The Congressional Budget Office projects that approxi.pdf
True or False The Congressional Budget Office projects that approxi.pdfTrue or False The Congressional Budget Office projects that approxi.pdf
True or False The Congressional Budget Office projects that approxi.pdf
 
Using the space provided compose an ESSAY concerning the following qu.pdf
Using the space provided compose an ESSAY concerning the following qu.pdfUsing the space provided compose an ESSAY concerning the following qu.pdf
Using the space provided compose an ESSAY concerning the following qu.pdf
 
We continually hear about interest groups in the news. Understanding.pdf
We continually hear about interest groups in the news. Understanding.pdfWe continually hear about interest groups in the news. Understanding.pdf
We continually hear about interest groups in the news. Understanding.pdf
 
View transaction list Journal entry worksheet 6 9 The company receive.pdf
View transaction list Journal entry worksheet 6 9 The company receive.pdfView transaction list Journal entry worksheet 6 9 The company receive.pdf
View transaction list Journal entry worksheet 6 9 The company receive.pdf
 
Physical security is a fundamental component of any secure infrastru.pdf
Physical security is a fundamental component of any secure infrastru.pdfPhysical security is a fundamental component of any secure infrastru.pdf
Physical security is a fundamental component of any secure infrastru.pdf
 
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdfTrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
 
This is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdfThis is a homework assignment that I have for my Java coding class. .pdf
This is a homework assignment that I have for my Java coding class. .pdf
 
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdfThe Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
 
The first thermodynamic law for a system of charged molecules in elec.pdf
The first thermodynamic law for a system of charged molecules in elec.pdfThe first thermodynamic law for a system of charged molecules in elec.pdf
The first thermodynamic law for a system of charged molecules in elec.pdf
 
show all of your work to arrive a final result Simple Interest Simpl.pdf
show all of your work to arrive a final result Simple Interest Simpl.pdfshow all of your work to arrive a final result Simple Interest Simpl.pdf
show all of your work to arrive a final result Simple Interest Simpl.pdf
 
Terms from which students can chooseMacrophages; •Only one.pdf
Terms from which students can chooseMacrophages; •Only one.pdfTerms from which students can chooseMacrophages; •Only one.pdf
Terms from which students can chooseMacrophages; •Only one.pdf
 
Simulate the Stakeholder deliverable for the development of an onlin.pdf
Simulate the Stakeholder deliverable for the development of an onlin.pdfSimulate the Stakeholder deliverable for the development of an onlin.pdf
Simulate the Stakeholder deliverable for the development of an onlin.pdf
 
I want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdfI want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdf
 

Recently uploaded

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Android Studio Assignment HelpCan someone who is familiar with And.pdf

  • 1. Android Studio Assignment Help Can someone who is familiar with Android Studio help me create (in Java) a code in an app page that lets the user upload any picture and saves it into the app after its uploaded. Can you please post the Java code, XML code, and screenshots if possible? Solution AndroidManifest.xml ----- --------- activity_upload_to_server.xml ---------------- --------------------- Upload.java --------------------- import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class Upload extends Activity {
  • 2. TextView messageText; Button uploadButton; int serverResponseCode = 0; ProgressDialog dialog = null; String upLoadServerUri = null; /********** File Path *************/ final String uploadFilePath = "/mnt/sdcard/"; final String uploadFileName = "123.png"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_upload_to_server); uploadButton = (Button)findViewById(R.id.uploadButton); messageText = (TextView)findViewById(R.id.messageText); messageText.setText("Uploading file path :- '/mnt/sdcard/"+uploadFileName+"'"); /************* Php script path ****************/ upLoadServerUri = "http://www.abc.com/media/UploadToServer.php"; uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true); new Thread(new Runnable() { public void run() { runOnUiThread(new Runnable() { public void run() { messageText.setText("uploading started.....");
  • 3. } }); uploadFile(uploadFilePath + "" + uploadFileName); } }).start(); } }); } public int uploadFile(String sourceFileUri) { String fileName = sourceFileUri; HttpURLConnection conn = null; DataOutputStream dos = null; String lineEnd = " "; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; File sourceFile = new File(sourceFileUri); if (!sourceFile.isFile()) { dialog.dismiss(); Log.e("uploadFile", "Source File not exist :" +uploadFilePath + "" + uploadFileName); runOnUiThread(new Runnable() { public void run() { messageText.setText("Source File not exist :"
  • 4. +uploadFilePath + "" + uploadFileName); } }); return 0; } else { try { // open a URL connection to the Servlet FileInputStream fileInputStream = new FileInputStream(sourceFile); URL url = new URL(upLoadServerUri); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); // Allow Inputs conn.setDoOutput(true); // Allow Outputs conn.setUseCaches(false); // Don't use a Cached Copy conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); conn.setRequestProperty("uploaded_file", fileName); dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name="uploaded_file";filename="" + fileName + """ + lineEnd); dos.writeBytes(lineEnd);
  • 5. // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // Responses from the server (code and message) serverResponseCode = conn.getResponseCode(); String serverResponseMessage = conn.getResponseMessage(); Log.i("uploadFile", "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode); if(serverResponseCode == 200){ runOnUiThread(new Runnable() { public void run() { String msg = "File Upload Completed. See uploaded file here : " +" xyz.com"
  • 6. +uploadFileName; messageText.setText(msg); Toast.makeText(UploadToServer.this, "File Upload Complete.", Toast.LENGTH_SHORT).show(); } }); } //close the streams // fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { dialog.dismiss(); ex.printStackTrace(); runOnUiThread(new Runnable() { public void run() { messageText.setText("MalformedURLException Exception : check script url."); Toast.makeText(UploadToServer.this, "MalformedURLException", Toast.LENGTH_SHORT).show(); } }); Log.e("Upload file to server", "error: " + ex.getMessage(), ex); } catch (Exception e) { dialog.dismiss(); e.printStackTrace(); runOnUiThread(new Runnable() { public void run() {
  • 7. messageText.setText("Got Exception : see logcat "); Toast.makeText(UploadToServer.this, "Got Exception : see logcat ", Toast.LENGTH_SHORT).show(); } }); Log.e("Upload file to server Exception", "Exception : " + e.getMessage(), e); } dialog.dismiss(); return serverResponseCode; } // End else block } } --------- activity_upload_to_server.xml ---------------- --------------------- Upload.java --------------------- import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView;
  • 8. import android.widget.Toast; public class Upload extends Activity { TextView messageText; Button uploadButton; int serverResponseCode = 0; ProgressDialog dialog = null; String upLoadServerUri = null; /********** File Path *************/ final String uploadFilePath = "/mnt/sdcard/"; final String uploadFileName = "123.png"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_upload_to_server); uploadButton = (Button)findViewById(R.id.uploadButton); messageText = (TextView)findViewById(R.id.messageText); messageText.setText("Uploading file path :- '/mnt/sdcard/"+uploadFileName+"'"); /************* Php script path ****************/ upLoadServerUri = "http://www.abc.com/media/UploadToServer.php"; uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true); new Thread(new Runnable() {
  • 9. public void run() { runOnUiThread(new Runnable() { public void run() { messageText.setText("uploading started....."); } }); uploadFile(uploadFilePath + "" + uploadFileName); } }).start(); } }); } public int uploadFile(String sourceFileUri) { String fileName = sourceFileUri; HttpURLConnection conn = null; DataOutputStream dos = null; String lineEnd = " "; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; File sourceFile = new File(sourceFileUri); if (!sourceFile.isFile()) { dialog.dismiss(); Log.e("uploadFile", "Source File not exist :" +uploadFilePath + "" + uploadFileName);
  • 10. runOnUiThread(new Runnable() { public void run() { messageText.setText("Source File not exist :" +uploadFilePath + "" + uploadFileName); } }); return 0; } else { try { // open a URL connection to the Servlet FileInputStream fileInputStream = new FileInputStream(sourceFile); URL url = new URL(upLoadServerUri); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); // Allow Inputs conn.setDoOutput(true); // Allow Outputs conn.setUseCaches(false); // Don't use a Cached Copy conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); conn.setRequestProperty("uploaded_file", fileName); dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name="uploaded_file";filename=""
  • 11. + fileName + """ + lineEnd); dos.writeBytes(lineEnd); // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // Responses from the server (code and message) serverResponseCode = conn.getResponseCode(); String serverResponseMessage = conn.getResponseMessage(); Log.i("uploadFile", "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode); if(serverResponseCode == 200){ runOnUiThread(new Runnable() {
  • 12. public void run() { String msg = "File Upload Completed. See uploaded file here : " +" xyz.com" +uploadFileName; messageText.setText(msg); Toast.makeText(UploadToServer.this, "File Upload Complete.", Toast.LENGTH_SHORT).show(); } }); } //close the streams // fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { dialog.dismiss(); ex.printStackTrace(); runOnUiThread(new Runnable() { public void run() { messageText.setText("MalformedURLException Exception : check script url."); Toast.makeText(UploadToServer.this, "MalformedURLException", Toast.LENGTH_SHORT).show(); } }); Log.e("Upload file to server", "error: " + ex.getMessage(), ex); } catch (Exception e) { dialog.dismiss();
  • 13. e.printStackTrace(); runOnUiThread(new Runnable() { public void run() { messageText.setText("Got Exception : see logcat "); Toast.makeText(UploadToServer.this, "Got Exception : see logcat ", Toast.LENGTH_SHORT).show(); } }); Log.e("Upload file to server Exception", "Exception : " + e.getMessage(), e); } dialog.dismiss(); return serverResponseCode; } // End else block } }