導航:首頁 > 操作系統 > androiddisconnected

androiddisconnected

發布時間:2022-05-26 08:14:09

A. 安卓虛擬機顯示disconnected是怎麼回事,顯示器上什麼內容都沒有

這是鎖屏了

B. 手機無法正常開機,出現android機器人,和 do not disconnect usb 等字樣

安卓手機無法正常開機處理方法:
一、長按電源鍵10秒以上看是否可以強制開機。如果能夠開機,請備份重要資料後恢復出廠設置或升級最新軟體版本。
二、如果無法強制開機,請核實手機是否有電,空電狀態插上電源會有充電指示,剛充可能無法立即開機,請持續充電一段時間,再嘗試開機。
三、如果無法充電請聯系手機售後處理。
四、針對開機有反映,但是不進系統,建議進入恢復模式將手機恢復出廠再試(恢復模式進入方法:按住音量減+電源鍵開機)。
如果以上方法均無法強制開機,建議前往專業的手機售後檢測維修。

C. android 怎麼通過藍牙向一個硬體發送AT指令

通過BluetoothSocket的OutputStream發送過去後,InputStream獲取不到數據...代碼用的android自帶的藍牙例子.這樣發送指令後

?12String string = "41542B50494F392C310D";mmOutStream.write(string.getBytes());讀取inputsteam中的?1Log.d("example", "do read");

不執行,完整代碼如下:

