当应用程序被关闭通知不来通过 [英] Notifications don't come through when the app is closed

查看:133
本文介绍了当应用程序被关闭通知不来通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与设置使用城市飞艇推送通知的Andr​​oid应用程序。该通知的正常工作,而我的应用程序是开放的,但我需要仍然收到通知时,我的应用程序被关闭。我环顾四周,但没有发现一些作品。我是pretty的确定问题出在我的表现,所以在这儿呢。

I've got an Android app with push notifications set up using Urban Airship. The notifications work fine while my app is open but I need to still receive notifications when my app is closed. I've looked around but haven't found something that works. I'm pretty sure the problem is in my manifest, so here it is.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="za.co.foo.android.financials"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

    <!-- Permissions for Urban Airship -->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <!-- Not sure if required for C2DM -->
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <!-- Only this application can receive the messages and registration result -->
    <permission android:name="za.co.foo.android.financials.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="za.co.foo.android.financials.permission.C2D_MESSAGE" />

    <!-- This app has permission to register and receive message -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".InvestorRelations"
            android:label="@string/app_name" 
            android:screenOrientation="landscape" 
            android:theme="@android:style/Theme.Holo.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- For Urban Airship -->
        <receiver android:name="com.urbanairship.CoreReceiver">
        </receiver>

        <receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver"
                android:permission="com.google.android.c2dm.permission.SEND"
                android:enabled="true">
             <!-- Receive the actual message -->
             <intent-filter>
                 <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                 <category android:name="za.co.foo.android.financials" />
             </intent-filter>
             <!-- Receive the registration id -->
             <intent-filter>
                 <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                 <category android:name="za.co.foo.android.financials" />
             </intent-filter>
        </receiver>

        <receiver android:name="za.co.foo.android.financials.IntentReceiver" />

        <service android:name="com.urbanairship.push.PushService" />

    </application>

</manifest>

下面是我的 IntentReceiver

public class IntentReceiver extends BroadcastReceiver {

    private static final String logTag = "IR Intent Receiver";

    @Override
        public void onReceive(Context context, Intent intent) {
        Log.i(logTag, "Received intent: " + intent.toString());
        String action = intent.getAction();

        if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {
            int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);

            Log.i(logTag, "Received push notification. Alert: "
                    + intent.getStringExtra(PushManager.EXTRA_ALERT)
                    + " [NotificationID="+id+"]");

            logPushExtras(intent);

        } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
            Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));

            logPushExtras(intent);

            Intent launch = new Intent(Intent.ACTION_MAIN);
            launch.setClass(UAirship.shared().getApplicationContext(), InvestorRelations.class);
            launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            launch.putExtra("FromNotification", true);

            UAirship.shared().getApplicationContext().startActivity(launch);

        } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {
            Log.i(logTag, "Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID)
                    + ". Valid: " + intent.getBooleanExtra(PushManager.EXTRA_REGISTRATION_VALID, false));
        }

    }

    public void logPushExtras(intent) {
        //Does some logging stuff
    }
}

任何帮助将是巨大的。

Any help would be great

修改

附带仅为我公司名称的整个舱单变更为富。

Included the entire manifest with only my company name changed to "foo".

修改

事实证明,我的应用程序也同时关闭,但不经过强制关闭接收通知。阅读这个的问题后,已实现。

As it turns out, my app does receive notifications while closed, but not after a force-close. Realised after reading this question.

推荐答案

原来,通知运行良好的应用程序是否正在运行。问题是,当应用程序被强制关闭。

It turns out the notifications worked fine whether the app was running or not. The problem was when the app was force-closed.

我觉得实际的问题是沿的BroadcastReceiver的线条被杀害时,应用程序是力封闭的,但我不知道的东西。

I think the actual problem is something along the lines of the BroadcastReceiver being killed when the app is force closed but I'm not sure.

这是刚刚结束的问题了,因为它是不太可能,现在我意识到这个问题是不同的问题标题来解决。

This is just to close the question off because it's unlikely to be solved now that I realise the problem is different to the question title.

这篇关于当应用程序被关闭通知不来通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