Wednesday, May 8, 2013

[android help] Setting up webserver to access media content for Android, Blackberry, and iPhone applications


first simply create VedioDownloader class and pass the url for download the vedio and call this class in thread in mainactivity



import android.os.Environment;
import android.util.Log;

public class VedioDownloader implements Runnable {
String vedio_URL = "http://daily3gp.com/vids/747.3gp";
//if download image then simply pass image url such as
//String image_URL = "http://www.appliconic.com/screen.jpg";
public void run() {
// TODO Auto-generated method stub
HttpURLConnection conn = null;
URL url = null;
try {
url = new URL(vedio_URLL);
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
conn = (HttpURLConnection) url.openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
conn.setDoInput(true);

try {
conn.connect();
Log.d("Connection", "Connection Established");
InputStream input = conn.getInputStream();
File storagePath = Environment.getExternalStorageDirectory();
OutputStream output = new FileOutputStream(new File(storagePath,
"vedio.3gp"));
Log.d("1", "1");
byte[] buffer = new byte[input.available()];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
Log.d("2", "2");
output.close();
input.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}


mainactivity class



public class MainActivity extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("aftar thread","befor thread");
Thread objThread=new Thread(new VedioDownloader());
objThread.start();
Log.d("aftar thread","fater thread");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


}



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...