Xử lý lỗi phím Return trong Samsung Smart TV App

Lỗi phím return là một lỗi thường gặp và đuợc đánh giá là lỗi nặng khiến app của bạn khi lên store sẽ bị reject. Điều đặc biệt là chúng ta khó có thể nhận ra khi test trên emulator, chỉ có thể phát hiện ra khi test trên máy smart tv thật.

Chúng ta có thể fix lỗi này bằng cách thêm vào hàm sf.key.preventDefault();
Đây là đoạn mã của  sự kiện nhấn Return:
case sf.key.RETURN:
     alert("Key exit pressed");
     sf.key.preventDefault();

     /* Hiển thị alert để confirm */
     $('#list_popup_exit').sfPopup({
     text : "Would You like to exit app?",
     buttons : [ "Yes", "No" ],
     defaultFocus : 1, // index of default focused button. this
                       // indicates array index of "buttons" option (zero-based)
       callback : function(selectedIndex) {
          if (selectedIndex == 0) {
            alert("Exit app");
            sf.core.exit(true);
          }
       }
     });
     $('#list_popup_exit').sfPopup('show');
 break;

Chúc các bạn may mắn!

Nhận xét