0

プッシュ通知に都市飛行船を使っています。残念ながら、プッシュ中にアプリがクラッシュしています。

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

        }
    }
}

プッシュは連続してログに記録されますが、アプリがクラッシュします.. Samsung 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 が問題を作成しているようです

4

0 に答える 0