[android-developers] Problems in use UTF-8 in the HTTP

2010-09-03 Thread João Sauer
Hi,

I'm having problems in get some UTF-8 characters, like 'ç','á' and
etc...
To be sure that the problem is in the http, I made few tests:
- Using a textView, I'm able to use these characters;
- If I open the link via Browser(firefox), I'm also able to see the
special characters;
- In the debug mode, when I receive the data from the server, if I
modify the value of the string that is having problems using the
eclipse debuging mode, I'm also able to see it correctly.

So, I really think that the problem is in the connection. I tried a
lot of combination and is not working.
These is the http code:
Code:

public class Http {

public String getUrlData(String url) {
String websiteData = null;
DefaultHttpClient client = new DefaultHttpClient();
try {
HttpGet method = new HttpGet(new URI(url));
HttpParams httpparams = new BasicHttpParams();
HttpProtocolParams.setVersion(httpparams,
HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpparams, "UTF-8");
method.setParams(httpparams);
method.addHeader("Accept", "*/*");
HttpResponse res = client.execute(method);
websiteData = getResponse(res.getEntity());
} catch (IOException e) {
Log.e( "ouch", "!!! IOException " + e.getMessage() );
} catch (URISyntaxException e) {
Log.e( "ouch", "!!! IOException " + e.getMessage() );
}
return websiteData;
}

private String getResponse( HttpEntity entity )
{
String response = "";
try
{
int length = ( int ) entity.getContentLength();
StringBuffer sb = new StringBuffer( length );
InputStreamReader isr = new
InputStreamReader( entity.getContent(), "UTF-8" );
char buff[] = new char[length];
int cnt;
while ( ( cnt = isr.read( buff, 0, length - 1 ) ) > 0 )
{
sb.append( buff, 0, cnt ); //Here the
character is alredy wrong.
}
response = sb.toString();
isr.close();
} catch ( IOException ioe ) {
ioe.printStackTrace();
}
return response;
}
}

You will probably notice that is liek any example on the internet. The
only thing is that I tried to add UTF-8 in any place that is possible
to receive it.

Thanks for your help!

Joao

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] onNewIntent() is never called when use Icons

2009-11-15 Thread João Sauer
Hi,

What I'm trying to do was supposed to be very simple, but is not
working. :)
I would like to have 2 Icons that will call my activity, that is the
only one in the package.
But, when the activity is called, I would like to know which of these
Icons was used.
In the logs, I'm able to see that the Intent sent asap after press the
icon is sending this message like:
I(  569:0x23d) Starting activity: Intent
{ action=android.intent.action.MAIN categories=
{android.intent.category.LAUNCHER} flags=0x1020 comp={teste.teste/
teste.teste.alias1} }

But, my override of onNewIntent is never called and the onResume is
receiving a modified version of the Intent:
D(  896:0x380) Intent is Intent { action=android.intent.action.MAIN
categories={android.intent.category.LAUNCHER} flags=0x1020 comp=
{teste.teste/teste.teste.mainapp} }

As you can see, the alias1 packagename was modified to mainapp. And
because of this, I'm unable to check which button was applied.

My code in the manifest file is simple:
 

























As you can see, I'm using the singleTop definition, as a requirement
for onNewIntent call.

Any ideas what could be wrong here? Or, How can I have a way to check
which Icon was used to call my Acitivity?

Thank you,
Joao Sauer

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en