[android-beginners] Re: [Help] About URLConnection

2008-09-25 Thread Ka

o ~~ I haven't ~~
now it works !! thx

On Sep 25, 5:02 pm, 김병주 [EMAIL PROTECTED] wrote:
 Have u put use-permission code into Manifesto.xml ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] [Help] About URLConnection

2008-09-24 Thread Ka

Hi,
I don't know why it doesn't work,
I'm using eclipse version 3.4
and android sdk0.9beta

Actually, I want to get the html code from a website,
and it throw to EXCEPETION , unknown error.
Then I try a sample code from http://www.anddev.org/working_with_files-t115.html

I found that when it runs .getInputStream(), it throw throw to
excepetion.

Here is the code.
-
package com.demo.test;
import java.net.*;
import java.io.*;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class test extends Activity {
@Override
public void onCreate(Bundle icicle) {
 super.onCreate(icicle);

 /* We will show the data we read in a TextView. */
 TextView tv = new TextView(this);

 /* Will be filled and displayed later. */
 String myString = null;
 try {
  /* Define the URL we want to load data from. */
  URL myURL = new URL(
http://www.anddev.org/images/tut/basic/
getdatafromtheweb/loadme.txt);
  /* Open a connection to that URL. */
  myString = before inputStream2;
  URLConnection ucon = myURL.openConnection();

  /* Define InputStreams to read
   * from the URLConnection. */
  InputStream is = ucon.getInputStream();
  BufferedInputStream bis = new BufferedInputStream(is);

  /* Read bytes to the Buffer until
   * there is nothing more to read(-1). */
  ByteArrayBuffer baf = new ByteArrayBuffer(50);
  int current = 0;
  while((current = bis.read()) != -1){
   baf.append((byte)current);
  }

  /* Convert the Bytes read to a String. */
  myString = new String(baf.toByteArray());
 } catch (Exception e) {
  /* On any Error we want to display it. */
  //myString = e.getMessage();
 }
 /* Show the String on the GUI. */
 tv.setText(myString);
 this.setContentView(tv);
}
}

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] [help] throw expection when use getInputStream()

2008-09-24 Thread Ka

Hi,

I am using eclipse version 3.4
android SDK 0.9Beta.

Actually, I want to get the html from a website. But it throw to
exception with unknow error, I found that when it
run .getInputStream(), then throw  exception.

I try a sample from http://www.anddev.org/working_with_files-t115.html,
same happen.

Here is the code:
---
package com.demo.test;
import java.net.*;
import java.io.*;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class test extends Activity {
@Override
public void onCreate(Bundle icicle) {
 super.onCreate(icicle);

 /* We will show the data we read in a TextView. */
 TextView tv = new TextView(this);

 /* Will be filled and displayed later. */
 String myString = null;
 try {
  /* Define the URL we want to load data from. */
  URL myURL = new URL(
http://www.anddev.org/images/tut/basic/
getdatafromtheweb/loadme.txt);
  /* Open a connection to that URL. */
  myString = before inputStream2;
  URLConnection ucon = myURL.openConnection();

  /* Define InputStreams to read
   * from the URLConnection. */
  InputStream is = ucon.getInputStream();
  BufferedInputStream bis = new BufferedInputStream(is);

  /* Read bytes to the Buffer until
   * there is nothing more to read(-1). */
  ByteArrayBuffer baf = new ByteArrayBuffer(50);
  int current = 0;
  while((current = bis.read()) != -1){
   baf.append((byte)current);
  }

  /* Convert the Bytes read to a String. */
  myString = new String(baf.toByteArray());
 } catch (Exception e) {
  /* On any Error we want to display it. */
  //myString = e.getMessage();
 }
 /* Show the String on the GUI. */
 tv.setText(myString);
 this.setContentView(tv);
}
}

Pls help ~ Thx so much !

Regards,
Ka

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Problem with java.net

2008-08-30 Thread KA

I added the permission it worked.
Thank you.

--
From: sacoskun [EMAIL PROTECTED]
Sent: Saturday, August 30, 2008 1:58 AM
To: Android Beginners android-beginners@googlegroups.com
Subject: [android-beginners] Re: Problem with java.net


 Please take a look at
 http://groups.google.com/group/android-developers/browse_thread/thread/d2fef5736396f41b/fe1b8d813e0e9eeb?show_docid=fe1b8d813e0e9eeb

 Regards,
 sacoskun

 On Aug 29, 1:37 pm, leafka [EMAIL PROTECTED] wrote:
 I want to test the following code, but the DDMS always display
 Unknown socket error -1 , I think the code is correct, Must I set up
 the emulator or soming? Thank you.

 Source Code:

 public class SocketApp extends Activity {

 private Button ok;
 private TextView tv1;
 HttpURLConnection uc ;
 URL url;
 private static final String ip=code.google.com/android/images/
 logo_android.gif;
 private static final String host=;
 private static final String path = http://; + ip +host ;

 ImageView view1;
 InputStream is;
 BufferedInputStream bis;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 ok = (Button)findViewById(R.id.Button01);

 ok.setOnClickListener(new View.OnClickListener() {
 public void onClick(View view) {
 openConn();
 sendRequest();
 getRespones();
 closeConn();
 }
 });

 }

 private void openConn(){
 try {
 url=new URL(path);
 uc = (HttpURLConnection)url.openConnection();
 uc.setDoInput(true);
 }catch (MalformedURLException e){
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }

 private void sendRequest(){
 try {
 Log.i([SocketApp], conn begin .);
 uc.connect();
 Log.i([SocketApp],conn end .);
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }

 private void getRespones(){
 try {
 is = uc.getInputStream();
 Log.d(lenght,+uc.getContentLength());
 tv1.setText(uc.getContentLength()+);
 bis = new BufferedInputStream(is);
 Bitmap bm = BitmapFactory.decodeStream(bis);
 view1.setImageBitmap(bm);
 } catch (IOException e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 }

 private void closeConn(){
 try {
 uc.disconnect();
 bis.close();
 is.close();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }

 }

 AndroidManifest.xml:

 ?xml version=1.0 encoding=utf-8?
 manifest xmlns:android=http://schemas.android.com/apk/res/android;
 package=com.ltinc.cn
 application android:icon=@drawable/icon android:label=@string/
 app_name
 activity android:name=.SocketApp android:label=@string/
 app_name
 intent-filter
 action android:name=android.intent.action.MAIN /
 category
 android:name=android.intent.category.LAUNCHER /
 /intent-filter
 intent-filter

 /intent-filter
 /activity
 /application
 /manifest
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---