Thanks for your valuable reply,
i have to develop speed test application in andorid. i have developed
upload application in java , i can upload the file from java to public
server, when i put that application to android , it is not working , i
will attach the upload code and log. kinldy guid me how do i proceed.
Idea behind this application is to find upload speed , download speed
and roundtrip time calculation.now i am trying to upload the file from
android to public server and then i will find the speed .
Thanks in advance
source code
package com.example.uplaod;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
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;
public class MyUpload extends Activity {
private Button mbutt;
public static String ftpServer= "upload.easy-share.com:21";
public static String user ="aswini";
public static String password ="sairom143";
public static String fileName ="abc";
//public static String localpath ="/mnt/sdcard/sample.txt";
File source =new File("/mnt/sdcard/sample.txt");
int bytesIn=0;
OutputStream outstream=null;
BufferedReader /*InputStream*/instream=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mbutt =(Button) findViewById(R.id.button1);
// (TextView) findViewById(R.id.textView1);
mbutt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
upload( ftpServer, user, password,
fileName, source );
}
private void upload(String ftpServer, String user,
String password,
String fileName, File source) {
// TODO Auto-generated method stub
if (ftpServer != null && fileName != null &&
source != null)
{
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its
anonymous
access.
if (user != null && password != null)
{
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
}
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
/*
* type ==> a=ASCII mode, i=image (binary)
mode, d= file
directory
* listing
*/
sb.append( ";type=i" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = null;
try {
url = new URL(
sb.toString() );
} catch (MalformedURLException
e) {
// TODO Auto-generated
catch block
e.printStackTrace();
}
URLConnection urlc = null;
try {
urlc =
url.openConnection();
if(urlc == null)
{
System.out.println( "URL didnt
open" );
return ;
}
} catch (IOException e) {
// TODO Auto-generated
catch block
e.printStackTrace();
}
System.out.println( "connection opened" );
try {
//bos = new
BufferedOutputStream( urlc.getOutputStream() );
outstream = urlc.getOutputStream() ;
} catch (IOException e1) {
// TODO Auto-generated
catch block
e1.printStackTrace();
}
System.out.println( "get output stream" );
try {
//bis = new
BufferedInputStream( new
FileInputStream( source ) );
if(source == null)
{
System.out.println( "file
Didnot open" );
return ;
}
instream = new BufferedReader(new
FileReader(source));
//instream = new BufferedInputStream(
new
FileInputStream( source ) );
} catch (FileNotFoundException
e) {
// TODO Auto-generated
catch block
e.printStackTrace();
}
int i;
// read byte by byte until end of stream
try {
//while ((i =
bis.read()) != -1)
if (instream == null)
{
System.out.println( "file didnt
open" );
return ;
}
//int fileSize=0;
//while ((i =
instream.read()) != -1)
String str;
while ( (str=instream.readLine())
!=null)
{
//
fileSize+=i;
//bos.write( i );
//Log.d("Test",str);
System.out.println( "afterLogd"
);
outstream.write(str.getBytes());
//outstream.write( i );
}
} catch (IOException e) {
// TODO Auto-generated
catch block
e.printStackTrace();
}
System.out.println( "file uploaded
successfully" );
}
finally
{
if (instream != null)
try
{
// bis.close();
instream.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (outstream != null)
try
{
//bos.close();
outstream.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
else
{
System.out.println( "Input not available." );
}
}
});
}
}
log:
03-25 10:21:51.470: DEBUG/AndroidRuntime(292): Shutting down VM
03-25 10:21:51.490: DEBUG/jdwp(292): adbd disconnected
03-25 10:21:51.589: INFO/AndroidRuntime(292): NOTE: attach of thread
'Binder Thread #3' failed
03-25 10:21:51.670: INFO/ActivityManager(59): Start proc
com.example.uplaod for activity com.example.uplaod/.MyUpload: pid=301
uid=10034 gids={3003}
03-25 10:21:53.509: INFO/ActivityManager(59): Displayed activity
com.example.uplaod/.MyUpload: 1939 ms (total 57693 ms)
03-25 10:21:53.521: INFO/ActivityManager(59): Displayed activity
com.android.launcher/com.android.launcher2.Launcher: 57702 ms (total
57702 ms)
03-25 10:26:33.650: DEBUG/SntpClient(59): request time failed:
java.net.SocketException: Address family not supported by protocol
03-25 10:30:25.390: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
03-25 10:30:25.609: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
03-25 10:30:25.990: INFO/ARMAssembler(59): generated
scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at
[0x3508f8:0x350a04] in 8088811 ns
03-25 10:30:26.100: INFO/ARMAssembler(59): generated
scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at
[0x350a08:0x350bd0] in 2057066 ns
03-25 10:30:27.240: INFO/System.out(301): connection opened
03-25 10:31:33.661: DEBUG/SntpClient(59): request time failed:
java.net.SocketException: Address family not supported by protocol
03-25 10:33:36.821: WARN/System.err(301): java.io.IOException: Unable
to connect to server: The operation timed out
03-25 10:33:36.850: WARN/System.err(301): at
org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:
204)
03-25 10:33:36.850: WARN/System.err(301): at
org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getOutputStream(FtpURLConnection.java:
344)
03-25 10:33:36.850: WARN/System.err(301): at
com.example.uplaod.MyUpload$1.upload(MyUpload.java:106)
03-25 10:33:36.860: WARN/System.err(301): at
com.example.uplaod.MyUpload$1.onClick(MyUpload.java:48)
03-25 10:33:36.869: WARN/System.err(301): at
android.view.View.performClick(View.java:2408)
03-25 10:33:36.869: WARN/System.err(301): at android.view.View
$PerformClick.run(View.java:8816)
03-25 10:33:36.869: WARN/System.err(301): at
android.os.Handler.handleCallback(Handler.java:587)
03-25 10:33:36.879: WARN/System.err(301): at
android.os.Handler.dispatchMessage(Handler.java:92)
03-25 10:33:36.879: WARN/System.err(301): at
android.os.Looper.loop(Looper.java:123)
03-25 10:33:36.889: WARN/System.err(301): at
android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 10:33:36.889: WARN/System.err(301): at
java.lang.reflect.Method.invokeNative(Native Method)
03-25 10:33:36.889: WARN/System.err(301): at
java.lang.reflect.Method.invoke(Method.java:521)
03-25 10:33:36.901: WARN/System.err(301): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 10:33:36.909: WARN/System.err(301): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 10:33:36.909: WARN/System.err(301): at
dalvik.system.NativeStart.main(Native Method)
03-25 10:33:36.909: INFO/System.out(301): get output stream
03-25 10:33:36.929: INFO/global(301): Default buffer size used in
BufferedReader constructor. It would be better to be explicit if an 8k-
char buffer is required.
03-25 10:33:36.951: INFO/System.out(301): afterLogd
03-25 10:33:36.951: DEBUG/AndroidRuntime(301): Shutting down VM
03-25 10:33:36.960: WARN/dalvikvm(301): threadid=1: thread exiting
with uncaught exception (group=0x4001d800)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): FATAL EXCEPTION: main
03-25 10:33:36.980: ERROR/AndroidRuntime(301):
java.lang.NullPointerException
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
com.example.uplaod.MyUpload$1.upload(MyUpload.java:146)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
com.example.uplaod.MyUpload$1.onClick(MyUpload.java:48)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
android.view.View.performClick(View.java:2408)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at android.view.View
$PerformClick.run(View.java:8816)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
android.os.Handler.handleCallback(Handler.java:587)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
android.os.Handler.dispatchMessage(Handler.java:92)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
android.os.Looper.loop(Looper.java:123)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
java.lang.reflect.Method.invokeNative(Native Method)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
java.lang.reflect.Method.invoke(Method.java:521)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 10:33:36.980: ERROR/AndroidRuntime(301): at
dalvik.system.NativeStart.main(Native Method)
03-25 10:33:37.050: WARN/ActivityManager(59): Force finishing
activity com.example.uplaod/.MyUpload
03-25 10:33:37.741: WARN/ActivityManager(59): Activity pause timeout
for HistoryRecord{450048f8 com.example.uplaod/.MyUpload}
03-25 10:33:37.780: INFO/ARMAssembler(59): generated
scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at
[0x369558:0x369614] in 740155 ns
03-25 10:33:48.551: WARN/ActivityManager(59): Activity destroy timeout
for HistoryRecord{450048f8 com.example.uplaod/.MyUpload}
03-25 10:36:33.702: DEBUG/SntpClient(59): request time failed:
java.net.SocketException: Address family not supported by protocol
03-25 10:38:00.259: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 10969
objects / 509000 bytes in 245ms
03-25 10:38:37.192: INFO/Process(301): Sending signal. PID: 301 SIG: 9
03-25 10:38:37.231: INFO/ActivityManager(59): Process
com.example.uplaod (pid 301) has died.
03-25 10:38:37.250: INFO/WindowManager(59): WIN DEATH: Window{45041eb0
com.example.uplaod/com.example.uplaod.MyUpload paused=false}
03-25 10:38:37.279: WARN/InputManagerService(59): Got RemoteException
sending setActive(false) notification to pid 301 uid 10034
Thanks & Regards
sneha
On Mar 25, 3:24 am, Nicholas Johnson <[email protected]> wrote:
> There are several FTP apps that can do just that. Astro file manager can
> create SFTP connections to upload files, or AndFTP... (there's a whole bunch
> if you search for FTP on the Android Market).
>
> If you're talking about uploading a file to a public server from an app
> you're developing, then you can use HTTP POST methods or a custom built FTP
> uploader.
>
> --Nick
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en