如何发送短信,就像我的Android应用程序在银行完成金钱交易后发送的短信 [英] How do I send sms like those are sent after a money transaction is done in banks from my android application

查看:102
本文介绍了如何发送短信,就像我的Android应用程序在银行完成金钱交易后发送的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have an activity called PerryRoad.java as following.




package com.example.streetparkingsystem;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class PerryRoad extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.perryroad);

    Button b = (Button)findViewById(R.id.b1);
    b.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

 String uri = "https://maps.google.com/maps?f=d&daddr=Perry road,Bandra West,Mumbai";
 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
 intent.setClassName("com.google.android.apps.maps",
     "com.google.android.maps.MapsActivity");
       startActivity(intent);
          }
    });

    Button m = (Button)findViewById(R.id.b2);
    m.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    Intent lomap = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(lomap);
        }
    });



}
  }




This is basically an app for parking vehicles. The amount is fixed 100 Rs. to park at this place.As soon as user clicks get map button (perryroad.xml) app redirects user to MainActivity.java which is as follows.







package com.example.streetsystemparking;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;




import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
	
	Button refresh;
	Button bv1;
	Button bv2;
	Button bv3;
	Button bv4;
	Button bv5;
	Button bv6;
	Button bv7;
	Button bv8;
	String uid;
	String status;
	InputStream is=null;
	String result=null;
	String line=null;
	HttpResponse response;
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		refresh = (Button)findViewById(R.id.refresh);
		bv1 = (Button)findViewById(R.id.button1);
		bv2 = (Button)findViewById(R.id.button2);
		bv3 = (Button)findViewById(R.id.button3);
		bv4 = (Button)findViewById(R.id.button4);
		bv5 = (Button)findViewById(R.id.button5);
		bv6 = (Button)findViewById(R.id.button6);
		bv7 = (Button)findViewById(R.id.button7);
		bv8 = (Button)findViewById(R.id.button8);
        bv1.setOnClickListener(this);
		bv2.setOnClickListener(this);
		bv3.setOnClickListener(this);
		bv4.setOnClickListener(this);
		bv5.setOnClickListener(this);
		bv6.setOnClickListener(this);
		bv7.setOnClickListener(this);
		bv8.setOnClickListener(this);

		 refresh.setOnClickListener(new View.OnClickListener(){
	            public void onClick(View arg0){

	            	Intent intent = getIntent();
	                finish();
	                startActivity(intent);

	            }

	        });
		
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					uid="1";
					select();
					uid="2";
					select();	
					uid="3";
					select();
					uid="4";
					select();
					uid="5";
					select();	
					uid="6";
					select();
					uid="7";
					select();
					uid="8";
					select();
			
				}
			}).start();


	}
	
    public void onClick(View v) {
       switch(v.getId()){
           case R.id.button1:
        	 
          	if (bv1.getText().toString().equals("R1"))
          	{
          		showAlert1();
          		
          	}
          	else
          	{
          		Toast.makeText(MainActivity.this,"You clicked on block 1",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment1Activity.class),1);
          	}
   				   				
				
		   break;
		    
            case R.id.button2:
            	
            	if (bv2.getText().toString().equals("R2"))
            	{
            		showAlert2();
            	}
            	else
            	{
            		
                 Toast.makeText(MainActivity.this,"You clicked on block 2",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment2Activity.class),2);
            	}
    				
		    break;
            
            case R.id.button3:
            	 
            	if (bv3.getText().toString().equals("R3"))
            	{
            		showAlert3();
            	}
            	else{
                 Toast.makeText(MainActivity.this,"You clicked on block 3",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment3Activity.class),3);
            	}
    				
            	
            break;
            
            case R.id.button4:
            	if (bv4.getText().toString().equals("R4"))
              	{
              		showAlert4();
              		
              	}
              	else
              	{
            	 Toast.makeText(MainActivity.this,"You clicked on block 4",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment4Activity.class),4);
              	}
           	break;
           	
            case R.id.button5:
            	if (bv5.getText().toString().equals("R5"))
              	{
              		showAlert5();
              		
              	}
              	else
              	{
            	 Toast.makeText(MainActivity.this,"You clicked on block 5",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment5Activity.class),5);
              	}
            break;
            
            case R.id.button6:
            	if (bv6.getText().toString().equals("R6"))
              	{
              		showAlert6();
              		
              	}
              	else
              	{
              		Toast.makeText(MainActivity.this,"You clicked on block 6",Toast.LENGTH_LONG).show();
				    startActivityForResult(new Intent(MainActivity.this,Payment6Activity.class),6);
              	}
            break;
            
            case R.id.button7:
            	if (bv7.getText().toString().equals("R7"))
              	{
              		showAlert7();
              		
              	}
              	else
              	{
            	 Toast.makeText(MainActivity.this,"You clicked on block 7",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment7Activity.class),7);
              	}
            break;
            
            case R.id.button8:
            	if (bv8.getText().toString().equals("R8"))
              	{
              		showAlert8();
              		
              	}
              	else
              	{
            	 Toast.makeText(MainActivity.this,"You clicked on block 8",Toast.LENGTH_LONG).show();
				 startActivityForResult(new Intent(MainActivity.this,Payment8Activity.class),8);
              	}
            break;
       
        }

  }
 
    public void showAlert1(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 1")
		    	.setMessage("Are you sure you want to vacate Block 1 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials1.class));
		    	    	 }
		    	})
		    	
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert2(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 2")
		    	.setMessage("Are you sure you want to vacate Block 2 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials2.class));
		    	    }
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert3(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 3")
		    	.setMessage("Are you sure you want to vacate Block 3 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials3.class));
		    	    }
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert4(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 4")
		    	.setMessage("Are you sure you want to vacate Block 4 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials4.class));
		    	    }
		    	    	
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert5(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 5")
		    	.setMessage("Are you sure you want to vacate Block 5 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials5.class));
		    	    }
		    	    
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert6(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 6")
		    	.setMessage("Are you sure you want to vacate Block 6 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials6.class));
		    	    }
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert7(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 7")
		    	.setMessage("Are you sure you want to vacate Block 7 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials7.class));
		    	    	
		    	    }
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    public void showAlert8(){
		MainActivity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		    	builder
		    	.setTitle("Release Block 8")
		    	.setMessage("Are you sure you want to vacate Block 8 ?")
		    	.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	    public void onClick(DialogInterface dialog, int which) {			      	
		    	    	startActivity(new Intent (MainActivity.this,CheckVacatingCredentials8.class));
		    	    }
		    	})
		    	.setNegativeButton("No", null)						//Do nothing on no
		    	.show();		    	       
		    	}
		    });		    	   		    	
		 }
    
    
    public void select()
    {
    	ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
 
	nameValuePairs.add(new BasicNameValuePair("uid",uid));
	
    	try
    	{
		HttpClient httpclient = new DefaultHttpClient();
	        HttpPost httppost = new HttpPost("http://tanushreedutta.site40.net/map/select.php");
	        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
	        HttpResponse response = httpclient.execute(httppost); 
	        HttpEntity entity = response.getEntity();
	        is = entity.getContent();
	        Log.e("pass 1", "connection success ");
	        
	}
        catch(Exception e)
	{
        	Log.e("Fail 1", e.toString());
        	runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
			    	Toast.makeText(getApplicationContext(), "Invalid IP Address",Toast.LENGTH_LONG).show();
					
				}
			});
	}     
        
      try
        {
         	BufferedReader reader = new BufferedReader
				(new InputStreamReader(is,"iso-8859-1"),8);
            	StringBuilder sb = new StringBuilder();
            	while ((line = reader.readLine()) != null)
		{
       		    sb.append(line + "\n");
           	}
            	is.close();
            	result = sb.toString();
	        Log.e("pass 2", "connection success ");
	}
        catch(Exception e)
    	{
		Log.e("Fail 2", e.toString());
	}     
       
   	try
    	{
        	JSONObject json_data = new JSONObject(result);
        	status=(json_data.getString("status"));
        	
        	runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					if (uid.equals("1"))
					{
					if (status.equals("2"))
		        		 bv1.setText("R1");
					else
						bv1.setText("V1");
					}
					if (uid.equals("2"))
					{
					if (status.equals("2"))
		        		 bv2.setText("R2");
					else
						bv2.setText("V2");
					}
					if (uid.equals("3"))
					{

					if (status.equals("2"))
		        		 bv3.setText("R3");
					else
						bv3.setText("V3");
					}
					if (uid.equals("4"))
					{
					if (status.equals("2"))
		        		 bv4.setText("R4");
					else
						bv4.setText("V4");
					}
					if (uid.equals("5"))
					{
					if (status.equals("2"))
		        		 bv5.setText("R5");
					else
						bv5.setText("V5");
					}
					if (uid.equals("6"))
					{

					if (status.equals("2"))
		        		 bv6.setText("R6");
					else
						bv6.setText("V6");
					}
					if (uid.equals("7"))
					{
					if (status.equals("2"))
		        		 bv7.setText("R7");
					else
						bv7.setText("V7");
					}
					if (uid.equals("8"))
					{
					if (status.equals("2"))
		        		 bv8.setText("R8");
					else
						bv8.setText("V8");
					}
					
				}
			});  
	    	
    	}
        catch(Exception e)
    	{
        	Log.e("Fail 3", e.toString());
    	} 
    }
    
    public void update()
    {
    	
    	try
    	{
    		
    		ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		HttpClient httpclient = new DefaultHttpClient();
	        HttpPost httppost = new HttpPost("http://tanushreedutta.site40.net/map/map.php");
	        nameValuePairs = new ArrayList<NameValuePair>(2);
	        
	       	nameValuePairs.add(new BasicNameValuePair("uid",uid));
	       	nameValuePairs.add(new BasicNameValuePair("status",status));
	        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
	        response = httpclient.execute(httppost); 
	        ResponseHandler<String> responseHandler = new BasicResponseHandler();
			final String response = httpclient.execute(httppost, responseHandler);
	       // HttpEntity entity = response.getEntity();
	       // is = entity.getContent();
	        Log.e("pass 1", "connection success ");
    	}
        catch(Exception e)
    	{
        	Log.e("Fail 1", e.toString());
	    	Toast.makeText(getApplicationContext(), "Invalid IP Address",
			Toast.LENGTH_LONG).show();
    	}     
    }

}




