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) {
}
}
}