hansemannn / titanium-firebase-cloud-messaging

Use the Firebase Cloud Messaging SDK in Axway Titanium 🚀 Edit
Other
43 stars 31 forks source link

Click on message restarts app #91

Closed tomjakobs1 closed 5 years ago

tomjakobs1 commented 5 years ago

For Android

Getting the push message, but when i click on it, the app restarts.

Any solutions?

Thanks

Tom

tomjakobs1 commented 5 years ago

SDK 8.1.1 GA

m1ga commented 5 years ago

works fine in my tests: http://migaweb.de/ti_push.mp4 If the app is in background it will come just come into foreground. if it is closed it will restart of course.

More information is needed, some code or demo project. But for me it doesn't look like a bug in the module

tomjakobs1 commented 5 years ago

Thanks for your reply

I have foreground services with notification that is working just fine. (it resumes that app when clicked on message), but clicking on push notification just kills the app, or restarts it. It also says : FirebaseMessaging: Unable to log event: analytics library is missing.

Im using the following versions: Titanium SDK 8.1.1 ti.playservices v: 16.1.3 firebase core v:5.0 firebase cloudmessaging v 2.01 firebase analytics v 3.0.0

Btw when i launch my foreground notifications i have an intent. (Ti.App.Android.launchIntent). Is there a way to set the intent when launching notifications from firebase

Thanks a lot for your help

Here is my code:

var core = require('firebase.core');
    core.configure({
     file : "google-services.json"
});
var fcm = require('firebase.cloudmessaging');
    // Called when the Firebase token is ready
    fcm.addEventListener('didRefreshRegistrationToken', onToken);

    // Called when direct messages arrive. Note that these are different from push notifications
    //fcm.addEventListener('didReceiveMessage', onMessage);

    function onToken(e) {
        Ti.API.info('Token is ready', e.fcmToken);
    }

    function onMessage(e) {
        Ti.API.info('GOT A DIRECTMESSAGE');
    }

    // Android: For configuring custom sounds and importance for the generated system 
    // notifications when app is in the background

    var channel = Ti.Android.NotificationManager.createNotificationChannel({
        id : 'TESTER,
        name : 'TESTER',
        importance : Ti.Android.IMPORTANCE_DEFAULT,
        enableLights : true,
        enableVibration : true,
        showBadge : true,     
    lockscreenVisibility : Titanium.Android.VISIBILITY_PUBLIC
    });
    fcm.notificationChannel = channel;

    fcm.registerForPushNotifications();

    // check if token is already available
    if (fcm.fcmToken !== null) {
        Ti.API.info('FCM-Token', fcm.fcmToken);
    } else {
        Ti.API.info('Token is empty. Waiting for the token callback ...');
    }

    // subscribe to topic
    fcm.subscribeToTopic('testTopic');
m1ga commented 5 years ago

working fine here. Android 7 (HTC A9), Android 8 (Samsung A5). When the app is in background (home button, not back button) it just comes to foreground. Pressing the back button (closing the app) will restart it when clicking the notification.

did you set anything special inside your tiapp.xml application tag?

tomjakobs1 commented 5 years ago

Hello again. Im trying on a Android 9 phone. Dont know if it could make a difference.

Here application tag code from my tiapp.xml (containts some analytics services also) s

           <application android:theme="@style/Theme.NoActionBar">
            <meta-data android:name="com.google.android.geo.API_KEY"
                android:value="xxx"/>

            <service
                android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService"/>
            <service android:enabled="true" android:exported="false"
                android:name="com.google.android.gms.measurement.AppMeasurementJobService" android:permission="android.permission.BIND_JOB_SERVICE"/>
            <service android:exported="false" android:name="com.company.myapp.gcm.RegistrationIntentService"/>
            <receiver android:enabled="true" android:name="com.google.android.gms.measurement.AppMeasurementReceiver">
                <intent-filter>
                    <action android:name="com.google.android.gms.measurement.UPLOAD"/>
                </intent-filter>
            </receiver>
            <!-- Only add the GCM-related tags if you are using push notifications as well -->
            <service android:exported="false" android:name="com.company.myapp.gcm.GcmIntentService">
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                </intent-filter>
            </service>
            <service android:exported="false" android:name="com.company.myapp.gcm.GcmIntentService">
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.SEND"/>
                </intent-filter>
            </service>
            <service android:exported="false" android:name="com.company.myapp.gcm.GcmIDListenerService">
                <intent-filter>
                    <action android:name="com.google.android.gms.iid.InstanceID"/>
                </intent-filter>

            </service>

            <service android:name="com.google.firebase.components.ComponentDiscoveryService">
                <meta-data
                    android:name="com.google.firebase.components:com.google.firebase.iid.Registrar" android:value="com.google.firebase.components.ComponentRegistrar"/>
            </service>
        </application>``
