0
public class test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

        String extra = "test";

        NotificationManager myNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Intent intent = new Intent(this, another.class);

        Notification notification = new Notification(R.drawable.ic_launcher, extra, 
                System.currentTimeMillis());
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 
                0,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(getApplicationContext(), "title", "text", pendingIntent);


        notification.defaults|= Notification.DEFAULT_SOUND;
        notification.defaults|= Notification.DEFAULT_LIGHTS;
        notification.defaults|= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_INSISTENT;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        myNotificationManager.notify(1, notification);
    }
}

このスニペットコードは正常に機能しています。実行すると、ステータスバーで確認するまで通知音が鳴り続けます。常に鳴るのではなく、一度だけ鳴らせる方法はありますか?

4

1 に答える 1

7

フラグを削除しますNotification.FLAG_INSISTENT

ドキュメントから:「ビット単位でフラグフィールドに入力します。設定すると、通知がキャンセルされるか、通知ウィンドウが開くまで音声が繰り返されます。」

于 2012-05-16T21:17:37.903 に答える