On clicking V1 button (in my activity_main.xml file)it goes to Payment1Activity.java and does payment.







package com.example.streetsystemparking;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.RemoteViews;
//import com.example.streetsystemparking.MainActivity; 


public class Payment1Activity extends Activity {
	Button b,br1;
	EditText et,pass;
	TextView tv;
	HttpPost httppost;
	StringBuffer buffer;
	HttpResponse response;
	HttpClient httpclient;
	List<NameValuePair> nameValuePairs;
	ProgressDialog dialog = null;
	String status;
	String uid;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment1);
        b = (Button)findViewById(R.id.Button01);  
        et = (EditText)findViewById(R.id.accountno);
        pass= (EditText)findViewById(R.id.password);
       // tv = (TextView)findViewById(R.id.tv);
        
        b.setOnClickListener(new OnClickListener() {
        	
           
			@Override
			public void onClick(View v) {
				
				dialog = ProgressDialog.show(Payment1Activity.this, "", 
                        "Validating user...", true);
				 new Thread(new Runnable() {
					    public void run() {
					    	payment();					      
					    }
					  }).start();				
			}
		});
    }
	
	void payment(){
		try{			
			 
			httpclient=new DefaultHttpClient();
			httppost= new HttpPost("http://tanushreedutta.site40.net/payment_new/check.php"); // make sure the url is correct.
			//add your data
			nameValuePairs = new ArrayList<NameValuePair>(2);
			// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
			nameValuePairs.add(new BasicNameValuePair("accno",et.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
			nameValuePairs.add(new BasicNameValuePair("bpassword",pass.getText().toString().trim())); 
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			//Execute HTTP Post Request
			response=httpclient.execute(httppost);
			ResponseHandler<String> responseHandler = new BasicResponseHandler();
			final String response = httpclient.execute(httppost, responseHandler);
			//System.out.println("Response : " + response); 
			runOnUiThread(new Runnable() {
			    public void run() {
			    	//tv.setText("Response from PHP : " + response);
				dialog.dismiss();
			    }
			});
			
			if(response.startsWith("User Found")){
				new Thread(new Runnable() {
				    public void run() {
				    	 
				    	update();					      
				    }
					
				  }).start();	
			
				runOnUiThread(new Runnable() {
				    public void run() {
				    	
				    	Toast.makeText(Payment1Activity.this,"Payment Successful for block 1", Toast.LENGTH_SHORT).show();
				    	Toast.makeText(Payment1Activity.this,"You reserved block 1",Toast.LENGTH_LONG).show();
				    	
                    setResult(1); 
				    }
				});
				startActivity(new Intent (Payment1Activity.this,VacatingCredentials.class));
				 
				
			}else{
				showAlert();		
			}
			
		}catch(Exception e){
			dialog.dismiss();
			System.out.println("Exception : " + e.getMessage());
		}
	}
	 public void update()
	    {
	    	try
	    	{
	    		uid="1";
				status="2";
			HttpClient httpclient = new DefaultHttpClient();
		        HttpPost httppost = new HttpPost("http://tanushreedutta.site40.net/map/map.php");
		        nameValuePairs = new ArrayList<NameValuePair>(2);
		        
		       	nameValuePairs.add(new BasicNameValuePair("uid",uid));
		       	nameValuePairs.add(new BasicNameValuePair("status",status));
		        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		        response = httpclient.execute(httppost); 
		        ResponseHandler<String> responseHandler = new BasicResponseHandler();
				final String response = httpclient.execute(httppost, responseHandler);
		       // HttpEntity entity = response.getEntity();
		       // is = entity.getContent();
		        Log.e("pass 1", "connection success ");
	    	}
	        catch(Exception e)
	    	{
	        	Log.e("Fail 1", e.toString());
		    	Toast.makeText(getApplicationContext(), "Invalid IP Address",
				Toast.LENGTH_LONG).show();
	    	}     
	    }
	public void showAlert(){
		Payment1Activity.this.runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(Payment1Activity.this);
		    	builder.setTitle("Payment Error.");
		    	builder.setMessage("User not Found.")  
		    	       .setCancelable(false)
		    	       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
		    	           public void onClick(DialogInterface dialog, int id) {
		    	        	   Toast.makeText(Payment1Activity.this,"Invalid Account number or Password,Try Again",Toast.LENGTH_LONG).show();
		    	        	    }
		    	       });		    	       
		    	AlertDialog alert = builder.create();
		    	alert.show();		    	
		    }
		});
	}
	
}





