freshplanet / ANE-Push-Notification

Air Native Extension (iOS and Android) for Push Notification
Apache License 2.0
205 stars 104 forks source link

App crashes after receiving push message #88

Open swarajcs opened 8 years ago

swarajcs commented 8 years ago

Hi,

am getting the message

[StatusEvent type="status" bubbles=false cancelable=false eventPhase=2 code="LOGGING" level="Received push notification with parameters: {"tickerText":"Test","collapse_key":"do_not_collapse","from":"xxxxxxxxxxxx","contentTitle":"Offer","contentText":"Testing"}"] Received push notification with parameters: {"tickerText":"Test","collapse_key":"do_not_collapse","from":"xxxxxxxxxxxx","contentTitle":"Offer","contentText":"Testing"}

but the app crashes after that. What could be the reason? Am using flash cs6 . How can I track the issue and fix it?

I have changed the build.config .

name=AirPushNotification useMultiMsg=false

flex.sdk=/path/to/your/flexsdk/folder bin.ext=

ios.sdkversion=iphoneos

android.sdk= D:\android_sdk_install\platforms\android-23 android.res= E:\efolder\test_android\ANE-Push-Notification-master(1)\ANE-Push-Notification-master\android\res\drawable-xhdpi

Just saved the path and do I have to make any changes or do anything for ane?

This is how I editted the xml file.

< uses-permission android:name="android.permission.INTERNET"/> < uses-permission android:name="android.permission.READ_PHONE_STATE"/> < uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> < uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> < uses-permission android:name="xxxxxxxxxxxxxxxxxxxxxxxxxx.permission.C2D_MESSAGE" android:protectionLevel="signature"/> < uses-permission android:name="xxxxxxxxxxxxxxxxxxxxxxxxxx.permission.C2D_MESSAGE" /> < uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> < application> < activity android:name="com.freshplanet.nativeExtensions.NotificationActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/> < receiver android:name="com.freshplanet.nativeExtensions.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> < intent-filter> < action android:name="com.google.android.c2dm.intent.RECEIVE"/> < category android:name="xxxxxxxxxxxxxxxxxxxxxxxxxx"/> < /intent-filter> < intent-filter> < action android:name="com.google.android.c2dm.intent.REGISTRATION"/> < category android:name="xxxxxxxxxxxxxxxxxxxxxxxxxx"/> < /intent-filter> </ receiver> < service android:name="com.freshplanet.nativeExtensions.LocalNotificationService"/> < receiver android:name="com.freshplanet.nativeExtensions.LocalBroadcastReceiver" android:process=":remote"/> < /application>

any bug in xml?

Please help. Hope I could get an option to how track the issues..

Thanks,

Laur3nt1u commented 8 years ago

I think it depends on what version of google play services you have, for me it crashed because of .setColor with google play services from lilili87222’s admob so I use admob without gps with my google play services (updated in december) and my fork for push notification

swarajcs commented 8 years ago

Some post says that the ios is working fine. So it could be any issue with changing config file? bcoz there is nothing to do with the ane in ios as per the documentation.

Laur3nt1u commented 8 years ago

your app crashes on ios or android?

swarajcs commented 8 years ago

Its in android.

Laur3nt1u commented 8 years ago

the android and ios code are different so a bug in one will not affect the other, to track the issue you can look at the logcat when the app get the notification and crashes to see what's wrong

swarajcs commented 8 years ago

Thank you,

