我尝试使用Imagebutton关闭当前片段.
我在Fragment-A中,当我点击按钮时它将转向Fragment-B.
当我点击Fragment-B上的按钮时,它将转向Fragment-C并关闭Fragment-B.
如果我单击Fragment-C上的后退按钮,它将返回Fragment-A.
我尝试过的代码如下所示
camera_album = (ImageButton) view.findViewById(R.id.camera_album);
camera_album.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
closefragment();
Fragment fragment = FileBrowserFragment.newInstance(null, null, null) ;
MainActivity.addFragment(LocalFileBrowserFragment.this, fragment) ;
}
});
private void closefragment() {
getActivity().getFragmentManager().beginTransaction().remove(this).commit();
}
Run Code Online (Sandbox Code Playgroud)
当我点击片段B的后退按钮时,它会转到Fragment-C.
但是当我单击Fragment-C上的后退按钮时,它不会返回到Fragment-A.它回到了空背景.如果我想回到Fragment-A,我必须再次单击后退按钮.
所以,似乎并没有完成当前片段的关闭.
如何像Android的后退按钮一样完成当前片段?
我正在使用Android中的应用程序,我遵循Android 开发者页面中的Codesuggestion
当我输入代码时:
private LeDeviceListAdapter mLeDeviceListAdapter;
Run Code Online (Sandbox Code Playgroud)
它有错误消息:
LeDeviceListAdapter无法解析为某种类型
我该怎么办才能修复这个错误?
我正在开发IOS,我使用以下代码来设置背景navigationBar.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar-back"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
我想在下图中添加一个图像navigationBar和中心navigationBar.

