0

I have integrated FCM (Firebase Cloud Messaging) in my android mobile app. I want to restart the android device(rooted) when a notification is received to device through FCM. But when I restart the device using following code, the device restarts and again it restarts automatically(though I didn't send the notification). Why this happens? How can I solve this?

Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot now"});

I send POST request to https://fcm.googleapis.com/fcm/send url as mentioed in right answer of this question.

My Code is as follows

    public class MyFirebaseMessagingService extends FirebaseMessagingService {
            String restart = "restart";
            String take_screenshot = "take_Screenshot";

            @Override
            public void onMessageReceived(RemoteMessage remoteMessage) {
                Map<String, String> data = remoteMessage.getData();
                final String myCustomKey = data.get("my_custom_key");
                reboot();
            }
            private void reboot() {
                try {
                    Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot now"});
                } catch (IOException e) {
                }
            }
}
AL.
  • 36,815
  • 10
  • 142
  • 281
Krishan Madushanka
  • 319
  • 1
  • 5
  • 21

1 Answers1

0

I suspect that restarting the device too quickly doesn't allow FCM to store the information that it received the message.

Therefore when the device restart the message is downloaded (and delivered to the app again).

I suggest to add few seconds of delay before the reboot.

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50