I have checked using logcat. It is not showing the reason for app crash. It just displays the recieving message. I tried the debug using usb method. But not sure where to trace the details. I found an actionscript file in folder "PushNotification.as". If I tried to add a trace statement inside it, it wont be showing as I may need to recompile the ane. Am not sure how it is. :(

Laur3nt1u commented 8 years ago

post the logcat if you can

Jim-Robbins commented 8 years ago

swarajcs - Are you setup to compile the ANE yourself? If so try adding debug comments to the .java source. By having the android SDK installed you can run 'monitor' from the command line and see the DDMS logcat for the device. It will show you the full stack trace of your issue.

I was able to work around these issues in a fork of the code. It depends on what keys are being sent in your bundle. They are not doing a good job of checking for null values when building the notification. For example:

    // Notification texts
    CharSequence contentTitle = _intent.getStringExtra("contentTitle");
    if (contentTitle.length() > 22)
    {
        contentTitle = contentTitle.subSequence(0, 20) + "...";
    }
    CharSequence contentText = _intent.getStringExtra("contentText");
    CharSequence tickerText = _intent.getStringExtra("tickerText");

I found that my Push Notification service did not use "contentTitle" and "contentText" so the app would crash when trying to create the notification.

I had to run a check to see what the keys actually were: Bundle bundle = _intent.getExtras(); for (String key : bundle.keySet()) { Object value = bundle.get(key); Log.d(TAG, String.format("Key:%s Value:%s Type:(%s)", key, value.toString(), value.getClass().getName())); }

I was then able to handle the keys properly.

Same thing in the NotificationActivity.onCreate() they are assuming that: Bundle values = this.getIntent().getExtras(); always returns a value. In my case it is null, so I had to wrap that to bypass and allow the notification to open the app.

swarajcs commented 8 years ago

sorry. Am not sure about how to do that. is there anything wrong in my code? Do I have to recompile ane ? Or just to change the path in build.config?

skolesnyk commented 8 years ago

Does it mean that this ANE has to be adapted to particular Push Provider? I've recently switched from Parse to OneSignal. Trying to figure out how to adapt the ANE to fit my needs. OneSignal sends a push object wrapper in "custom" property holding JSON data, e.g.

"custom":"{ \"a\":{\"data1\":\"1\",\"data0\":\"0\"}, \"i\":\"ffb0c078-c1de-41a0-8e8f-195149436aea\"}", "o":"[{\"p\":\"buttonicon0\",\"i\":\"0\",\"n\":\"button0\"}, {\"p\":\"buttonicon1\",\"i\":\"1\",\"n\":\"button2\"}]", "bgac":"ff00ff","from":"335489973458","ledc":"fffff", "alert":"kk","bicon":"url:bigpic.jpg", "licon":"largeicon1","sicon":"smallicon1","sound":"sound1", "title":"ok","collapse_key":"do_not_collapse" }

Jim-Robbins commented 8 years ago

@swarajcs My suggestion was to modify the ANE to add some additional logging into the following classes:

In the onPostExecute(), I had to modify the string params coming in since they did not match what was hard coded into the ANE. My function ended up looking like this:

    @Override
    protected void onPostExecute(Boolean downloadSuccess)
    {
        if (_context == null || _intent == null)
        {
            Extension.log("Couldn't create push notification: _context or _intent was null (CreateNotificationTask.onPostExecute)");
            return;
        }

        Bundle bundle = _intent.getExtras();
        for (String key : bundle.keySet())
        {
            Object value = bundle.get(key);
            Log.d(TAG, String.format("Key:%s Value:%s Type:(%s)", key, value.toString(), value.getClass().getName()));
        }

        // Notification texts
        CharSequence contentTitle = _intent.getStringExtra("contentTitle");
        if (contentTitle != null)
        {
            if (contentTitle.length() > 22)
            {
                contentTitle = contentTitle.subSequence(0, 20) + "...";
            }
        }
        else
        {
            int stringId = _context.getApplicationInfo().labelRes;
            contentTitle = _context.getString(stringId);
        }

        CharSequence contentText = _intent.getStringExtra("contentText");
        if (contentText == null)
        {
            contentText = _intent.getStringExtra("message");
            if (contentText == null)
            {
                contentText = "Come back and play!";
            }
        }

        CharSequence tickerText = _intent.getStringExtra("tickerText");
        if (tickerText == null)
        {
            tickerText = _intent.getStringExtra("message");
            if (tickerText == null)
            {
                tickerText = contentText;
            }
        }
...

the rest didn't change

For me this little debug output helped me track down the differences in what my push services was sending vs what the ANE was expecting.

for (String key : bundle.keySet())
{
            Object value = bundle.get(key);
            Log.d(TAG, String.format("Key:%s Value:%s Type:(%s)", key, value.toString(), value.getClass().getName()));
}

@skolesnyk Looks like you are seeing the same thing, that the data being returned isn't in the expected format. I would expect you would need to also need to modify the intent parameters.

yokoboko commented 7 years ago

I fixed it. You can download ANE from here: https://www.dropbox.com/s/mvjgx0tg1cmz9e1/AirPushNotification.ane?dl=0

You should send: {"contentTitle":"Title..","contentText":"Message...","tickerText":"...","priority":"2"} *priority is optional(-2 <---> +2) ** it will not crash if you don't send all params

You will need AIR 25+

To change the icons: 1) Rename to .zip 2) Open with WinRar(don't extract!) 3) Drag and drop your icons to "\META-INF\ANE\Android-ARM\res\drawable-xhdpi" to replace files 4) Close WinRar and change file name back to .ane