?57677787980/*** This thread runs ring a connection with a remote device. It handles all* incoming and outgoing transmissions.*/private class ConnectedThread extends Thread {private final BluetoothSocket mmSocket;private final InputStream mmInStream;private final OutputStream mmOutStream;public ConnectedThread(BluetoothSocket socket, String socketType) {Log.d(TAG, "create ConnectedThread: " + socketType);mmSocket = socket;InputStream tmpIn = null;OutputStream tmpOut = null;// Get the BluetoothSocket input and output streamstry {tmpIn = socket.getInputStream();tmpOut = socket.getOutputStream();} catch (IOException e) {Log.e(TAG, "temp sockets not created", e);}mmInStream = tmpIn;mmOutStream = tmpOut;}public void run() {Log.i(TAG, "BEGIN mConnectedThread");byte[] buffer = new byte[1024];int bytes;// Keep listening to the InputStream while connectedwhile (true) {Log.d("example", "do read");try {// Read from the InputStreambytes = mmInStream.read(buffer);// Send the obtained bytes to the UI ActivitymHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes,-1, buffer).sendToTarget();} catch (IOException e) {Log.e(TAG, "disconnected", e);connectionLost();// Start the service over to restart listening modeBluetoothChatService.this.start();break;}}}/*** Write to the connected OutStream.* * @param buffer* The bytes to write*/public void write(byte[] buffer) {String string = "41542B50494F392C310D";try {mmOutStream.write(string.getBytes());// Share the sent message back to the UI ActivitymHandler.obtainMessage(BluetoothChat.MESSAGE_WRITE, -1, -1,buffer).sendToTarget();} catch (IOException e) {Log.e(TAG, "Exception ring write", e);}}public void cancel() {try {mmSocket.close();} catch (IOException e) {Log.e(TAG, "close() of connect socket failed", e);}}}




0收藏(0)

D. 在Android的藍牙4.0 API的close和斷開之間的區別

通過斷開連接()您可以稍後致電連接()並繼續這一循環。

在你調用關閉()你做。如果你想再次連接,你將不得不調用 connectGatt()在 BluetoothDevice類試; 關閉()將釋放由 BluetoothGatt持有的任何資源。

Public APIs for the Bluetooth Profiles配置文件.
Clients should call getProfileProxy(Context,
BluetoothProfile.ServiceListener, int), to get the Profile Proxy代理. Each public profile implements this interface.

關於getProfileProxy方法
Get the profile proxy object associated交互 with the profile.

Profile can be one of HEALTH, HEADSET, A2DP, GATT, or GATT_SERVER. Clients must implement BluetoothProfile.ServiceListener to get notified 通知of the connection status and to get the proxy object.

方法中的參數
context Context: Context of the application

listener BluetoothProfile.ServiceListener: The service Listener for connection callbacks.

profile int: The Bluetooth profile; either HEALTH, HEADSET, A2DP. GATT or GATT_SERVER.

返回值類型為boolean
BluetoothProfile.ServiceListener介面描述
An
interface for notifying BluetoothProfile IPC clients when they have been connected or disconnected to the service.
通知鏈接狀態
其中的兩個方法:1.public
abstract vois onServiceConected(int profile,BluetoothProfile proxy)
profile
int: - One of HEALTH, HEADSET or A2DP
proxy
BluetoothProfile: - One of BluetoothHealth, BluetoothHeadset or BluetoothA2dp
2.public
abstract void onServiceDIsConected(int profile)
profile
int: - One of HEALTH, HEADSET or A2DP
常量:
String

EXTRA_PREVIOUS_STATE
String EXTRA_STATE
int

A2DP 藍牙音頻協議

int
GATT
int

GATT_SERVER
int

HEADSET 協議類型
int

HEALTH
協議類型
int
SAP
int

STATE_CONNECTED 鏈接狀態
int
STATE_CONNECTING 連接中
int

STATE_DISCONNECTED
int

STATE_DISCONNECTING
公有的方法
abstract List<BluetoothDevice>
getConnectedDevices()
Get connected devices for this specific profile.
獲取設備列表
abstract int getConnectionState(BluetoothDevice device)

Get the current connection state of the profile
Requires BLUETOOTH permission.
abstratct List<BluetoothDevice> (int[] states)
Get
a list of devices that match any of the given connection states.獲取目標鏈接狀態的設備列表

E. android的socket怎樣判斷斷線

非阻塞模式,如果暫時沒有數據,返回的值也會是<=0的,如果用阻塞模式的話,返回<=0的值是可以認為socket已經無效了。

當使用 select()函數測試一個socket是否可讀時,如果select()函數返回值為1,
且使用recv()函數讀取的數據長度為0 時,就說明該socket已經斷開。

經過代碼試驗,如果進程受到一些信號時,例如:EINTR,recv()返回值小於等於0時,這是就需要判斷 errno是否等於 EINTR , 如果errno == EINTR 則說明recv函數是由於程序接收到信號後返回的,socket連接還是正常的,不應close掉socket連接。

如果write,我覺得還有一些情況需要考慮,那就是寫的太快的時候,有可能buffer寫滿了,這是,errno是EAGAIN,可以根據實際需要,如果errno是EAGAIN的話,再寫幾次。

當然,read的時候也有類似write的情況,需要check一下errno,如果是EAGAIN或者EINTR,最好不要立刻終止操作,再嘗試一下!

這是我寫的一個代碼!int SocketConnected(int sock)
{
int res,recvlen;
char buf[20] = {'\0'};
struct timeval timeout={3,0};
fd_set rdfs;
FD_ZERO(&rdfs);
FD_SET(sock,&rdfs);

res = select(sock+1,&rdfs,NULL,NULL,&timeout);

if(res > 0){

recvlen = recv(sock,buf,sizeof(buf),0);
if(recvlen > 0){
printf("socket connected\n");
return 1;
} else if (recvlen < 0 ){
if(errno == EINTR){
printf("socket connected\n");
return 1;
}else {
printf("socket disconnected! connect again!\n");
return 0;
}
} else if (recvlen == 0){
printf("socket disconnected!connect again\n");
return 0;
}
} else if(res == 0 ){
//time out
printf("socket connected\n");
return 1;
} else if(res < 0){
if (errno == EINTR){
printf("socket connected\n");
return 1;
}else{
printf("socket disconnected ! connect again!\n");
return 0;
}
}
return 0;
}

F. android開發中: ServiceConnection類的onServiceDisconnected(ComponentName name)在什麼時候執行

ServiceConnection類中的兩個方法非別在服務連接成功時、不成功時調用。
其中onServiceDisconnected()方法在連接正常關閉的情況下是不會被調用的, 該方法只在Service 被破壞了或者被殺死的時候調用.
例如, 系統資源不足, 要關閉一些Services, 剛好連接綁定的 Service 是被關閉者之一, 這個時候onServiceDisconnected() 就會被調用。

G. 安卓手機鎖屏時數據連接斷開怎麼辦

安卓手機鎖屏時數據連接斷開是怎麼回事?
安卓(Android)是一個基於Linux內核的操作系統,是Google公司在2007年11月5日公布的手機操作系統,不是手機,不過有很多手機採用安卓系統。安卓系統是一款手機系統,現在流行的主流的手機系統之一。
下面,我們就來看看安卓手機鎖屏時數據連接斷開的原因及解決方法。
1、打開手機的設置,這個很簡單吧,不用說了,可以從下拉菜單中找到,也可以直接點擊圖標打開。
2、在「無線和網路」選擇「更多...」
3、選擇「移動網路」。
4、是不是發現問題所在了!只要把「始終連接數據業務」勾選上,就可以解決問題啦!
安卓手機鎖屏時數據連接斷開的解決方法

註:更多精彩教程請關注三聯手機教程欄目,三聯手機數碼群:296605639歡迎你的加入

H. Android:BroadcastReceiver中不能發送請求嗎為什麼我發送請求,只要有disconnect(),就會有異常

對的,主線程中,除了UI相關的其他事情都不能做。回報異常。

I. android ble為什麼自動斷開連接

Generic Attribute Profile (GATT)
通過BLE連接,讀寫屬性類小數據的Profile通用規范。現在所有的BLE應用Profile都是基於GATT的。

Attribute Protocol (ATT)
GATT是基於ATT Protocol的。ATT針對BLE設備做了專門的優化,具體就是在傳輸過程中使用盡量少的數據。每個屬性都有一個唯一的UUID,屬性將以characteristics and services的形式傳輸。

Characteristic
Characteristic可以理解為一個數據類型,它包括一個value和0至多個對次value的描述(Descriptor)。

Descriptor
對Characteristic的描述,例如范圍、計量單位等。

Service
Characteristic的集合。例如一個service叫做「Heart Rate Monitor」,它可能包含多個Characteristics,其中可能包含一個叫做「heart rate measurement"的Characteristic。

二、角色和職責:

Android設備與BLE設備交互有兩組角色:

中心設備和外圍設備(Central vs. peripheral);
GATT server vs. GATT client.

Central vs. peripheral:
中心設備和外圍設備的概念針對的是BLE連接本身。Central角色負責scan advertisement。而peripheral角色負責make advertisement。

GATT server vs. GATT client:
這兩種角色取決於BLE連接成功後,兩個設備間通信的方式。

舉例說明:
現 有一個活動追蹤的BLE設備和一個支持BLE的Android設備。Android設備支持Central角色,而BLE設備支持peripheral角 色。創建一個BLE連接需要這兩個角色都存在,都僅支持Central角色或者都僅支持peripheral角色則無法建立連接。

當 連接建立後,它們之間就需要傳輸GATT數據。誰做server,誰做client,則取決於具體數據傳輸的情況。例如,如果活動追蹤的BLE設備需要向 Android設備傳輸sensor數據,則活動追蹤器自然成為了server端;而如果活動追蹤器需要從Android設備獲取更新信息,則 Android設備作為server端可能更合適。

三、許可權及feature:

和經典藍牙一樣,應用使用藍牙,需要聲明BLUETOOTH許可權,如果需要掃描設備或者操作藍牙設置,則還需要BLUETOOTH_ADMIN許可權:
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

除了藍牙許可權外,如果需要BLE feature則還需要聲明uses-feature:
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

按時required為true時,則應用只能在支持BLE的Android設備上安裝運行;required為false時,Android設備均可正常安裝運行,需要在代碼運行時判斷設備是否支持BLE feature:

// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}

四、啟動藍牙:

在使用藍牙BLE之前,需要確認Android設備是否支持BLE feature(required為false時),另外要需要確認藍牙是否打開。
如果發現不支持BLE,則不能使用BLE相關的功能。如果支持BLE,但是藍牙沒打開,則需要打開藍牙。

打開藍牙的步驟:

1、獲取BluetoothAdapter

BluetoothAdapter是Android系統中所有藍牙操作都需要的,它對應本地Android設備的藍牙模塊,在整個系統中BluetoothAdapter是單例的。當你獲取到它的示例之後,就能進行相關的藍牙操作了。

獲取BluetoothAdapter代碼示例如下:
// Initializes Bluetooth adapter.
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();

註:這里通過getSystemService獲取BluetoothManager,再通過BluetoothManager獲取BluetoothAdapter。BluetoothManager在Android4.3以上支持(API level 18)。

2、判斷是否支持藍牙,並打開藍牙

獲取到BluetoothAdapter之後,還需要判斷是否支持藍牙,以及藍牙是否打開。
如果沒打開,需要讓用戶打開藍牙:
private BluetoothAdapter mBluetoothAdapter;
...
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

五、搜索BLE設備:

通過調用BluetoothAdapter的startLeScan()搜索BLE設備。調用此方法時需要傳入 BluetoothAdapter.LeScanCallback參數。
因此你需要實現 BluetoothAdapter.LeScanCallback介面,BLE設備的搜索結果將通過這個callback返回。

由於搜索需要盡量減少功耗,因此在實際使用時需要注意:

1、當找到對應的設備後,立即停止掃描;
2、不要循環搜索設備,為每次搜索設置適合的時間限制。避免設備不在可用范圍的時候持續不停掃描,消耗電量。

搜索的示例代碼如下:
/**
* Activity for scanning and displaying available BLE devices.
*/
public class DeviceScanActivity extends ListActivity {

private BluetoothAdapter mBluetoothAdapter;
private boolean mScanning;
private Handler mHandler;

// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
...
private void scanLeDevice(final boolean enable) {
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}, SCAN_PERIOD);

mScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
...
}
...
}

