Create an (repetitive high pitch) Alarm on a remote trigger when App is not running (iphone/android) just like Find My iPhone

前端 未结 3 1710
萌比男神i
萌比男神i 2020-12-18 20:03

I would like to cause an alarm on a remote iphone/android device when the app is running or not running.

How do I achieve it ?

I can only think of Whatsapp/S

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 20:53

    Its possible using FireBase Notification Services with JobService & FirebaseMessagingService.

    • Download the FireBase samples from here .Run module "messaging".I tested it and I was able to receive the notification , even in the Application killed state.

    • To manage events periodically/scheduled you must implement & deploy your Server somewhere.You can also check FireBase Functions (Beta) to easily implement Server.

    • To show something (Alaram/UI like calling screen) to user start your custom Activity while receiving FireBase notification.Override handleIntent from FirebaseMessagingService.So that you can receive data from your killed/idle Application.

    • FireBase Service is System Service & it will be always running.Please have a read.

      Code snippet

      @Override
      public void handleIntent(Intent intent) {
          super.handleIntent(intent);
          // Get Data here
          Log.d(TAG, "intent.."+intent.getExtras());
          Intent intent1=new Intent(this,MainActivity.class);
          intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(intent1);
      }
      

    Note : Some devices (Eg; ASUS's Mobile Manager) may reject to start Application's receiver while , Notification arrives.In that case please provide appropriate permissions.

提交回复
热议问题