Tại thời điểm này, các giao diện sẽ được hoàn thành, vì vậy bắt đầu ứng dụng sẽ cho bạn thấy màn hình trong hình 17-2.
1. Bây giờ tạo một mảng danh sách mới của Strings trong Hoạt động EmergencyResponder để lưu trữ các số điện thoại của các yêu cầu đến cho trạng thái của bạn. Ràng buộc Danh sách Array List Xem cách sử dụng một adapter Array trong phương pháp onCreate của hoạt động, và tạo ra một đối tượng ReentrantLock mới để đảm bảo xử lý chủ đề an toàn của Danh Array. Hãy opportu¬nity này để có được một tham chiếu đến các hộp kiểm tra và thêm Nhấp Thính giả cho mỗi nút trả lời. Mỗi nút nên gọi phương thức phản ứng, trong khi Setup nút Auto Responder nên gọi stub startAutoResponder.
Khóa ReentrantLock;
CheckBox locationCheckBox;
ArrayListngười yêu cầu;
ArrayAdapteraa;
© Override
public void onCreate (Bundle savedlnstanceState) {super.onCreate (savedlnstanceState); setContentView (R.layout.main);
khóa = new ReentrantLock (); yêu cầu = new ArrayList(); wireUpControls ();
}
trống wireUpControls tin () {
locationCheckBox = (CheckBox) findViewByld (R.id.checkboxSendLocation);
ListView myListView = (ListView) findViewByid (R.id.myListView);
int layoutID = android.R.layout.simple_list_item_1 ;
aa = ArrayAdapter mới(this, layoutID, Người yêu cầu);
myListView.setAdapter (aa);
Nút okButton = (Button) findViewById (R.id.okButton); okButton.set0nClickListener (mới View.0nClickListener () {public void onClick (View xem) {
phản ứng (đúng, locationCheckBox.isChecked ());
}
});
Nút notOkButton = (Button) findViewByid (R.id.notOkButton); not0kButton.set0nClickListener (View.0nClickListener mới () {public void onClick (View xem) {
phản ứng (false, locationCheckBox.isChecked ());
}
});
Nút autoResponderButton =
(Button) findViewByid (R.id.autoResponder); autoResponderButton.set0nClickListener (mới View.0nClickListener () {public void onClick (View xem) {startAutoResponder ();
}
});
}
public void phản ứng (boolean ok, boolean includeLocation) {) private void startAutoResponder () {)
2. Tạo một nhận Broadcast rằng sẽ lắng nghe các tin nhắn SMS. Bắt đầu bằng cách tạo ra một biến static string mới để lưu trữ các ý định hành động nhắn SMS gửi đến, và sau đó tạo ra một Broadcast Receiver mới như là một biến trong Hoạt động EmergencyResponder. Thu cần lắng nghe các tin nhắn SMS và gọi phương thức requestReceived khi nó thấy tin nhắn SMS có chứa các chuỗi © / tài nguyên chuỗi truy vấn mà bạn xác định trong bước 4.
public static String cuối cùng SMS_RECEIVED =
đang được dịch, vui lòng đợi..