0

i'm sending a post using this code:

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("imagem", "1"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}
v.setEnabled(true);

it works fine on my emulator. I have already searched on other posts how to solve this and what i have found was something about the android manifest having internet permission. Here is my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="imp.projecto.teste.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".ActivityImagem" />
    <activity android:name=".ActivityVideo" />
    <activity android:name=".ActivityMusica" />
    <activity android:name=".ActivityRadio" />
    <activity android:name=".ActivityOpcoes" />

</application>

I have no idea if i used the internet permission code in the right place and if it is doing it's job. I really need some help and some orientation.

TronicZomB
  • 8,667
  • 7
  • 35
  • 50

1 Answers1

1

Looks like you're trying to run a network request on the main UI thread. Android does not allow you to do that since 3.0 (I believe). Doing so causes your UI to lock up until the request is completed, rendering your app useless during the execution of the request.

You'll either have to run your request in a new Thread or an ASyncTask, to take the load of the UI thread. You can find more info on how to use multiple threads here.

Sander van't Veer
  • 5,930
  • 5
  • 35
  • 50
  • thanks for the input but that's not the real problem, because i'm runing it in android 2.2. My problem is that when i'm running my app in the emulator 2.2 all works fine, but when i try to run the emulator in my phone witch is android 2.3.4 the posts stop working and the app does not give any error or excetion. – user2315467 Apr 24 '13 at 13:54
  • Well... You're not doing anything with the Exceptions it throws in the code you posted so that might explain why you don't see any errors. You catch them, but you don't handle them. – Sander van't Veer Apr 24 '13 at 14:41