⑴ android 怎么实现屏幕的自动匹配
在AndroidManifest.xml中定义如下:
<supports-screens
android:largeScreens=”true”
android:normalScreens=”true”
android:smallScreens=”true”
android:resizable=”true”
android:anyDensity=”true” />
⑵ Android是怎样匹配资源的
针对大多数APK应用程序,开发人员都会提供各种不同的资源。比如对于同一张图片image.png,我们通常会提供高分辨率,中分辨率和低分辨率三个版本。
res/它们都必须以相同的名字存储在各个drawable目录下。当应用程序运行时,系统会根据当前设备的实际分辨率来选择最佳的资源。
那么系统运行时如何动态选择最合适的资源来使用呢?
理解最佳资源的匹配过程至少有两个好处:
理解最佳资源匹配过程之前,我们先来看一下资源标签的属性和优先级。所谓优先级顺序指的是Android规定的资源标签属性的优先级。
其实除了分辨率外,同种资源之间还可以有下面许多资源属性标签,它们在匹配过程中是有优先级顺序的。
以下资源标签修饰语按照优先级从高到低的顺序排列。
MCC和MNC
MCC(Mobile Country Code)和MNC(Mobile Network
Code)是网络运营商的全球唯一编号。其中MCC指国家码,MNC指网络号。
例如,MCC-310属于美国,MCC-460属于中国。460-00代表中国移动,460-01代表中国联通。一般情况下,SIM卡中存有此卡的主归属地。
用作资源标签时,可以同时使用MCC和MNC
组合,也可以只使用MCC。例如,mcc460,mcc460-mnc00。程序编码时,可以使用Configuration类中的mcc和mnc属性来获取当前设备的这两个值。
语言和地区
Android系统采用ISO
639-1国际语言码,由两个字母组成。地区代码遵循3166-1-alpha-2标准执行,也由两个字母组成,是可选的。如何组合使用需要加”r”.例如en表示英语,fr表示法语,en-rUS表示英语和美国地区。程序中可以通过Configuration类的locale属性值来获取当前设备的语言地区信息。
最小宽度(Smallest Width)
格式为 sw<N>dp
例如用res/layout-sw600dp来标志自己的布局资源,相当于告诉系统,屏幕的可显示尺寸必须在任何时刻都大于600dp(不管横屏还是竖屏),才可以使用这一资源。与设备语言值不同的是,设备最小宽度不会随系统设置的变化而改变,它是固定的。
可以在AndroidManifest.xml中,通过指定"android:requiresSmallestWidthDp"属性值来表示此程序要求的最小宽度值。代码中可以通过Configuration类中的smallestScreenWidthDp成员变量来获取当前设备的最小宽度值。
可用宽度(Available Width)
格式为 w<N>dp
设备的可用宽度值随着当前是横屏还是竖屏会产生变化,即它表示的是当前真实的宽度值。如果多种可选资源中都采用了这一标签修饰,那么系统会自动选择一个最接近于(但不超过)当前值得资源。
例如w720dp,代码中可以通过Configuration类的screenWidthDp成员变量来获取当前的可用宽度值。
可用高度(Available Height)
格式为:h<N>dp
和可用宽度表达含义类似,只不过这里值高度。代码中可以通过Configuration类的screenHeightDp成员变量来获取当前的可用宽度值。
屏幕大小(Screen Size)
Android设备尺寸众多,大致将屏幕尺寸分为以下几类:
代码中通过Configuration类中的screenLayout成员变量来获取当前设备的屏幕大小。
屏幕宽高外观(Screen Aspect)
指的是当前屏幕的宽高比(aspect ratio)。分为以下两种
nolong
非长屏幕,如QVGA,HVGA,VGA等。
可以通过Configuration类中的screenLayout成员变量来获知屏幕是否为长屏。
屏幕方向(Screen Orientation)
分为两种,竖屏(port)和横屏(land)。
这个值会随着用户的操作而变化,但我们可以通过Configuration类中的orientation成员变量来获知当前设备的屏幕方向。
UI模式(UI mode)
分为以下几种:car,desk,television,appliance.
表示设备被放置在底盘(dock)时的模式,如汽车上的手机托盘,桌面托盘等。这个模式会随着用户的操作而改变,可以通过UiModeManager来开启和关闭这一功能。
夜间模式(Night Mode)
分为两种,night(处于夜间模式)和notnight(非夜间模式)。
可以通过UiModeManager来开启和关闭这一功能。
屏幕像素密度(dpi)
触摸屏类型(Touchscreen Type)
分为notouch(设备不带触摸屏)和finger(触摸屏通过手指操作)。
通过Configuration类中的touchscreen成员变量来获知当前设备的触摸屏类型。
键盘可用性
分为以下三种状态
这个值在运行过程中会发生变化,可以通过Configuration类的hardkeyboardHidden和keyboardHidden变量来获知当前状态。
⑶ android本地api文档 检索功能不能自动匹配
直接把自己在知乎的回答过得拷贝过来,希望对大家有作用。
一、原因
不能索索的根本原因是浏览器无法访问Google,服务器无法响应里面的Ajax。
二、解决办法
方法1:使用Mozilla Firefox浏览器,点击“文件”选择“脱机模式”,然后在浏览器里面输入android sdk的docs路径,比如:file:///E:/androidstudio/sdk/docs/reference/packages.html 。 然后再去搜索的时候就可以了。
方法2:将docs文件放到tomcat里面,然后运行tomcat,再通过localhost访问文档。这种方式还是有点慢,推荐第一种。
⑷ 如何实现Android蓝牙开发 自动配对连接,并不弹出提示框
android蓝牙自动配对连接的具体代码如下: 1. 获取蓝牙适配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter(); 如果BluetoothAdapter 为null,说明android手机没有蓝牙模块。 2. 判断蓝牙模块是否开启,blueadapter.isEnabled() true表示已经开启,false表示蓝牙并没启用。 3. 启动配置蓝牙可见模式,即进入可配对模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200); startActivity(in); ,200就表示200秒。 4. 获取蓝牙适配器中已经配对的设备Set<BluetoothDevice> device=blueadapter.getBondedDevices(); 当然,还需要在androidManifest.xml中声明蓝牙的权限 <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 5.自动配对设置Pin值 static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin) throws Exception { Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class }
⑸ android蓝牙配对 如何自动配对设置PIN码
Android对于音频设备是自动输入0000的pin码的,参照$frameworks/base/core/java/android/server/BluetoothEventLoop.java 的onRequestPinCode()你若是在app里编写代码,可以在收到ACTION_PAIRING_REQUEST的时候,直接调用BluetoothDevice.setpin()reference $package/apps/Settings/src/android/settings/bluetooth/BluetoothPairingDialog.java 的onPair();
⑹ android 怎么实现蓝牙的自动匹配和连接
eoe 看到过:
<receiver android:name=".broadcast.PairingRequest">
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" /$amp;>amp;$nbsp;
<action android:name="android.bluetooth.device.action.PAIRING_CANCEL" /$amp;>amp;$nbsp;
</intent-filter>
</receiver>
public class PairingRequest extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
if (intent.getAction().equals("ACTION_PAIRING_REQUEST")) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
device.setPin(pinBytes);
}
}
}
其中的蓝牙BluetoothDevice这个类要用源码里的替换下(不然会缺少方法)。
⑺ 如何实现android蓝牙自动配对连接
望你踩呐我的回答
下面是自动配对的代码
Mainfest,xml注册
<receiver android:name="." >
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>
自己在收到广播时处理并将预先输入的密码设置进去
public class extends BroadcastReceiver
{
String strPsw = "0";
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if (intent.getAction().equals(
"android.bluetooth.device.action.PAIRING_REQUEST"))
{
BluetoothDevice btDevice = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
// device.setPin(pinBytes);
Log.i("tag11111", "ddd");
try
{
ClsUtils.setPin(btDevice.getClass(), btDevice, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(btDevice.getClass(), btDevice);
ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
<b>/************************************ 蓝牙配对函数 * **************/
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
public class ClsUtils
{
/**
* 与设备配对 参考源码:platform/packages/apps/Settings.git
* /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
static public boolean createBond(Class btClass, BluetoothDevice btDevice)
throws Exception
{
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
/**
* 与设备解除配对 参考源码:platform/packages/apps/Settings.git
* /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
static public boolean removeBond(Class btClass, BluetoothDevice btDevice)
throws Exception
{
Method removeBondMethod = btClass.getMethod("removeBond");
Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
static public boolean setPin(Class btClass, BluetoothDevice btDevice,
String str) throws Exception
{
try
{
Method removeBondMethod = btClass.getDeclaredMethod("setPin",
new Class[]
{byte[].class});
Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice,
new Object[]
{str.getBytes()});
Log.e("returnValue", "" + returnValue);
}
catch (SecurityException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
// 取消用户输入
static public boolean cancelPairingUserInput(Class btClass,
BluetoothDevice device)
throws Exception
{
Method createBondMethod = btClass.getMethod("cancelPairingUserInput");
// cancelBondProcess()
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}
// 取消配对
static public boolean cancelBondProcess(Class btClass,
BluetoothDevice device)
throws Exception
{
Method createBondMethod = btClass.getMethod("cancelBondProcess");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}
/**
*
* @param clsShow
*/
static public void printAllInform(Class clsShow)
{
try
{
// 取得所有方法
Method[] hideMethod = clsShow.getMethods();
int i = 0;
for (; i < hideMethod.length; i++)
{
Log.e("method name", hideMethod[i].getName() + ";and the i is:"
+ i);
}
// 取得所有常量
Field[] allFields = clsShow.getFields();
for (i = 0; i < allFields.length; i++)
{
Log.e("Field name", allFields[i].getName());
}
}
catch (SecurityException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}</b>
执行时直接使用:
<b>public static boolean pair(String strAddr, String strPsw)
{
boolean result = false;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter
.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
if (!bluetoothAdapter.isEnabled())
{
bluetoothAdapter.enable();
}
if (!BluetoothAdapter.checkBluetoothAddress(strAddr))
{ // 检查蓝牙地址是否有效
Log.d("mylog", "devAdd un effient!");
}
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(strAddr);
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
{
try
{
Log.d("mylog", "NOT BOND_BONDED");
ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(), device);
remoteDevice = device; // 配对完毕就把这个设备对象传给全局的remoteDevice
result = true;
}
catch (Exception e)
{
// TODO Auto-generated catch block
Log.d("mylog", "setPiN failed!");
e.printStackTrace();
} //
}
else
{
Log.d("mylog", "HAS BOND_BONDED");
try
{
ClsUtils.createBond(device.getClass(), device);
ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(), device);
remoteDevice = device; // 如果绑定成功,就直接把这个设备对象传给全局的remoteDevice
result = true;
}
catch (Exception e)
{
// TODO Auto-generated catch block
Log.d("mylog", "setPiN failed!");
e.printStackTrace();
}
}
return result;
}</b>
⑻ android自动匹配的下拉菜单快捷键怎么调出来
需要修改config.xml文件、String.xml文件和添加矢量图xml文件或添加一张png图片。锁屏开关点击时不需要动画,因此不添加动画xml文件
(1) 在\frameworks\base\packages\SystemUI\res\values\config.xml里找到 "quick_settings_ tiles_default",添加lockscreen,用“,”隔开:
<string name="quick_settings_tiles_default" translatable="false">
wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,hotspot,lockscreen
</string>
(2) 在\frameworks\base\packages\SystemUI\res\values\string.xml里添加:
<string name="quick_settings_lockscreen_label">
"lockscreen"
</string>
(3) 在\frameworks\base\packages\SystemUI\res\values values-zh-rCN\string.xml里添加:
<string name="quick_settings_lockscreen_label">"锁屏"</string>
其他语言在相应的values文件夹下对应的string.xml文件里添加。
(4) 在\frameworks\base\packages\SystemUI\res\drawable-hdpi文件夹里添加图片ic_qs_locks- creen.png,也可以在drawable文件夹下添加矢量图xml文件;
⑼ 如何让Android的浮动搜索框具有AutoCompleteTextView的自动匹配功能
其常用属性定义如下
<AutoCompleteTextView
android:id="@+id/mp002_top_place_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:layout_marginTop="5dp" >
</AutoCompleteTextView>
其中android:completionThreshold定义了从第几个字符开始显示候补列表
默认值为2
使用例:
AutoCompleteTextView mPlace = (AutoCompleteTextView)findViewById(R.id.mp002_top_place_input);
ArrayList<String> result = new ArrayList<String>();
result.add("1111111");
result.add("1222222");
mPlace.setAdapter(new ArrayAdapter<String>(
MP002TopActivity.this,
android.R.layout.simple_dropdown_item_1line,
result)
);
局限性是completionThreshold设定的最小值是1
小于1的情况下,会默认变成1。
所以要在不输入任何字符的条件下显示候补列表
就必须重载AutoCompleteTextView这个控件。
public class MyAutoCompleteTextView extends AutoCompleteTextView{
public MyAutoCompleteTextView(Context context) {
super(context);
}
public MyAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean enoughToFilter() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
performFiltering(getText(), KeyEvent.KEYCODE_UNKNOWN);
}
}