Android send SMS automatically on button click

后端 未结 5 1665
孤独总比滥情好
孤独总比滥情好 2020-12-24 04:01

I am trying to automatically send SMS message to a certain number when the user presses a button on the screen.

This is my code:

Intent smsIntent = n         


        
5条回答
  •  醉话见心
    2020-12-24 04:37

    Try this

    private static final String SMS_SENT_INTENT_FILTER = "com.yourapp.sms_send";
    private static final String SMS_DELIVERED_INTENT_FILTER = "com.yourapp.sms_delivered";
    
    String message = "hey, this is my message";
    
    String phnNo = " " //preferable use complete international number
    
    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
                    SMS_SENT_INTENT_FILTER), 0);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(
                    SMS_DELIVERED_INTENT_FILTER), 0);
    
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phnNo, null, message, sentPI, deliveredPI);
    

提交回复
热议问题