tomjakobs1 commented 5 years ago

Here is from the console: (I have an eventlistener that listen for app close. This stops foreground services that is running if the app is closed. If you see in the console output it looks like the close event is fired.)

[WARN] : FirebaseMessaging: Unable to log event: analytics library is missing [DEBUG] : Window: Window is closed normally.

[DEBUG] : InputTransport: Input channel destroyed: fd=76 [INFO] : I/System.out: (HTTPLog)-Static: isSBSettingEnabled false [INFO] : I/System.out: (HTTPLog)-Static: isSBSettingEnabled false [DEBUG] : NetworkManagementSocketTagger: tagSocket(76) with statsTag=0xffffffff, statsUid=-1 [INFO] : Stopping neworderalertsintent [INFO] : Stopping newmessagesalertsintent [INFO] : Stopping syncdataintent [INFO] : Stopping uploadmessagesintent [INFO] : Stopping uploaderintent [INFO] : Stopping dozerintent [INFO] : Stopping getcurrentlocationintent [DEBUG] : Window: Window is closed normally.

[DEBUG] : InputTransport: Input channel destroyed: fd=91

[DEBUG] : InputTransport: Input channel destroyed: fd=63 [WARN] : ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@9e29b94 [INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null [INFO] : MultiWindowDecorSupport: updateCaptionType >> com.android.internal.policy.MultiWindowDecorSupport@87f4939, isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true [DEBUG] : MultiWindowDecorSupport: setCaptionType = 0 [WARN] : ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@9b44c18 [INFO] : TiActivity: (main) [114,114] Launching with 'org.appcelerator.titanium.TiActivity' is not allowed. Closing activity. [INFO] : MultiWindowDecorSupport: updateCaptionType >> com.android.internal.policy.MultiWindowDecorSupport@61f78ad, isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true [DEBUG] : MultiWindowDecorSupport: setCaptionType = 0 [WARN] : V8Object: (main) [152,266] Runtime disposed, cannot fire event 'disposehandle'

tomjakobs1 commented 5 years ago

Also i get this in the console when receiving message: [WARN] : FirebaseMessaging: Unable to log event: analytics library is missing [WARN] : FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

m1ga commented 5 years ago

[DEBUG] : Window: Window is closed normally. so you've pressed the back button on your phone? If so this is the normal behavior. If I press the home button there won't be any log because the app is still running. This could also mean that the system closed the app in background if you exitOnClose: false is set

m1ga commented 5 years ago

Also your demo code and the error messages don't match. There is no analytics in the demo code

var fc = require('firebase.core');
var fa = require('firebase.analytics');
var fcm = require('firebase.cloudmessaging');

and then you can use

fa.log('My_Event', { /* Optional arguments */ });

and those are just warnings which can be ignored if you don't want to use it. If so, just add

<meta-data android:name="firebase_analytics_collection_enabled" android:value="false"/>
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false"/>

to the application block

tomjakobs1 commented 5 years ago

I push the home button, so that the app is active in the background. Im using a foreground service with notification to try to keep the apps network alive while in background. If i click that notification the app resume like intended. But clicking the notification from firebase the app just closes. (with the splash image flickering a couple of times)

tomjakobs1 commented 5 years ago

The demo code only has the firebase messaging. I have the analytics code in the app.js

m1ga commented 5 years ago

what kind of notification are you sending? if it is a normal notification message than the phone is handling the notification. If it is a data message the notification is created here: https://github.com/hansemannn/titanium-firebase-cloud-messaging/blob/master/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java#L162 and you could try to change those values.

tomjakobs1 commented 5 years ago

Im just testing directly from the https://console.firebase.google.com/ Seems like its only one method of sending messages here.

tomjakobs1 commented 5 years ago

Took a while. But got it now. It was the difference with a notification message and a data message that i did not understand. Removing "notification" from data body that i sendt, made it always use data message, and now it seems to work as expected.

Note: using notification payload it seems like it always is running the code from the phone and hence it always will restart the app.

Thanks for your patience and help.