0

Request_Viewer Activity

public class Request_Viewer extends ListActivity {
    private ProgressDialog pDialog;
    private static final String REQUEST_VIEWER_URL = "http://192.168.43.84/taxiservice/request_view.php";
    private static final String TAG_POSTS = "posts";
    private static final String TAG_REQUEST_ID = "request_id";
    private static final String TAG_CUSTOMER_CITY = "currentcity";
    private static final String TAG_CUSTOMER_NAME = "customername";
    private static final String TAG_CUSTOMER_MOBILE = "customermobile";
    private static final String TAG_STARTING_LOCATION = "starting_location";
    private static final String TAG_DISTINATION = "destination";
    private static final String TAG_WHENDATE = "whendate";
    private static final String TAG_WHENTIME = "whentime";
    private JSONArray cRequest = null;
    private ArrayList<HashMap<String, String>> cRequestList;
    Handler mHandler;
    TextView TextViewMobile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.request_viewer);

        this.mHandler = new Handler();
        m_Runnable.run();
    }
    private final Runnable m_Runnable = new Runnable()
    {
        public void run()

        {
            Request_Viewer.this.mHandler.postDelayed(m_Runnable,200);
        }
    };

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        new LoadRequests().execute();
    }

    public void addrefresh(View v) {
        new LoadRequests().execute();
    }
    public void addYes(View v) {
        Intent i = new Intent(getApplicationContext(),Send.class);
        startActivity(i);
    }
    public void updateJSONdata() {
        cRequestList = new ArrayList<HashMap<String, String>>();
        JSONParser jParser = new JSONParser();
        JSONObject json = jParser.getJSONFromUrl(REQUEST_VIEWER_URL);
        try {
            cRequest = json.getJSONArray(TAG_POSTS);
            for (int i = cRequest.length()-1; i > 0; i--) {
                JSONObject c = cRequest.getJSONObject(i);       
                String request_id = c.getString(TAG_REQUEST_ID);
                String current_city = c.getString(TAG_CUSTOMER_CITY);
                String customer_name = c.getString(TAG_CUSTOMER_NAME);
                String customer_mobile = c.getString(TAG_CUSTOMER_MOBILE);
                String starting_location = c.getString(TAG_STARTING_LOCATION);
                String distination = c.getString(TAG_DISTINATION);
                String whendate = c.getString(TAG_WHENDATE);
                String customer_time = c.getString(TAG_WHENTIME);
                HashMap<String, String> map = new HashMap<String, String>();
                map.put(TAG_REQUEST_ID, request_id);
                map.put(TAG_CUSTOMER_CITY, current_city);
                map.put(TAG_CUSTOMER_NAME, customer_name);
                map.put(TAG_CUSTOMER_MOBILE, customer_mobile);
                map.put(TAG_STARTING_LOCATION, starting_location);
                map.put(TAG_DISTINATION, distination);
                map.put(TAG_WHENDATE, whendate);
                map.put(TAG_WHENTIME, customer_time);
                cRequestList.add(map);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    private void updateList() {
        ListAdapter adapter = new SimpleAdapter(this, cRequestList,
                R.layout.single_view, new String[] { TAG_REQUEST_ID,TAG_CUSTOMER_CITY,TAG_CUSTOMER_NAME,TAG_CUSTOMER_MOBILE,TAG_STARTING_LOCATION,TAG_DISTINATION, TAG_WHENDATE,
                TAG_WHENTIME }, new int[] { R.id.request_id,R.id.current_city,R.id.customer_name,R.id.customer_mobile, R.id.starting_location,
                R.id.distination,R.id.whendate,R.id.customer_time });
        setListAdapter(adapter);
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextViewMobile=(TextView)findViewById(R.id.customer_mobile);
            final  String CustomerMobile=TextViewMobile.getText().toString();
            Intent intent = new Intent(Request_Viewer.this, Send.class);
            intent.putExtra("customermobile",CustomerMobile);
             startActivity(intent);
            }
        });
    }
    public class LoadRequests extends AsyncTask<Void, Void, Boolean> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Request_Viewer.this);
            pDialog.setMessage("Loading Requests...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected Boolean doInBackground(Void... arg0) {
            updateJSONdata();
            return null;
        }
        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            pDialog.dismiss();
            updateList();
        }
    }
}
**Send Activity**

