Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a little support for Android Oreo #102

Merged
merged 1 commit into from
Nov 6, 2018

Conversation

slash-84
Copy link
Contributor

No description provided.

@emilyfeder
Copy link

emilyfeder commented May 9, 2018

I believe that each notification channel can only have one configuration for sound + importance so that if your push has a custom sound it will not use that -- it will only play the sound used for the first push sent on that channel. In your changes, you are not setting the sound for the channel, so I'm guessing it plays the default sound. Did you see that behavior in your tests?
See comments on this issue: https://stackoverflow.com/a/46120056/2872106

@slash-84
Copy link
Contributor Author

@emilyfeder i did not try, this is a very little support just for having notifications shown on Oreo (see #97 ) and i have not considered custom sound at all.

At the moment this PR add support just for one channel: you can only specify its name via tiapp.xml

It would be nice to completely support Oreo, with multiple channel handling and so on :)

@SeanMaraj
Copy link

Does this solution actually work when targeting API 26 and running on an Android 8 device? The channel implementation here seems fine but the BroadcastReceiver is still using "startWakefulService" which is no longer supported when you target 26 due to the new background restrictions. So in theory the service would never be started.

@miniman42
Copy link

@SeanMaraj Doesn't look like the notifications are received if the service is not actually running :/ Did you have any luck finding a solution?

@SeanMaraj
Copy link

@miniman42 I'm currently migrating to Firebase using this module: https://github.com/hansemannn/titanium-firebase-cloud-messaging
It uses the new Firebase services which work with the new target.

Alternatively, if you want to use continue to use this Goosh module, you'll have to compile it yourself and be sure to use "startForegroundService" instead of "startWakefulService". I did that and the service started fine. Unfortunately, I was having some trouble getting the actual notification to display properly. So that's when I decided to use the new Firebase module from Hans. It's more work to set up but Firebase seems pretty worth it.

@miniman42
Copy link

@SeanMaraj Thanks for the info - I'm on a similar mission to upgrade to FCM and API level 26, we've already a fairly heavily customised version of ti.goosh :)
I'll take a look at Hans module. I'm just concerned, as a foreground service is out for us. I want to ensure that a visible notification gets posted when the app is not running in the background. Hopefully there's something new in FCM that allows that? As that is why we needed the broadcast receiver up till now. Maybe I'm missing something!

@SeanMaraj
Copy link

@slash-84 So Hans' module by default doesn't really let you show a notification when the app is closed (unless i'm missing something). But I'm literally working on that feature right now for my app. You just have to build and show your notification in the "onMessageReceived" function in TiFirebaseMessagingService.java. No extra service is required from what I can tell.

@miniman42
Copy link

Ahh yes, just took a peek at the doc's there https://developers.google.com/cloud-messaging/android/android-migrate-fcm - I'll have a go at updating my goosh to use FCM directly, looks pretty trivial #famouslastwords

@emilyfeder
Copy link

I ended up using the module you mentioned: https://github.com/hansemannn/titanium-firebase-cloud-messaging in my app.
It did indeed have all the features I needed, including playing specific sounds for notification channels that are part of API 26, and push notifications still appear even when the app is in the background. When the app is closed, the push notification is handled by android's native fcm support, and when you click on the notification, it opens your app and any extras are part of Ti.App.Android.launchIntent.

@DFoxinator
Copy link
Contributor

@emilyfeder did you have to do anything special with titanium-firebase-cloud-messaging to get notifications to work from the background? No matter what I do, I can't get the data to show up in Ti.App.Android.launchIntent getExtra methods. It seems to just not have access to the data that was in the payload of the notif. I also tried Ti.Android.currentActivity but the data wasn't there either. Any help is appreciated, I'm hoping to learn how you got it going.

@emilyfeder
Copy link

emilyfeder commented Aug 30, 2018 via email

@DFoxinator
Copy link
Contributor

@emilyfeder thanks for the info. That's what I was trying, but it doesn't seem to work. I confirmed the data was coming through because the notification and data are successfully received if the app is in the foreground. But once in the background, the notification is received but when you navigate to the app via the notif, the data isn't showing up anywhere. It's definitely a notif + data, and works in the foreground, so not sure if I'm doing something wrong or this some kind of issue. But the data doesn't seem to be present on any of the activity/intents.

@emilyfeder
Copy link

Are you using the firebase console to send test messages so that you can eliminate any issues you may have in your push server? They have 'advanced' message options where you can set the data payload.
Also, here's what my code looked like on the app side to grab the extra:
Ti.App.Android.launchIntent.getStringExtra(key). I'm not sure beyond that what the issue may be, so I would suggest looking through the issues raised in the https://github.com/hansemannn/titanium-firebase-cloud-messaging repo.

@DFoxinator
Copy link
Contributor

@emilyfeder thank you. I will try sending from the console. Two more questions if you don't mind - where in your app are you calling Ti.App.Android.launchIntent.getStringExtra? (I've tried numerous places, but no luck. ex. the initial window open even handler, before initial window open, etc.) I'm wondering if I'm calling it too late in the lifecycle or maybe just the wrong place, to have it not be there at the point I'm looking for it. Also, what version of the Titanium SDK are you using? I tried with various 7.x builds but no luck.

@RavindraChherke
Copy link

@DFoxinator

In the classic Titanium app I am getting data from intent in app.js I think for alloy app you will get it in index.js

var _intent = Ti.App.Android.launchIntent;
var chat_id = _intent.getStringExtra("chat_id");

I think your problem is related to payload. Don't forget to make necessary changes on server side. There are two section in notification payload.

  1. notifcation
  2. data
{
     data:{
        chat_id:mychat_id
      },
     notification: {
        title:mytitle,
        body: message,
      }
 }

Please check server code given by Hans on
https://github.com/hansemannn/titanium-firebase-cloud-messaging

<?php
    $url = 'https://fcm.googleapis.com/fcm/send';

    $fields = [
        'to' => '/topics/testTopic', // or device token
        'notification' => [
            'title' => 'TiFirebaseMessaging',
            'body' => 'Message received'
        ],
        'data' => [
            'key1' => 'value1',
            'key2' => 'value2'
        ]
    ];

    $headers = [
        'Authorization: key=SERVER_ID_FROM_FIREBASE_SETTIGNS_CLOUD_MESSAGING', 'Content-Type: application/json'
    ];
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    $result = curl_exec($ch);

    echo $result;
    curl_close($ch);
?>

@DFoxinator
Copy link
Contributor

@RavindraChherke thanks for all of the info. I am using a classic app so I have my code in app.js. I tried that code, but unfortunately, no luck. I can see the data is coming through properly, because it works if the app is in the foreground when the notif is received (didReceiveMessage) I'm able to see the passed along data. But unfortunately, when the app is backgrounded, no matter what I've tried I can't seem to get it to find any data on the intent.

@Jei Jei merged commit d34142c into caffeinalab:master Nov 6, 2018
@Jei
Copy link
Contributor

Jei commented Nov 6, 2018

We're merging this solution for now, as a starting point. We need to address the biggest problems first, and then implement a more comprehensive solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants