android-关闭应用程序时不会收到通知

android-关闭应用程序时不会收到通知,第1张

概述我有一个Android应用,该应用使用UrbanAirship设置了推送通知.在我的应用程序打开时,通知工作正常,但是在我的应用程序关闭时,我仍然需要接收通知.我环顾四周,但未找到有效的方法.我很确定问题出在我的清单上,所以就在这里.<?xmlversion="1.0"encoding="utf-8"?><manifestxml

我有一个Android应用,该应用使用Urban Airship设置了推送通知.在我的应用程序打开时,通知工作正常,但是在我的应用程序关闭时,我仍然需要接收通知.我环顾四周,但未找到有效的方法.我很确定问题出在我的清单上,所以就在这里.

<?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    }}

任何帮助都会很棒

编辑

包括整个清单,只有我的公司名称更改为“ foo”.

编辑

事实证明,我的应用在关闭时确实会收到通知,但在强制关闭后不会收到通知.阅读this问题后实现.

解决方法:

事实证明,无论应用程序是否运行,通知都可以正常工作.问题是该应用程序被强制关闭.

我认为实际问题是在强制关闭该应用程序时,broadcastReceiver被杀死了,但我不确定.

这只是为了结束问题,因为由于我意识到问题与问题标题不同,因此不太可能解决.

总结

以上是内存溢出为你收集整理的android-关闭应用程序时不会收到通知全部内容,希望文章能够帮你解决android-关闭应用程序时不会收到通知所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073871.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存