如果你只需要搜索指定UUID的外設,你可以調用 startLeScan(UUID[], BluetoothAdapter.LeScanCallback)方法。
其中UUID數組指定你的應用程序所支持的GATT Services的UUID。

BluetoothAdapter.LeScanCallback的實現示例如下:
private LeDeviceListAdapter mLeDeviceListAdapter;
...
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
};

注意:搜索時,你只能搜索傳統藍牙設備或者BLE設備,兩者完全獨立,不可同時被搜索。

六、連接GATT Server:

兩個設備通過BLE通信,首先需要建立GATT連接。這里我們講的是Android設備作為client端,連接GATT Server。
連接GATT Server,你需要調用BluetoothDevice的connectGatt()方法。此函數帶三個參數:Context、autoConnect(boolean)和BluetoothGattCallback對象。調用示例:

mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

函數成功,返回BluetoothGatt對象,它是GATT profile的封裝。通過這個對象,我們就能進行GATT Client端的相關操作。BluetoothGattCallback用於傳遞一些連接狀態及結果。

BluetoothGatt常規用到的幾個操作示例:

connect() :連接遠程設備。
discoverServices() : 搜索連接設備所支持的service。
disconnect():斷開與遠程設備的GATT連接。
close():關閉GATT Client端。
readCharacteristic(characteristic) :讀取指定的characteristic。
setCharacteristicNotification(characteristic, enabled) :設置當指定characteristic值變化時,發出通知。
getServices() :獲取遠程設備所支持的services。

