user3536515 February 2016

Send android activity variable to php script

I'm trying to read a php script URL through QR code and then retrieve MAC of device, after that, I want to send the MAC to php script but android app is crashing if I try it.

I'm also opening the url in a browser using intent. What should I write at php side to retrieve the MAC address and any changes in android activity?

Code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_decoder);

    mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
    mydecoderview.setOnQRCodeReadListener(this);

    myTextView = (TextView) findViewById(R.id.exampleTextView);

    line_image = (ImageView) findViewById(R.id.red_line_image);

    TranslateAnimation mAnimation = new TranslateAnimation(
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 0.5f);
    mAnimation.setDuration(1000);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    mAnimation.setInterpolator(new LinearInterpolator());
    line_image.setAnimation(mAnimation);

     Button button2 = (Button) findViewById(R.id.button2);
    button2.setOnClickListener(
            new View.OnClickListener() {
                public void onClick(View v) {
               /*String ur="http://192.168.0.105/project/rec.html";
                    Intent intent1=new Intent("android.intent.action.VIEW");
                    if (!ur.contains("http://"))
                        ur = "http://" + ur;
                    intent1.setData(Uri.parse(ur));

                    startActivity(intent1);// Perform action on click*/



                }

            });




}

// Called when a QR is decoded
// "text" : the text encoded in QR
// "points" : points where QR control points are placed

@Override
public void on        

Answers


Muhammad Maavia Kamran February 2016

error_reporting(0);
include("db_config.php");
$response = array();
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $item = $_GET['item']; 
    $r = mysql_query("select Department_id from student where st_id = '$id'");
    $row = mysql_fetch_array($r);
    $Department_id = $row[0];
    $r = mysql_query("select Subject_name from subject where Subject_code ='$item'");
    $row = mysql_fetch_array($r);
    $Subject_name = $row[0];
    $result = mysql_query("INSERT INTO `sis_fyp`.`student-subject` (`st_id`, `Subject_code`, `Status`, `grade`, `Department_id`, `Subject_name`) VALUES ('$id', '$item', 'Repeat', 'W', '$Department_id', '$Subject_name');");

    if ($result>0) {
        $response["success"] = 1;
    } else {
        $response["success"] = 0;
    }
    // echoing JSON response
    echo json_encode($response);
}

Just make a php script like above and pass your url in and android like:

wwww.yoururl.com?id=$id&item=$item

Post Status

Asked in February 2016
Viewed 2,939 times
Voted 8
Answered 1 times

Search




Leave an answer