⑴ 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);
}
}