如何在Objective-C的navigationBar中心添加图像?
提前致谢.
我下面的页面蓝牙低耗能为发展中国家的Android 4.3的蓝牙低能量.
我已经可以打开蓝牙,扫描设备并连接到BLE设备.
但它显示了BluetoothGatt : android.os.DeadObjectException我尝试连接到设备之后(device.connectGatt),然后发现 (mBluetoothGatt.discoverServices) BLE设备的服务.
在BluetoothGatt : android.os.DeadObjectException显示日志之前,如下所示
W/bt-smp (10670): io_cap = 4
W/bt-smp (10670): new io_cap = 4 p_cb->loc_enc_size = 16
W/BluetoothEventManager( 7380): CachedBluetoothDevice for device 20:73:20:00:6C:B4 not found, calling readPairedDevices().
D/BluetoothAdapterService(1108123608)(10670): Get Bonded Devices being called
E/BluetoothEventManager( 7380): Got bonding state changed for 20:73:20:00:6C:B4, but we have no record of that device.
Run Code Online (Sandbox Code Playgroud)
在发现服务之前连接到BLE设备时的完整日志如下所示
I/BluetoothLeService(10888): BluetoothGattCallback-----newState = 2
I/BluetoothLeService(10888): …Run Code Online (Sandbox Code Playgroud) android bluetooth bluetooth-lowenergy android-bluetooth gatt
我在Android中开发BLE,我可以扫描,连接和写入BLE设备的特性.
我调用下面的函数传递BluetoothGatt,并characteristic于AsyncTask当点击Button.
write_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new WriteCharacteristic(mBluetoothGatt , HueCharacteristic).execute();
}
});
Run Code Online (Sandbox Code Playgroud)
写特性的代码如下:
private class WriteCharacteristic extends AsyncTask<String, Void, String> {
public BluetoothGatt mGatt;
public BluetoothGattCharacteristic mCharacteristic;
public WriteCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic){
mGatt = gatt;
mCharacteristic = characteristic;
}
@Override
protected String doInBackground(String... urls) {
mGatt.writeCharacteristic(mCharacteristic);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
但我尝试点击该按钮连续,看来Android的没有每次写入characteristic到BLE装置.
如果我连续点击按钮5次,则会丢失1~3次.它只能写characteristic到BLE装置两次.
题:
Is there any better …
我在Android中开发,我从文件夹中读取文件并放入列表中.
该列表有两个值:1.Name 2.Time
它可以像下面的代码一样显示List:
for(int i=0;i<fileList.size();i++){
Log.i("DownloadFileListTask", "file mName("+i+") = " + fileList.get(i).mName);
Log.i("DownloadFileListTask", "file mTime("+i+") = " + fileList.get(i).mTime);
}
Run Code Online (Sandbox Code Playgroud)
日志如下:
file mName(0) = /DCIM/100__DSC/MOV_0093.LG1
file mTime(0) = 2015-04-15 14:47:46
file mName(1) = /DCIM/100__DSC/PICT0094.JPG
file mTime(1) = 2015-04-15 14:47:52
file mName(2) = /DCIM/100__DSC/MOV_0095.LG1
file mTime(2) = 2015-04-15 14:48:04
file mName(3) = /DCIM/100__DSC/MOV_0096.LG1
file mTime(3) = 2015-04-15 14:48:12
file mName(4) = /DCIM/100__DSC/MOV_0097.LG1
file mTime(4) = 2015-04-15 14:48:20
file mName(5) = /DCIM/100__DSC/MOV_0098.LG1
file mTime(5) = 2015-04-15 14:50:26
Run Code Online (Sandbox Code Playgroud)
从日志中,早期时间是第一个对象.但是我希望改变它的顺序.
如何在Android中反转列表的顺序?
我正在开发一个应用程序,我必须连接到Android 4.3上的蓝牙设备.
我想通过使用Battery_Service和Battery_Level获得电池电量.
public class BluetoothLeService extends Service {
private static final UUID Battery_Service_UUID =
UUID.fromString("0000180F-0000-1000-8000-00805f9b34fb");
private static final UUID Battery_Level_UUID =
UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb");
public void getbattery() {
BluetoothGattService batteryService = mBluetoothGatt.getService(Battery_Service_UUID);
if(batteryService == null) {
Log.d(TAG, "Battery service not found!");
return;
}
BluetoothGattCharacteristic batteryLevel = batteryService.getCharacteristic(Battery_Level_UUID);
if(batteryLevel == null) {
Log.d(TAG, "Battery level not found!");
return;
}
mBluetoothGatt.readCharacteristic(batteryLevel);
?????// What should I do that I can get the battery level ??
Log.d(TAG, "Battery level " + …Run Code Online (Sandbox Code Playgroud) android battery bluetooth-lowenergy batterylevel android-4.3-jelly-bean
我在Android和BLE开发.我希望应用程序在BLE设备断开连接后自动重新连接到BLE设备,但回到范围和广告中.
我使用以下代码连接到BLE设备:
public void connect(final String address) {
// TODO Auto-generated method stub
Log.w(TAG, "BluetoothLeService Connect function.");
if(mBluetoothAdapter == null || address == null){
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
//return false;
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
}
Run Code Online (Sandbox Code Playgroud)
我已设置AutoConnect为true,但当BLE设备断开连接并返回范围时,它没有重新连接.
在Android中将autoConnect设置为true时,为什么应用程序不会重新连接到BLE设备?
我错过了什么吗?
提前致谢.
我正在开发Android for BLE.我的BLE设备会播放不同的名字,所以我需要继续重新扫描Android.
我创建了一个Runnable停止并开始扫描,如下所示.当我打电话时mHandler.post(monitorDevice);,它会启动Runnable.
final Runnable monitorDevice = new Runnable() {
@Override
public void run() {
scanLeDevice(false);
scanLeDevice(true);
mHandler.postDelayed(this,3000);
}
};
Run Code Online (Sandbox Code Playgroud)
代码scanLeDevice如下:
public void scanLeDevice(final boolean enable) {
// TODO Auto-generated method stub
if(enable){
mScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
}else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在开始时看到日志中的扫描结果.但是大约10~15分钟后,logcat显示以下日志,我看不到任何扫描结果.
startLeScan(): null
D/BluetoothLeScanner? onClientRegistered() - status=0 clientIf=5
Run Code Online (Sandbox Code Playgroud)
有人有这个问题吗?提前致谢!!!
我按照蓝牙低能耗页面进行Android 4.3蓝牙低功耗开发
我尝试通过以下代码连接BLE设备:
public void connect(final String address) {
// TODO Auto-generated method stub
Log.w(TAG, "BluetoothLeService Connect function.");
if(mBluetoothAdapter == null || address == null){
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
}
Run Code Online (Sandbox Code Playgroud)
连接到BLE设备后,它将通过mBluetoothGatt.discoverServices();以下代码发现服务.
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
public void onConnectionStateChange(android.bluetooth.BluetoothGatt gatt, int status, int newState) {
if(mBluetoothGatt == null){
Log.e(TAG, "mBluetoothGatt not created!");
return;
}
device = gatt.getDevice();
address = device.getAddress();
try …Run Code Online (Sandbox Code Playgroud)