1

アプリに通知を統合し、次の 2 つのケースを処理しました: NotificationCompat.Builder を使用した Pre Jelly bean 通知と、builder を使用した Post Jelly bean 通知。これにより、ジェリービーン後のバージョンで大きなテキストとアクションを管理できるようになり、2、3 回は動作しますが、奇妙なことに、今日は JB 以下で同じ結果が得られました。

Pre JB のコード:

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pint = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder notif = new NotificationCompat.Builder(context)
    .setContentTitle(nMessage.getTitle())
    .setContentText(nMessage.getMessage())
    .setTicker(nMessage.getTitle())
    .setWhen(when)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setSmallIcon(R.drawable.ic_ttd_petales)
    .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
    .setAutoCancel(true)
    .setContentIntent(pint);
    notification= notif.build();
    notificationManager.notify(0, notification);

JB 以上のコード:

Builder bigTextNotification = new Notification.Builder(context)
        .setContentTitle(nMessage.getTitle())
        .setTicker(nMessage.getTitle())
        .setContentText(nMessage.getMessage())
        .setWhen(when)
        .setPriority(Notification.PRIORITY_HIGH)
        .setSmallIcon(R.drawable.ic_ttd_petales)
        .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
        .setAutoCancel(true)
        .setContentIntent(pint);
        if(nMessage.getHasPhone()){
        Intent iCall = new Intent(Intent.ACTION_CALL,Uri.parse(nMessage.getPhone()));
        PendingIntent pintCall = PendingIntent.getActivity(context, 0, iCall, Intent.FLAG_ACTIVITY_NEW_TASK);
        bigTextNotification.addAction(R.drawable.ic_menu_call, context.getResources().getString(R.string.call_ttd), pintCall);
    }

    String[] recipients = new String[]{context.getResources().getString(R.string.default_email)};
    String subject = context.getResources().getString(R.string.about_offer);

    Intent iEmail = new Intent(android.content.Intent.ACTION_SEND);
    iEmail.setType("text/html"); 
    iEmail.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
    iEmail.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    PendingIntent pintEmail = PendingIntent.getActivity(context, 1, iEmail, Intent.FLAG_ACTIVITY_NEW_TASK);
    bigTextNotification.addAction(R.drawable.ic_menu_compose, context.getResources().getString(R.string.call_ttd), pintEmail);

    Notification notif = new Notification.BigTextStyle(bigTextNotification)
    .bigText(nMessage.getMessage())
    .build();
    notificationManager.notify(1000, notif);

あなたはそのような行動に遭遇したことがありますか、それとも私は何かを見逃していますか?

4

2 に答える 2

1

同様の経験がありました。通知を送信すると、大きなテキストではなくコンテンツ テキストが表示されます。次に、USB を抜くと、大きなテキストが展開されて表示されます。

ここで、USB に接続すると、「メディア デバイスとして接続されました」という継続的な通知が表示されることに注意してください。「GPS を使用して検索中」など、他の進行中の通知で同じ動作が発生するかどうかを確認してください。そうです。(私のテスト デバイスは Samsung Galaxy Rush で、垂直方向のスペースは非常に限られています。)

そのため、Android通知のドキュメントでは、一番上の通知のみが展開されて表示されると記載されていますが、別のルールもあるようです。

通知リストが空欄になると、一番上の通知も崩れてしまいます。

OS のバージョンに応じて、折りたたまれた通知を 2 本指または 1 本指でドラッグして展開できます。

于 2013-12-19T15:50:55.613 に答える
0

このダミーの質問で申し訳ありません。このアプリをテストするためにエミュレーターを使用していませんが、実際の電話を使用しています。奇妙なことは、USB デバッグ ケーブルが接続されている場合、通知 (JB) にアクションがなく、接続されていない場合、ボタンが機能します:)これで問題は解決しますが、この動作についてはわかりません。

于 2013-02-13T15:44:36.873 に答える