Powiadomienia nie pojawiają się, gdy aplikacja jest zamknięta
Mam aplikację na Androida z ustawieniami powiadomień push za pomocą Urban Airship. Powiadomienia działają prawidłowo, gdy moja aplikacja jest otwarta, ale muszę nadal otrzymywać powiadomienia, gdy moja aplikacja jest zamknięta. Rozejrzałem się, ale nie znalazłem czegoś, co działa. Jestem pewien, że problem jest w moim manifeście, więc oto jest.
<?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>
Tutaj jest mójIntentReceiver
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
}
}
Każda pomoc byłaby świetna
Edytować
Dołączono cały manifest tylko z nazwą mojej firmy zmienioną na „foo”.
Edytować
Jak się okazuje, moja aplikacja odbiera powiadomienia, gdy jest zamknięta, ale nie po przymusowym zamknięciu. Zrealizowane po przeczytaniuto pytanie.