Microsoft Word - bluetooth_trong_android.docx

Tài liệu tương tự
Microsoft Word - custom_font_trong_android.docx

Microsoft Word - mot_so_ung_dung_android_co_ban.docx

Microsoft Word - auto_complete_trong_android.docx

Microsoft Word - audio_capture_trong_android.docx

Microsoft Word - alert_dialog_trong_android.docx

Microsoft Word - edittext_trong_android.docx

Microsoft Word - tao_ung_dung_hello_world_trong_android.docx

Microsoft Word - fragment_transition_trong_android.docx

Microsoft Word - custom_component_trong_android.docx

Microsoft Word - grid_view_trong_android.docx

Microsoft Word - activity_trong_android.docx

Microsoft Word - google_map_trong_android.docx

Microsoft Word - single_fragment_trong_android.docx

Microsoft Word - content_provider_trong_android.docx

Microsoft Word - cai_dat_android_studio.docx

Trường Đại học Công nghiệp TpHCM - Thiết kế giao diện - Xử lý sự kiện - Thao tác với menu - Làm việc với Intent - Làm việc với Dialog - Đa ngôn ngữ Bà

Microsoft Word - resource_trong_android.docx

CÀI ĐẶ T ANDROID TRÊN NETBEAN Yêu cầ u:trong quá trình cài đặ t phả i kế t nố i mạ ng,và phiên bả n này đượ c cài trên windows. 1.Download Netbean(6.7

Kế thừa

Microsoft Word - server_response_trong_servlet.docx

GIẢI PHÁP NHÀ THÔNG MINH LUMI LIFE HƯỚNG DẪN SỬ DỤNG VOICE CONTROL

Những cơ sở của ngôn ngữ C# Những cơ sở của ngôn ngữ C# Bởi: phamvanviet truonglapvy Trong chương này sẽ trình bày về hệ thống kiểu trong C#; phân biệ

Trường ĐH Khoa Học Tự Nhiên Tp. Hồ Chí Minh TRUNG TÂM TIN HỌC Lập trình Android Bài 2. Các thành phần ứng dụng Ngành Mạng & Thiết bị di động 2014

Microsoft Word - status_code_trong_servlet.docx

Kế thừa và đa hình

Trường ĐHBK Hà Nội Khoa Điện Bộ môn Điều khiển Tự động Tài liệu hướng dẫn thực hành: KĨ THUẬT LẬP TRÌNH C/C++ Bài 1: Lập trình cơ sở 1 Mục đích bài th

1

Microsoft Word - Bai 7.1.docx

Array, Indexer và Collection Array, Indexer và Collection Bởi: phamvanviet truonglapvy Mảng (Array) Mảng là một tập hợp các phần tử có cùng kiểu, được

Java cơ bản

Microsoft Word - client_request_trong_servlet.docx

Microsoft Word - jsp_syntax.docx

XJ-UT311WN_XJ-UT351WN

Microsoft Word - xu_ly_cookie_trong_servlet.docx

Microsoft Word - session_tracking_trong_servlet.docx

Microsoft Word - action_trong_jsp.docx

ĐỒNG HỒ ĐỊNH VỊ GPS GW01 Dành cho hệ điều hành Android 4.3 trở lên Tài liệu hướng dẫn sử dụng cho điện thoại Android (Phiên bản 2.1)

Lập trình cấu trúc trong Visual Basic Lập trình cấu trúc trong Visual Basic Bởi: Nguyễn Sơn Học xong chương này, sinh viên phải nắm bắt được các vấn đ

Microsoft Word - TN216.doc

Lớp đối tượng trong.net Framework Lớp đối tượng trong.net Framework Bởi: Khuyet Danh Trong chương này chúng ta sẽ tìm hiểu các lớp cơ sở mà.net cung c

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC DÂN LẬP HẢI PHÒNG ISO 9001:2015 ĐỒ ÁN TỐT NGHIỆP NGÀNH: CÔNG NGHỆ THÔNG TIN Sinh

Copyright vietjack.com Nạp chồng toán tử trong C# Operator Overloading là Nạp chồng toán tử. Bạn có thể tái định

Thực hành trên Rose Thực hành trên Rose Bởi: Đoàn Văn Ban Xây dựng biểu đồ thành phần + Tạo lập mới hoặc mở một biểu đồ thành phần đã được tạo lập trư

Lập trình và ngôn ngữ lập trình

Hướng dẫn KHG sử dụng dịch vụ BaaS do Mobifone Global cung cấp Tổng Công ty Viễn thông MOBIFONE là nhà cung cấp dịch vụ Viễn thông và CNTT hàng đầu tạ

Microsoft Word - fragment_trong_android.docx

Microsoft Word - su_dung_sqlite_voi_php.docx

sdfsdfsdfsfsdfd

Câu lệnh (statement) Câu lệnh (statement) Bởi: Khuyet Danh Trong C# một chỉ dẫn lập trình đầy đủ được gọi là câu lệnh. Chương trình bao gồm nhiều câu

Microsoft Word - emulator_trong_android.docx

GO-IXE HƯỚNG DẪN SỬ DỤNG ỨNG DỤNG ANDROID DRIVER Phiên bản /12/2018

Tìm hiểu ngôn ngữ lập trình Visual Basic Tìm hiểu ngôn ngữ lập trình Visual Basic Bởi: Khuyet Danh Tìm hiểu ngôn ngữ lập trình Visual Basic Tổng quan

Copyright vietjack.com Chuỗi (String) trong C# Trong C#, bạn có thể sử dụng các chuỗi (string) như là mảng các ký

hdsd soft token

Microsoft Word - mot_so_tool_trong_android.docx

Microsoft Word - co_ban_ve_jquery.docx

hdsd sinh trac hoc

BƯỚC 1 CÀI LẮP SIM BƯỚC 2 APN BƯỚC 3 ĐĂNG KÝ HOÀN THÀNH Bỏ SIM vào máy di động. Cài đặt APN. Vui lòng khởi động lại thiết bị. Vui lòng mở trình duyệt

HƯỚNG DẪN SỬ DỤNG CÁC SẢN PHẨM CỦA OFFICE 365 Hợp đồng số: 25/KTQD-FPT Cung cấp hệ thống Office trực tuyến và thư điện tử Trường Đại Học Kinh Tế Quốc

HƯỚNG DẪN SỬ DỤNG ROLAND RP-102 1

Slide 1

Xử lý ngoại lệ

BÀI TẬP THỰC HÀNH

HƯỚNG DẪN SỬ DỤNG Vui lòng đọc kỹ tài liệu hướng dẫn này trước khi vận hành thiết bị của bạn. MODEL : PD239W/ PD239P/ PD239Y/ PD239TW/ PD239TP/ PD239T

Chương trình dịch

Presentations

VIE_v5.pages

Microsoft Word - Huong dan su dung Mailchimp.docx

ESET Mobile Security

Công ty CP công nghệ thẻ NACENCOMM HÓA ĐƠN ĐIỆN TỬ CA2 CÔNG TY CỔ PHẦN CÔNG NGHỆ THẺ NACENCOMM TÀI LIỆU NGHIỆP VỤ HÓA ĐƠN ĐIỆN TỬ CA2 Hà Nội 12/2017 1

Chủ đề :

Microsoft Word - jsp_exception_handling.docx

Microsoft Word - jsp_file_uploading.docx

PowerPoint Presentation

Microsoft Word - Lab09 - WebSieuthisach.doc

NGÔN NGƯ LÂ P TRIǸH Biên tập bởi: nguyenvanlinh

Hướng dẫn sử dụng 1

TỔNG CỤC THUẾ TÀI LIỆU HƯỚNG DẪN CÀI ĐẶT ỨNG DỤNG HỖ TRỢ KÊ KHAI PHIÊN BẢN 4.0.X (DÙNG CHO NGƯỜI NỘP THUẾ) HÀ NỘI

THU THẬP DỮ LIỆU TRÊN THIẾT BỊ DI ĐỘNG ANDROID isurvey là ứng dụng thu thập dữ liệu trên thiết bị di động sử dụng hệ điều hành Android. isurvey khai t

NGÔN NGỮ THỐNG KÊ R

Microsoft Word - selector_trong_jquery.docx

ZTE-U V889D Hướng dẫn sử dụng

GHI DANH TRỰC TUYẾN NCSD Qua thủ tục này, quý vị sẽ có thể ghi danh (các) con em học sinh mới vào Khu Học Chánh North Clackamas hoặc xác nhận thông ti

HƯỚNG DẪN SỬ DỤNG DỊCH VỤ STORAGE.COM.VN

Yeastar S50 VoIP PBX Installation Guide Version 1.0 Jun. 2016

HƯỚNG DẪN CÁC NGHIỆP VỤ KÊ KHAI (Trên phần mềm ebh của công ty Thái Sơn) Nghiệp vụ : Đăng ký đóng BHXH bắt buộc (Người lao động có thời hạn ở nước ngo

Animation, Modules 6 - Hoạt hình, tách file

Chuỗi Chuỗi Bởi: phamvanviet truonglapvy Chuỗi (string) trong C# là một kiểu dựng sẵn như các kiểu int, long, có đầy đủ tính chất mềm dẻo, mạnh mẽ và

Moduel 7:Trinh chiếu bài thuyết trình 163 Moduel 7: rình chiếu bài thuyết trình 7.1. rình chiếu bài thuyết trình Thiết lập các tùy ch n cho chế độ Sli

PHỤ LỤC 01 HƯỚNG DẪN KHÁCH HÀNG THAO TÁC ĐĂNG KÝ, KÍCH HOẠT VÀ SỬ DỤNG SOFT OTP (CHALLENGE VÀ MOBILE PUSH) CHO DỊCH VỤ ONLINE BANKING CỦA KHÁCH HÀNG C

Microsoft Word - form_trong_html.docx

PowerPoint Presentation

Phụ lục 2: HỒ SƠ NĂNG LỰC NĂM 2014

Chương trình dịch

Lớp và đối tượng-các hàm và các lớp friend Lớp và đối tượng-các hàm và các lớp friend Bởi: Thanh Hiền Vũ CÁC HÀM VÀ CÁC LỚP friend Một hàm friend của

Easy UI Solution 3 Hướng dẫn sử dụng

iCeeNee iOS User's Manual.docx

Giới thiệu

Hàm và lớp template trong Lập trình hướng đối tượng Hàm và lớp template trong Lập trình hướng đối tượng Bởi: unknown Trong phần này, chúng ta tìm hiểu

DICENTIS_Wireless_ConfigSWM

Bản ghi:

Bluetooth trong Android Bluetooth là một cách để truyền và nhận dữ liệu giữa hai thiết bị khác nhau. Android platform cung cấp hỗ trợ cho Bluetooth framework cho phép một thiết bị trao đổi dữ liệu với thiết bị Bluetooth khác. Android cung cấp Bluetooth API để thực hiện các hoạt động: Quét các thiết bị Bluetooth khác. Lấy một danh sách các thiết bị có thể ghép cặp (Paired Device). Kết nối với thiết bị khác thông qua dịch vụ dò tìm. Android cung cấp lớp BluetoothAdapter để giao tiếp với Bluetooth. Tạo một đối tượng của lớp này bởi gọi phương thức static là getdefaultadapter(). Cú pháp như sau: private BluetoothAdapter BA; BA = BluetoothAdapter.getDefaultAdapter(); Để kích hoạt Bluetooth của thiết bị, gọi Intent với hằng ACTION_REQUEST_ENABLE. Cú pháp như sau: Intent turnon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startactivityforresult(turnon, 0); Ngoài hằng này, API còn cung cấp một số hằng khác để hỗ trợ các tác vụ khác nhau. Bảng dưới liệt kê các hằng này: Stt Constant & Miêu tả 1 ACTION_REQUEST_DISCOVERABLE Hằng này được sử dụng để bật trình dò tìm của Bluetooth 2 ACTION_STATE_CHANGED Hằng này thông báo rằng trạng thái Bluetooth đã bị thay đổi 3 ACTION_FOUND

Hằng này được sử dụng để nhận thông tin về mỗi thiết bị đã được dò tìm Khi bạn kích hoạt Bluetooth, bạn có thể lấy một danh sách các thiết bị có thể ghép cặp bằng cách gọi phương thức getbondeddevices(). Nó trả về một tập hợp các thiết bị Bluetooth. Cú pháp là: private Set<BluetoothDevice>pairedDevices; paireddevices = BA.getBondedDevices(); Ngoài các thiết bị có thể ghép đôi, API còn cung cấp một số phương thức khác để giúp bạn có nhiều điều khiển hơn thông qua Bluetooth. Stt Phương thức & Miêu tả 1 enable() Phương thức này kích hoạt Adapter nếu nó chưa được kích hoạt 2 isenabled() Phương thức này trả về true nếu Adapter đã được kích hoạt 3 disable() Phương thức này vô hiệu hóa Adapter 4 getname() Phương thức này trả về tên của Bluetooth Adapter 5 setname(string name) Phương thức này thay đổi tên của Bluetooth 6 getstate() Phương thức này trả về trạng thái hiện tại của Bluetooth Adapter 7 startdiscovery() Phương thức này bắt đầu tiến trình dò tìm của Bluetooth trong 120 s

Ví Ví dụ sau minh họa lớp BluetoothAdapter để thao tác Bluetooth và liệt kê các thiết bị có thể ghép đôi. Để thử nghiệm ví dụ, bạn cần chạy trên một thiết bị thực sự. Sau đây là nội dung của src/mainactivity.java package com.example.sairamkrishna.myapplication; import android.app.activity; import android.bluetooth.bluetoothadapter; import android.bluetooth.bluetoothdevice; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.graphics.color; import android.net.wifi.scanresult; import android.net.wifi.wifimanager; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.listview; import android.widget.textview; import android.widget.toast; import java.util.arraylist; import java.util.list; import java.util.set; public class MainActivity extends Activity { Button b1,b2,b3,b4; private BluetoothAdapter BA; private Set<BluetoothDevice>pairedDevices; ListView lv; @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); b1 = (Button) findviewbyid(r.id.button); b2=(button)findviewbyid(r.id.button2); b3=(button)findviewbyid(r.id.button3); b4=(button)findviewbyid(r.id.button4); BA = BluetoothAdapter.getDefaultAdapter(); lv = (ListView)findViewById(R.id.listView); } public void on(view v){ if (!BA.isEnabled()) { Intent turnon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startactivityforresult(turnon, 0); Toast.makeText(getApplicationContext(),"Turned on",toast.length_long).show(); } else { Toast.makeText(getApplicationContext(),"Already on", Toast.LENGTH_LONG).show(); } } public void off(view v){ BA.disable(); Toast.makeText(getApplicationContext(),"Turned off",toast.length_long).show(); } public void visible(view v){ Intent getvisible = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); startactivityforresult(getvisible, 0); } public void list(view v){ paireddevices = BA.getBondedDevices(); ArrayList list = new ArrayList(); for(bluetoothdevice bt : paireddevices) list.add(bt.getname()); Toast.makeText(getApplicationContext(),"Showing Paired Devices",Toast.LENGTH_SHORT).show(); final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, list); lv.setadapter(adapter); } @Override public boolean oncreateoptionsmenu(menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @Override public boolean onoptionsitemselected(menuitem item) { //

Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getitemid(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onoptionsitemselected(item); } } Sau đây là nội dung của activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity" android:transitiongroup="true"> <TextView android:text="bluetooth Example" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview" android:textsize="35dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <TextView android:text="tutorials point" android:id="@+id/textview" android:layout_below="@+id/textview" android:layout_centerhorizontal="true" android:textcolor="#ff7aff24" android:textsize="35dp" /> <ImageView android:id="@+id/imageview" android:src="@drawable/abc" android:layout_below="@+id/textview" android:layout_centerhorizontal="true" android:theme="@style/base.textappearance.appcompat" /> <Button android:text="turn On" android:id="@+id/button" android:layout_below="@+id/imageview" android:layout_tostartof="@+id/imageview" android:layout_toleftof="@+id/imageview" android:clickable="true" android:onclick="on" /> <Button android:text="get visible" android:onclick="visible" android:id="@+id/button2" android:layout_alignbottom="@+id/button" android:layout_centerhorizontal="true" /> <Button android:text="list devices" android:onclick="list" android:id="@+id/button3" android:layout_below="@+id/imageview" android:layout_torightof="@+id/imageview" android:layout_toendof="@+id/imageview" /> <Button android:text="turn off" android:onclick="off" android:id="@+id/button4" android:layout_below="@+id/button" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <ListView android:id="@+id/listview" android:layout_alignparentbottom="true"

android:layout_alignleft="@+id/button" android:layout_alignstart="@+id/button" android:layout_below="@+id/textview2" /> <TextView android:text="paired devices:" android:id="@+id/textview2" android:textcolor="#ff34ff06" android:textsize="25dp" android:layout_below="@+id/button4" android:layout_alignleft="@+id/listview" android:layout_alignstart="@+id/listview" /> </RelativeLayout> Sau đây là nội dung của Strings.xml <resources> <string name="app_name">my Application</string> <string name="hello_world">hello world!</string> <string name="action_settings">settings</string> </resources> Sau đây là nội dung của AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sairamkrishna.myapplication" > <uses-permission android:name="android.permission.bluetooth"/> <uses-permission android:name="android.permission.bluetooth_admin"/> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest> Cuối cùng, bạn chạy ứng dụng Android vừa tạo ở trên.

Bây giờ, chọn nút Turn On để bật Bluetooth. Nhưng khi bạn chọn nó, thì thì Bluetooth sẽ không được bật lên ngay, nó sẽ hỏi bạn về permission để kích hoạt Bluetooth.

Bây giờ chọn nút GET VISIBLE để bật tính năng Visibility. Màn hình sau xuất hiện hỏi bạn về permission để bật dò tìm trong 120 s.

Chọn tùy chọn List Devices. Nó sẽ liệt kê các thiết bị có thể ghép đôi.

Chọn nút TURN OFF để tắt Bluetooth. Thông báo sau sẽ xuất hiện: