Android App收到推送通知后崩溃

时间:2012-11-17 18:10:41

标签: android urbanairship.com

我正在使用城市飞艇推动通知。不幸的是,app在推送时崩溃了。

public class IntentReceiver extends BroadcastReceiver {

    private static final String logTag = "PushSample";

    @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);

            logPushExtras(intent);


        } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {


            logPushExtras(intent);

            Intent launch = new Intent(Intent.ACTION_MAIN);
            launch.setClass(UAirship.shared().getApplicationContext(), GetStartedActivity.class);
            launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

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

        } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {

        } else if (action.equals(PushManager.ACTION_GCM_DELETED_MESSAGES)) {

        }

    }


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

            //ignore standard C2DM extra keys
            List<String> ignoredKeys = (List<String>)Arrays.asList(
                    "collapse_key",//c2dm collapse key
                    "from",//c2dm sender
                    PushManager.EXTRA_NOTIFICATION_ID,//int id of generated notification (ACTION_PUSH_RECEIVED only)
                    PushManager.EXTRA_PUSH_ID,//internal UA push id
                    PushManager.EXTRA_ALERT);//ignore alert
            if (ignoredKeys.contains(key)) {
                continue;
            }

        }
    }
}

推送已连续记录,但应用程序崩溃.. 我正在测试三星Galaxy标签。

这是我的班级

AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);

    // Optionally, customize your config at runtime:
    //
    // options.inProduction = false;
    // options.developmentAppKey = "Your Development App Key";
    // options.developmentAppSecret "Your Development App Secret";

    UAirship.takeOff(this, options);
    Logger.logLevel = Log.VERBOSE;

    //use CustomPushNotificationBuilder to specify a custom layout
    CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();

    //nb.statusBarIconDrawableId = R.drawable.icon_small;//custom status bar icon

    //nb.layout = R.layout.notification;
    //nb.layoutIconDrawableId = R.drawable.icon;//custom layout icon
    //nb.layoutIconId = R.id.icon;
    //nb.layoutSubjectId = R.id.subject;
    //nb.layoutMessageId = R.id.message;

    // customize the sound played when a push is received
    //nb.soundUri = Uri.parse("android.resource://"+this.getPackageName()+"/" +R.raw.cat);

    PushManager.shared().setNotificationBuilder(nb);
    PushManager.shared().setIntentReceiver(IntentReceiver.class);
    PushManager.enablePush();

似乎CustomPushNotificationBuilder正在创建问题

0 个答案:

没有答案