17

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/Skype when there is incoming call, its ringing. Or would it be possible to cause the phone to play a looping alarm sound on Push Notification.

Another very clear example is "Find My iPhone" app which can trigger a loud alarm to an iPhone.

How can I achieve this programmatically on ios and android ?

Axil
  • 2,835
  • 5
  • 43
  • 97
  • Is the trigger location based (geo-fence) ? Depends what type of app you want to develop but background operations are pretty restricted. VoIP apps usually use PushKit which allows to respond to notifications (APNs + background mode is also an option). You can check the types of background modes in the `Capabilities` pane > `Background Modes`. There's a [30sec](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW10) limit on custom PN sounds – nathan Jul 24 '17 at 00:13
  • its an alert application, somewhat like a panic button. https://developer.apple.com/documentation/pushkit is for VoIP, you think this would be allowed ? how do you think you propose to do this alert buzzer ? normal push notification is not good enough. How about Android, any solution there ? – Axil Jul 24 '17 at 01:41
  • No, PushKit is only for VoIP apps. You should create a separate question for Android I think. It's too broad otherwise (unless you are using React Native, Cordova, etc.) I'm not sure if you can or if Apple would allow such usage. Have you seen similar apps in the AppStore ? – nathan Jul 24 '17 at 02:04
  • Well we can narrow it down to jusy iOS first if you wish. Ideally I'm trying to find for ionic or both ios&android. Well one example is "Find My iPhone" app. We can trigger an alarm on that phone. Anyway this is made by Apple. But is there a way to do something similar ? – Axil Jul 24 '17 at 14:08
  • Can you use azure? https://azure.microsoft.com/en-us/services/notification-hubs/ – stephan14x Jul 26 '17 at 06:06
  • there is alot of notification services. currently im using onesignal. I am not clear whether it can create a loud repetitive alarm audio. And something separate from the normal push notification sound. Can you clarify in detail how it can be done ? – Axil Jul 26 '17 at 06:08

3 Answers3

4

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.

Don Chakkappan
  • 6,872
  • 5
  • 41
  • 54
  • sure, i'ved been also able to receive notification when application is in idle. the issue is whether you can create a strong alarm sound that is repetitive. – Axil Jul 31 '17 at 02:59
  • no. push is fine but it wont generate an alarm that kind of thing. are you able to demonstrate how to do so ? – Axil Jul 31 '17 at 03:02
  • Ok.Let me check – Don Chakkappan Jul 31 '17 at 03:04
  • thank you. Use "Find My iPhone" as a reference. how do we accomplish this. – Axil Jul 31 '17 at 03:04
  • here something i have found. but i think its possible using some tricks. https://stackoverflow.com/questions/38297790/ionic-how-to-create-an-alarm-notification-similar-to-incoming-call-or-clock-al?rq=1 – Axil Jul 31 '17 at 03:05
  • are you able to verify that it will execute that code when app is closed ? can you show me the documentation for handleIntent. thanks. – Axil Jul 31 '17 at 04:36
  • @Axil I tested in both emulator & real device.Its working fine. – Don Chakkappan Jul 31 '17 at 04:45
3

1 possible solution could be schedule alarm event with repeatInterval on receiving push notification.

EDIT We can create custom notifications using Notification extensions.They are called as soon as notification arrives & we can present customized view with image/video downloading. So you can try there to schedule events.

Ellen
  • 5,232
  • 1
  • 10
  • 16
  • how to schedule ? the push is just a push. only when user select the notification then only it can enter the app and then only its able to do something like schedule alarm. So, no way to do like "Find My iPhone" app alarm trigger – Axil Jul 31 '17 at 03:02
2

For iOS, you will need a server to deliver a push notification to your app, where the notification references a custom audio alert to be played. The audio alert has to be included within the app's bundle as stated in Apple docs.

This alert can't be longer than 30 seconds. If you want the alert to be played longer, you can send send another push notification times roughly 30-seconds after and stop sending the alert when a) user open the app or b) you've reached the maximum threshold.

It's generally not good practise to send multiple notification containing the same payload, unless there is a good reason.

I would suggest splitting up this question into two: one for iOS, and another for Android.

Kashif Shaikh
  • 81
  • 1
  • 3