无意图接收器设置 Urban AirShip

Posted

技术标签:

【中文标题】无意图接收器设置 Urban AirShip【英文标题】:No intent receiver set Urban AirShip 【发布时间】:2013-06-03 12:05:07 【问题描述】:

我确实收到了推送消息,但是每当我在通知栏中单击它们时,就会出现这个 logcat 并且通知消失...

这是我的 logcat 输出:

 05-31 16:49:47.165: D/Test - UALib(20523): No intent receiver set, not sending ACTION_NOTIFICATION_OPENED

这是我的清单结构:

        <category android:name="com.test.push" />
    </intent-filter>
</receiver>

<service
    android:name="com.urbanairship.push.PushService"
    android:label="Push Notification Service" />
<service
    android:name="com.urbanairship.push.PushWorkerService"
    android:label="Push Notification Worker Service" />
<service
    android:name="com.urbanairship.analytics.EventService"
    android:label="Event Service" />

<provider
    android:name="com.urbanairship.UrbanAirshipProvider"
    android:authorities="com.test.push.urbanairship.provider"
    android:exported="false"
    android:multiprocess="true" />

<activity
    android:name="com.test.push.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="com.test.push.SettingsActivity"
    android:label="@string/title_activity_settings" />
<activity
    android:name="com.test.push.ChooseClass"
    android:label="@string/app_name" />
</application>

这是我的 MyApplication.java:

public class MyApplication extends Application 

@Override
public void onCreate() 
AirshipConfigOptions options = AirshipConfigOptions
        .loadDefaultOptions(this);
options.developmentAppKey = "1234567890";
options.developmentAppSecret = "1234567890";
options.productionAppKey = "";
options.productionAppSecret = "";
options.gcmSender = "1234567890";
options.transport = "gcm";
options.inProduction = false;

UAirship.takeOff(this, options);
PushManager.enablePush();


这是我的 IntentReceiver.java:

public class IntentReceiver extends BroadcastReceiver 
@Override
public void onReceive(Context aContext, Intent aIntent) 
String action = aIntent.getAction();

if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) 
    logPushExtras(aIntent);
 else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) 
    logPushExtras(aIntent);

    Intent launch = new Intent(Intent.ACTION_MAIN);
    launch.setClass(UAirship.shared().getApplicationContext(),
            MainActivity.class);

    launch.putExtra("push_message",
            aIntent.getStringExtra(PushManager.EXTRA_ALERT));
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    UAirship.shared().getApplicationContext().startActivity(launch);
 else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) 
    Logger.info("device registrated, APID="
            + aIntent.getStringExtra(PushManager.EXTRA_APID)
            + ", valid="
            + aIntent.getBooleanExtra(
                    PushManager.EXTRA_REGISTRATION_VALID, false));



private void logPushExtras(Intent intent) 
Set<String> keys = intent.getExtras().keySet();
for (String key : keys) 

    List<String> ignoredKeys = (List<String>) Arrays.asList(
            "collapse_key", "from", PushManager.EXTRA_NOTIFICATION_ID,
            PushManager.EXTRA_PUSH_ID, PushManager.EXTRA_ALERT);
    if (ignoredKeys.contains(key)) 
        continue;
    



【问题讨论】:

【参考方案1】:

问题是,我的MyApplication.java 文件中缺少以下行:

    PushManager.shared().setIntentReceiver(IntentReceiver.class);

其余的都是正确的。它现在运行良好。

【讨论】:

你把这个语句放在java文件的什么地方?实际上我在 onCreate() 中保留了这个语句,但没有工作。【参考方案2】:

我没有在清单文件中指定应用程序的 android:name 属性-

<application
  android:allowBackup="true"
  android:icon="@drawable/app_icon"
  android:label="@string/app_name"
  android:theme="@style/AppTheme"
  android:allowClearUserData="true"
  android:enabled="true" 
  android:name=".MyMainApplication">

  <activity>
  Some Activity
  </activity>

</application>

【讨论】:

以上是关于无意图接收器设置 Urban AirShip的主要内容,如果未能解决你的问题,请参考以下文章

Urban Airship 收不到富推

Urban Airship 在呼叫起飞时坠毁

如何使用 Urban AirShip (Swift) 获取 appDelegate

Urban Airship 和 AirshipConfig.plist

Urban Airship 与 Cordova iOS 投掷集成

无法从 Urban Airship 获得推送通知