等等。

註:
1、某些函數調用之間存在先後關系。例如首先需要connect上才能discoverServices。
2、 一些函數調用是非同步的,需要得到的值不會立即返回,而會在BluetoothGattCallback的回調函數中返回。例如 discoverServices與onServicesDiscovered回調,readCharacteristic與 onCharacteristicRead回調,setCharacteristicNotification與 onCharacteristicChanged回調等。

J. 有誰知道為什麼我在啟動android模擬器的時候,有時候為什麼會emulator-5554 disconnected

可能是adb的問題

閱讀全文

與androiddisconnected相關的資料

熱點內容
移動端微信商城源碼 瀏覽:438
編程貓下一個背景在哪裡 瀏覽:352
javaclasstype 瀏覽:232
樂高編程和樂高課的延伸 瀏覽:350
蘋果手機怎麼切換app美國賬號 瀏覽:861
編譯程序輸入一個字元串 瀏覽:407
圓命令畫法 瀏覽:308
如果給電腦e盤文件加密 瀏覽:801
javaswing項目 瀏覽:778
androidsdksetup 瀏覽:1005
pdf怎麼設置中文 瀏覽:128
安卓手機用什麼軟體看倫敦金 瀏覽:966
魅族文件夾無名稱 瀏覽:791
蘇黎世無人機演算法 瀏覽:876
核桃編程和小碼王的融資 瀏覽:686
微積分教材pdf 瀏覽:727
寫python給微信好友發消息 瀏覽:338
蚊帳自營米加密 瀏覽:422
學校推薦核桃編程 瀏覽:805
湖南農信app怎麼導明細 瀏覽:475