i have found lots of responses of them written deprecated functions or don't work in case.
i need imei number (unic id of device) of mobile device app installed, , send value (in form of string) php file located in folder created in website (because app has webview visualize website , want save imei data base).
so far, got in code:
public void postdata() { // create new httpclient , post header httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://www.chapatelo.hol.es/php/postimei.php"); telephonymanager telephonymanager = (telephonymanager)getsystemservice(context.telephony_service); try { // add data list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(1); namevaluepairs.add(new basicnamevaluepair("imei", telephonymanager.getdeviceid())); 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 } }
and have <uses-permission android:name="android.permission.internet"/>
, <uses-permission android:name="android.permission.read_phone_state"/>
in manifest.
and php file:
<?php require_once("conexion.php"); if(!isset($_session)){ session_start(); } $imei = $_post["imei"]; $query1 = "select * usuarios imei = '$imei'"; if($resp1 = mysqli_query($conexion, $query1)){ if(mysqli_num_rows($resp1) == 0){ $query2 = "insert usuarios (imei) values ('$imei')"; if(mysqli_query($conexion, $query2)){ $_session["imei"] = $imei; echo true; }else{ echo "error de conexión"; } }else{ echo "ya existe el imei en la db"; } }else{ echo "error de conexión"; } mysqli_close($conexion); ?>
however, , not mentioning every function such httpclient
deprecated, nothing of works.
i gave permitions 755 (read , execute) php folder , file access through app, nothing happens...
is there "new version" of functions i'm using imei , send php file?
is because of deprecated functions app doesn't save imei in data base?
you can refer this, might
java
public void executehttpget() throws exception { bufferedreader in = null; try { httpclient client = new defaulthttpclient(); httpget request = new httpget(); request.seturi(new uri("http://testsite.com/" + "imei_script.php?imei=" + telmanager.getdeviceid() )); httpresponse response = client.execute(request); in = new bufferedreader (new inputstreamreader(response.getentity().getcontent())); stringbuffer sb = new stringbuffer(""); string line = ""; string nl = system.getproperty("line.separator"); while ((line = in.readline()) != null) { sb.append(line + nl); } in.close(); string page = sb.tostring(); system.out.println(page); } { if (in != null) { try { in.close(); } catch (ioexception e) { e.printstacktrace(); } } } }
php
<?php // return plain text header("content-type: plain/text"); $imei = $_get["imei"]; $file=fopen("imei.txt","r") or exit("unable open file!"); while(!feof($file)) { if ($imei==chop(fgets($file))) echo "true"; } fclose($file); ?>
Comments
Post a Comment