Android Send sms when app not running in background

Viewed 243

Is there any way to send sms using SmsManager without open the App. I am using FirebaseMessagingService and i got remoteMessage from onMessageReceived method its Contains Mobile No and Message. Then i am sending SMS using using SmsManager. and also i declared permission.SEND_SMS/RECEIVE_SMS in manifest file.

This is My Code:

public void onMessageReceived(RemoteMessage remoteMessage){

    String mobile = remoteMessage.getData().get("mobileno");
    String message = remoteMessage.getData().get("message");

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(mobile, null, message, null, null);
}

Its Working on when App is Running. but not working on when app is not running in background. Is there any way to SEND sms when App is not running.?? Please help me.. Thanks...

1 Answers
Related