Ich bin sehr neu in Android und ich würde gerne einige Variablen aus meiner Android-Anwendung auf eine PHP-Seite übergeben. Ich habe einen Code von einer Seite verwendet und versucht, ihn an das anzupassen, was ich brauche, aber im Moment werden die Variablen nicht übergeben. Was ich machen möchte ist, dass der Button mit der ID "button_wp" die Funktion "run" aktiviert. Der Code, den ich verwende, ist die folgende:Objekt an php senden von Android
Android xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to webpage"
android:id="@+id/button_wp"
android:onClick="wp" />
Android Java
public class Main3Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
}
public void wp(View v) {
new Thread(new Runnable() {
@Override
public void run() {
OutputStream os = null;
InputStream is = null;
HttpURLConnection conn = null;
try {
//constants
URL url = new URL("https://www.mypage.com/login_app.php");
JSONObject jsonObject = new JSONObject();
jsonObject.put("precio", "5000€");
String message = jsonObject.toString();
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /*milliseconds*/);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(message.getBytes().length);
//make some HTTP header nicety
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
//open
conn.connect();
//setup send
os = new BufferedOutputStream(conn.getOutputStream());
os.write(message.getBytes());
//clean up
os.flush();
//do somehting with response
is = conn.getInputStream();
//String contentAsString = readIt(is,len);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
//clean up
try {
os.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
conn.disconnect();
}
}
}).start();
}
}
php
$json = file_get_contents('php://input');
$obj = json_decode($json);
$precio = $obj->{'precio'};
Fehler nach Fehlersuche:
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve interface method 16209: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve interface method 16211: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve interface method 16215: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 532: Landroid/content/res/TypedArray;.getChangingConfigurations()I
08-18 04:28:02.021 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 554: Landroid/content/res/TypedArray;.getType (I)I
08-18 04:28:02.211 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 16639: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
08-18 04:28:02.271 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 495: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-18 04:28:02.271 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 497: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-18 04:28:02.271 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 321: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
08-18 04:28:02.651 31463-31463/com.example.+++.+++E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
08-18 04:28:02.651 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve instanceof 152 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
08-18 04:35:38.731 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 16912: Landroid/widget/Spinner;.getPopupContext()Landroid/content/Context;
08-18 04:35:38.731 31463-31463/com.example.+++.+++E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.<init>
08-18 04:35:38.731 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve instanceof 2085 (Landroid/widget/ThemedSpinnerAdapter;) in Landroid/support/v7/widget/AppCompatSpinner$DropDownAdapter;
08-18 04:37:23.001 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 196: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
08-18 04:37:23.001 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 453: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller;
08-18 04:37:32.901 31463-31463/com.example.+++.+++W/dalvikvm: method Landroid/support/v7/widget/ListViewCompat;.lookForSelectablePosition incorrectly overrides package-private method with same name in Landroid/widget/ListView;
08-18 04:37:32.901 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 14245: Landroid/support/v7/widget/DropDownListView;.drawableHotspotChanged (FF)V
08-18 04:37:32.901 31463-31463/com.example.+++.+++W/dalvikvm: VFY: unable to resolve virtual method 15841: Landroid/view/View;.drawableHotspotChanged (FF)V
08-18 04:37:39.821 31463-31463/com.example.+++.+++W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
Vielen Dank für Ihre Zeit
Sind Sie 'Post' Daten versuchen? – px06
Ja, ich versuche, die in meiner App generierten Daten in eine PHP-Seite zu posten. – alberzyzz
Was siehst du, wenn du 'echo $ json;' in deinem PHP-Skript verwendest? – simon