导航:首页 > 操作系统 > 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相关的资料

热点内容
两个数字的加减乘除运算编程 浏览:221
给手机加密码忘记了怎么办 浏览:596
单片机运算符 浏览:292
移动端微信商城源码 浏览:442
编程猫下一个背景在哪里 浏览:356
javaclasstype 浏览:238
乐高编程和乐高课的延伸 浏览:354
苹果手机怎么切换app美国账号 浏览:865
编译程序输入一个字符串 浏览:407
圆命令画法 浏览:308
如果给电脑e盘文件加密 浏览:802
javaswing项目 浏览:778
androidsdksetup 浏览:1005
pdf怎么设置中文 浏览:128
安卓手机用什么软件看伦敦金 浏览:966
魅族文件夹无名称 浏览:792
苏黎世无人机算法 浏览:876
核桃编程和小码王的融资 浏览:686
微积分教材pdf 浏览:728
写python给微信好友发消息 浏览:340