package com.example.king.driverapptaxiexpress;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Send extends Activity {
    EditText AnswerYes;
    TextView Phone;
    Button DriverSend;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send);
        AnswerYes = (EditText) findViewById(R.id.editYes);
        Phone=(TextView)findViewById(R.id.editView1);
        DriverSend = (Button) findViewById(R.id.button1); 
        //int index = data.getIntExtra("songIndex", 0);
        Phone.setText(getIntent().getExtras().getString("customermobile",null));
        DriverSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phoneNumber = ((TextView)findViewById(R.id.editView1)).getText().toString();
                String yes=AnswerYes.getText().toString();

                try {
                    SmsManager.getDefault().sendTextMessage(phoneNumber, null,yes, null, null);
                    Toast.makeText(getApplicationContext(), "Sent Successfully", Toast.LENGTH_SHORT).show();
                }
                catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "sending fail", Toast.LENGTH_SHORT).show();
                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Send.this);
                    AlertDialog dialog = alertDialogBuilder.create();
                    dialog.setMessage(e.getMessage());
                    dialog.show();
                }
            }
        });
    }
}

My Php Script is

<?php
$query_params=null;
require("config.inc.php");
$query = "Select * FROM req_spec";
try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
    $response["success"] = 0;
    $response["message"] = "Database Error!";
    die(json_encode($response));
} 
$rows = $stmt->fetchAll();
if ($rows) {
    $response["success"] = 1;
    $response["message"] = "Available Requests";
    $response["posts"]   = array();
    foreach ($rows as $row) {
        $post             = array();
        $post["request_id"]  = $row["request_id"];
        $post["currentcity"] = $row["currentcity"];
        $post["customername"] = $row["customername"];
        $post["customermobile"] = $row["customermobile"];
        $post["starting_location"] = $row["starting_location"];
        $post["destination"]    = $row["destination"];
        $post["whendate"]  = $row["whendate"];
        $post["whentime"]  = $row["whentime"];
        //update our repsonse JSON data
        array_push($response["posts"], $post);
    }
   // echoing JSON response
    echo json_encode($response);

} 
else {
    $response["success"] = 0;
    $response["message"] = "No Requests Available";
    die(json_encode($response));
}
?>`
Cœur
  • 37,241
  • 25
  • 195
  • 267
Zahir Ali
  • 1
  • 1
  • convert them to String – karan Aug 27 '15 at 07:34
  • You also need to explain, what is the problem in the code. – Murtaza Khursheed Hussain Aug 27 '15 at 07:34
  • sir i the mobile no which i am getting from Request_viewer class...that mobile no i would like to send to Send class for sending sms.....when i click on list view....the code does not send the correct Mobile no...that i have stored in database – Zahir Ali Aug 27 '15 at 17:41
  • `Intent intent = new Intent(Request_Viewer.this, Send.class); intent.putExtra("customermobile",CustomerMobile); startActivity(intent);` – Zahir Ali Aug 27 '15 at 17:42
  • ` AnswerYes = (EditText) findViewById(R.id.editYes); Phone=(TextView)findViewById(R.id.editView1); DriverSend = (Button) findViewById(R.id.button1); Phone.setText(getIntent().getExtras().getString("customermobile");` – Zahir Ali Aug 27 '15 at 17:44
  • but this code always sends mobile no from upper row in table – Zahir Ali Aug 27 '15 at 17:46
  • possible duplicate of (https://stackoverflow.com/questions/2736389/how-to-pass-an-object-from-one-activity-to-another-on-android) –  Sep 10 '18 at 13:20

0 Answers0