I am storing 1000 Rs in database as soon as the user registers with the system. Now what I want to implement is, as soon as the payment is successful it should deduct 100 Rs. from the users account (virtually) and send an sms stating \"Deducted 100 Rs. Balance is 900\" to the mobile no which a user had given during registration. Again if he tries to reserve another place then it should deduct 100 from 900 and so on. Can anyone help me with this ? Any suggestions or advices will be highly appreciated. Thank You.



I am storing 1000 Rs in database as soon as the user registers with the system. Now what I want to implement is, as soon as the payment is successful it should deduct 100 Rs. from the users account (virtually) and send an sms stating "Deducted 100 Rs. Balance is 900" to the mobile no which a user had given during registration. Again if he tries to reserve another place then it should deduct 100 from 900 and so on. Can anyone help me with this ? Any suggestions or advices will be highly appreciated. Thank You.

推荐答案

Edittext_value =
Edittext_value =


_POST['Edittext_value'];
\t\t\tnameValuePairs.add(new BasicNameValuePair(\"bpassword\",pass.getText().toString().trim()));
\t\t\thttppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
\t\t\t//Execute HTTP Post Request
\t\t\tresponse=httpclient.execute(httppost);
ResponseHandler< String> responseHandler = new BasicResponseHandler();
\t\t\tfinal String response = httpclient.execute(httppost, responseHandler);
\t\t\t//System.out.println(\"Response : \" + response);
\t\t\trunOnUiThread(new Runnable() {
\t\t\t public void run() {
\t\t\t \t//tv.setText(\"Response from PHP : \" + response);
\t\t\t\tdialog.dismiss();
\t\t\t }
\t\t\t});
\t\t\t
\t\t\tif(response.startsWith(\"User Found\")){
\t\t\t\tnew Thread(new Runnable() {
\t\t\t\t public void run() {
\t\t\t\t \t
\t\t\t\t \tupdate();\t\t\t\t\t
\t\t\t\t }
\t\t\t\t\t
\t\t\t\t }).start();
\t\t\t
\t\t\t\trunOnUiThread(new Runnable() {
\t\t\t\t public void run() {
\t\t\t\t \t
\t\t\t\t \tToast.makeText(Payment1Activity.this,\"Payment Successful for block 1\", Toast.LENGTH_SHORT).show();
\t\t\t\t \tToast.makeText(Payment1Activity.this,\"You reserved block 1\",Toast.LENGTH_LONG).show();
\t\t\t\t \t
setResult(1);
\t\t\t\t }
\t\t\t\t});
\t\t\t\tstartActivity(new Intent (Payment1Activity.this,VacatingCredentials.class));
\t\t\t\t
\t\t\t\t
\t\t\t}else{
\t\t\t\tshowAlert();
\t\t\t}
\t\t\t
\t\t}catch(Exception e){
\t\t\tdialog.dismiss();
\t\t\tSystem.out.println(\"Exception : \" + e.getMessage());
\t\t}
\t}
\t public void update()
\t {
\t \ttry
\t \t{
\t \t\tuid=\"1\";
\t\t\t\tstatus=\"2\";
\t\t\tHttpClient httpclient = new DefaultHttpClient();
\t\t HttpPost httppost = new HttpPost(\"http://tanushreedutta.site40.net/map/map.php\");
\t\t nameValuePairs = new ArrayList<NameValuePair>(2);
\t\t
\t\t \tnameValuePairs.add(new BasicNameValuePair(\"uid\",uid));
\t\t \tnameValuePairs.add(new BasicNameValuePair(\"status\",status));
\t\t httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
\t\t response = httpclient.execute(httppost);
\t\t ResponseHandler<String> responseHandler = new BasicResponseHandler();
\t\t\t\tfinal String response = httpclient.execute(httppost, responseHandler);
\t\t // HttpEntity entity = response.getEntity();
\t\t // is = entity.getContent();
\t\t Log.e(\"pass 1\", \"connection success \");
\t \t}
\t catch(Exception e)
\t \t{
\t \tLog.e(\"Fail 1\", e.toString());
\t\t \tToast.makeText(getApplicationContext(), \"Invalid IP Address\",
\t\t\t\tToast.LENGTH_LONG).show();
\t \t}
\t }
\tpublic void showAlert(){
\t\tPayment1Activity.this.runOnUiThread(new Runnable() {
\t\t public void run() {
\t\t \tAlertDialog.Builder builder = new AlertDialog.Builder(Payment1Activity.this);
\t\t \tbuilder.setTitle(\"Payment Error.\");
\t\t \tbuilder.setMessage(\"User not Found.\")
\t\t \t .setCancelable(false)
\t\t \t .setPositiveButton(\"OK\", new DialogInterface.OnClickListener() {
\t\t \t public void onClick(DialogInterface dialog, int id) {
\t\t \t \t Toast.makeText(Payment1Activity.this,\"Invalid Account number or Password,Try Again\",Toast.LENGTH_LONG).show();
\t\t \t \t }
\t\t \t });
\t\t \tAlertDialog alert = builder.create();
\t\t \talert.show();
\t\t }
\t\t});
\t}
\t
}
_POST['Edittext_value']; nameValuePairs.add(new BasicNameValuePair("bpassword",pass.getText().toString().trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); //Execute HTTP Post Request response=httpclient.execute(httppost); ResponseHandler<String> responseHandler = new BasicResponseHandler(); final String response = httpclient.execute(httppost, responseHandler); //System.out.println("Response : " + response); runOnUiThread(new Runnable() { public void run() { //tv.setText("Response from PHP : " + response); dialog.dismiss(); } }); if(response.startsWith("User Found")){ new Thread(new Runnable() { public void run() { update(); } }).start(); runOnUiThread(new Runnable() { public void run() { Toast.makeText(Payment1Activity.this,"Payment Successful for block 1", Toast.LENGTH_SHORT).show(); Toast.makeText(Payment1Activity.this,"You reserved block 1",Toast.LENGTH_LONG).show(); setResult(1); } }); startActivity(new Intent (Payment1Activity.this,VacatingCredentials.class)); }else{ showAlert(); } }catch(Exception e){ dialog.dismiss(); System.out.println("Exception : " + e.getMessage()); } } public void update() { try { uid="1"; status="2"; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://tanushreedutta.site40.net/map/map.php"); nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("uid",uid)); nameValuePairs.add(new BasicNameValuePair("status",status)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); response = httpclient.execute(httppost); ResponseHandler<String> responseHandler = new BasicResponseHandler(); final String response = httpclient.execute(httppost, responseHandler); // HttpEntity entity = response.getEntity(); // is = entity.getContent(); Log.e("pass 1", "connection success "); } catch(Exception e) { Log.e("Fail 1", e.toString()); Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_LONG).show(); } } public void showAlert(){ Payment1Activity.this.runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(Payment1Activity.this); builder.setTitle("Payment Error."); builder.setMessage("User not Found.") .setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(Payment1Activity.this,"Invalid Account number or Password,Try Again",Toast.LENGTH_LONG).show(); } }); AlertDialog alert = builder.create(); alert.show(); } }); } }





I am storing 1000 Rs in database as soon as the user registers with the system. Now what I want to implement is, as soon as the payment is successful it should deduct 100 Rs. from the users account (virtually) and send an sms stating \"Deducted 100 Rs. Balance is 900\" to the mobile no which a user had given during registration. Again if he tries to reserve another place then it should deduct 100 from 900 and so on. Can anyone help me with this ? Any suggestions or advices will be highly appreciated. Thank You.



I am storing 1000 Rs in database as soon as the user registers with the system. Now what I want to implement is, as soon as the payment is successful it should deduct 100 Rs. from the users account (virtually) and send an sms stating "Deducted 100 Rs. Balance is 900" to the mobile no which a user had given during registration. Again if he tries to reserve another place then it should deduct 100 from 900 and so on. Can anyone help me with this ? Any suggestions or advices will be highly appreciated. Thank You.


Why send SMS when you can send notifications for free?



http://developer.android.com/guide/topics/ui/notifiers/notifications.html[^]
Why send SMS when you can send notifications for free?

http://developer.android.com/guide/topics/ui/notifiers/notifications.html[^]


这篇关于如何发送短信,就像我的Android应用程序在银行完成金钱交易后发送的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