android遇到的问题记录
2016-08-06 08:41
260 查看
1 用gson对json进行解析时候非空字段的判断:
gson = new GsonBuilder().serializeNulls().create();
2 让linearlayout下拉到顶部时候可继续下拉出空白区域然后回弹至顶部的方法:
继承一个scrollview,然后重写ontouchevent方法如下:
@Override
public boolean onTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
if (view != null)
mNormalRect = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
break;
case MotionEvent.ACTION_MOVE:
int temp = (int) ((ev.getY() - m_y) * 0.25);
if(temp>0&&mNormalRect!=null)
view.layout(view.getLeft(), view.getTop() + temp, view.getRight(), view.getBottom() + temp);
break;
case MotionEvent.ACTION_UP:
if(mNormalRect!=null){
view.layout(mNormalRect.left, mNormalRect.top, mNormalRect.right, mNormalRect.bottom);
TranslateAnimation animation = new TranslateAnimation(0, 0, view.getTop() - mNormalRect.top, 0);
animation.setDuration(200);
startAnimation(animation);
}
break;
}
m_y = ev.getY();
return super.onTouchEvent(ev);
}
3:单选dialog的风格设置如下:
<style name="CustomDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<!--背景颜色及透明程度-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--是否有标题 -->
<item name="android:windowNoTitle">true</item>
<!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item>
<!--是否模糊-->
<item name="android:backgroundDimEnabled">true</item>
</style>
4:蓝牙实现自动配对:(暂时只能实现自动输入配对码进行配对,无法实现配对对话框不显示的问题)
1:首先查看蓝牙是否打开,没有发开进行打开
2:打开蓝牙之后注册蓝牙监听广播
BluetoothAdapter.ACTION_DISCOVERY_STARTED //开始搜索设备
BluetoothDevice.ACTION_FOUND //搜索设备中
BluetoothAdapter.ACTION_DISCOVERY_FINISHED //搜索设备结束
BluetoothDevice.ACTION_BOND_STATE_CHANGED//绑定状态发生改变
android.bluetooth.device.action.PAIRING_REQUEST //自动配对时候收到的action
3::触发蓝牙进行配对
ClsUtils.createBond(btDevice.getClass(), btDevice);
其中createBond方法如下:
static public boolean createBond(Class btClass, BluetoothDevice btDevice) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
采用反射机制调用createBondMethod;
然后在receiver中对action进行判断,如果是android.bluetooth.device.action.PAIRING_REQUEST这action,则进行如下操作:
setPin(device.getClass(), device, strPsw);
createBond(device.getClass(), device);
//cancelPairingUserInput(device.getClass(), device);此方法也是调用java的反射机制获取到源码中的取消对话框弹出的方法,但是测试了没有效果,如果有知道的朋友可以发表评论,让大家都学习学习;
最后进行页面设计,完成蓝牙配对工作。
gson = new GsonBuilder().serializeNulls().create();
2 让linearlayout下拉到顶部时候可继续下拉出空白区域然后回弹至顶部的方法:
继承一个scrollview,然后重写ontouchevent方法如下:
@Override
public boolean onTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
if (view != null)
mNormalRect = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
break;
case MotionEvent.ACTION_MOVE:
int temp = (int) ((ev.getY() - m_y) * 0.25);
if(temp>0&&mNormalRect!=null)
view.layout(view.getLeft(), view.getTop() + temp, view.getRight(), view.getBottom() + temp);
break;
case MotionEvent.ACTION_UP:
if(mNormalRect!=null){
view.layout(mNormalRect.left, mNormalRect.top, mNormalRect.right, mNormalRect.bottom);
TranslateAnimation animation = new TranslateAnimation(0, 0, view.getTop() - mNormalRect.top, 0);
animation.setDuration(200);
startAnimation(animation);
}
break;
}
m_y = ev.getY();
return super.onTouchEvent(ev);
}
3:单选dialog的风格设置如下:
<style name="CustomDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<!--背景颜色及透明程度-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--是否有标题 -->
<item name="android:windowNoTitle">true</item>
<!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item>
<!--是否模糊-->
<item name="android:backgroundDimEnabled">true</item>
</style>
4:蓝牙实现自动配对:(暂时只能实现自动输入配对码进行配对,无法实现配对对话框不显示的问题)
1:首先查看蓝牙是否打开,没有发开进行打开
2:打开蓝牙之后注册蓝牙监听广播
BluetoothAdapter.ACTION_DISCOVERY_STARTED //开始搜索设备
BluetoothDevice.ACTION_FOUND //搜索设备中
BluetoothAdapter.ACTION_DISCOVERY_FINISHED //搜索设备结束
BluetoothDevice.ACTION_BOND_STATE_CHANGED//绑定状态发生改变
android.bluetooth.device.action.PAIRING_REQUEST //自动配对时候收到的action
3::触发蓝牙进行配对
ClsUtils.createBond(btDevice.getClass(), btDevice);
其中createBond方法如下:
static public boolean createBond(Class btClass, BluetoothDevice btDevice) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
采用反射机制调用createBondMethod;
然后在receiver中对action进行判断,如果是android.bluetooth.device.action.PAIRING_REQUEST这action,则进行如下操作:
setPin(device.getClass(), device, strPsw);
createBond(device.getClass(), device);
//cancelPairingUserInput(device.getClass(), device);此方法也是调用java的反射机制获取到源码中的取消对话框弹出的方法,但是测试了没有效果,如果有知道的朋友可以发表评论,让大家都学习学习;
最后进行页面设计,完成蓝牙配对工作。
相关文章推荐
- 简单记录android apk 打包签名中遇到的问题
- 记录 cocos2dx ios&android遇到的一些注意问题
- 记录Android开发中遇到的一些问题
- Android学习记录(六) 记录一下最近遇到的坑:url转义遇到的问题
- 记录最近面试时遇到的一个问题:Android root的原理
- 记录 cocos2dx ios&android遇到的一些注意问题
- android 开发中遇到未知问题的记录
- 记录Android端百度地图API使用遇到的问题
- Android与html交互所遇到的问题记录
- Android开发中遇到的问题记录
- Ubuntu 12.04 LTS , 编译Android 源代码遇到的若干问题记录
- 持续记录-修改--写写自己Android学习中遇到的关键性问题
- 记录一下android开发过程中遇到的问题
- Android搜索栏遇到的问题记录
- 天天记录 - 编译Android 4.1.2源码遇到问题解决
- Ubuntu12.04 32位 + android-ndk-r9c 编译ffmpeg遇到的问题记录
- 微信支付 for android 集成笔记( 集成遇到问题记录)
- 记录一下学习Android时遇到一些问题
- (记录学习android遇到的问题)Error:Execution failed for task ':app:packageDebug'. > Failed to create
- 从今天开始记录一下每天学到的Android知识、以及开发中遇到的问题