Thursday, June 25, 2015

Send SMS from Your Android Application

Use bellow code in Activity class in your own method
public void SendSMSRequest(View view) {
    String SendSMSNumber = "880xxxxxxxxxx";   
    String smsText = "Need Permission";
    String phoneNo = GetSMSNumber.toString();   
    String msg = smsText.toString();  
   try {
        SmsManager smsManager = SmsManager.getDefault();    
        smsManager.sendTextMessage(phoneNo, null, msg, null, null);     
        Toast.makeText(getApplicationContext(), "Message Sent",           
        Toast.LENGTH_LONG).show();    } catch (Exception ex) {
        Toast.makeText(getApplicationContext(),           
        ex.getMessage().toString(),               
        Toast.LENGTH_LONG).show();      
       ex.printStackTrace();    }
}


Use bellow code in XML 
   <Button android:layout_width="225dp"  
           android:layout_height="75dp"  
           android:text="Off Line Play"  
           android:id="@+id/button"    
           android:onClick="SendSMSRequest"
           android:textColor="#ffffff"  
           android:textStyle="bold"   
           android:textSize="21sp"  
           android:layout_above="@+id/subscribe"  
           android:layout_centerHorizontal="true"    />
Use permission in Androidmanifest
<!-- Permission:Sms Related access -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />

No comments:

Post a Comment