當前位置: 首頁>>代碼示例>>Java>>正文


Java Intent.getShortExtra方法代碼示例

本文整理匯總了Java中android.content.Intent.getShortExtra方法的典型用法代碼示例。如果您正苦於以下問題:Java Intent.getShortExtra方法的具體用法?Java Intent.getShortExtra怎麽用?Java Intent.getShortExtra使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.Intent的用法示例。


在下文中一共展示了Intent.getShortExtra方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReceive

import android.content.Intent; //導入方法依賴的package包/類
@Override
        public void onReceive(Context context, Intent intent)
        {
            String action = intent.getAction();

            // When discovery finds a device
            if (BluetoothDevice.ACTION_FOUND.equals(action))
            {
                // Get the BluetoothDevice object from the Intent
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                // Get rssi value
                short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,  Short.MIN_VALUE);

                // If it's already paired, skip it, because it's been listed already
                if (device.getBondState() != BluetoothDevice.BOND_BONDED)
                {
                    NLog.d( "ACTION_FOUND SPP : " +device.getName() + " address : "+ device.getAddress()+", COD:" + device.getBluetoothClass());

                    mNewDevicesArrayAdapter.add(device.getName() + "\n" + "[RSSI : "+rssi +"dBm] " + device.getAddress());
//                    mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()+"\n Major"+device.getBluetoothClass().toString()+"\nDeviceClass()"+device.getBluetoothClass().getDeviceClass()+"device="+device.getType());

                }
            // When discovery is finished, change the Activity title
            }
            else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
            {
                setProgressBarIndeterminateVisibility(false);
                setTitle(R.string.select_device);

                if (mNewDevicesArrayAdapter.getCount() == 0)
                {
                    String noDevices = getResources().getText(R.string.none_found).toString();
                    mNewDevicesArrayAdapter.add(noDevices);
                }
            }
        }
 
開發者ID:NeoSmartpen,項目名稱:AndroidSDK2.0,代碼行數:38,代碼來源:DeviceListActivity.java

示例2: scanNetworks

import android.content.Intent; //導入方法依賴的package包/類
@ProtoMethod(description = "Scan bluetooth networks. Gives back the name, mac and signal strength", example = "")
@ProtoMethodParam(params = {"function(name, macAddress, strength)"})
public void scanNetworks(final ReturnInterface callbackfn) {
    MLog.d(TAG, "scanNetworks");
    start();

    mAdapter.startDiscovery();
    BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);

                ReturnObject o = new ReturnObject();
                String name = device.getName();
                if (name == null) name = "";

                o.put("name", name);
                o.put("mac", device.getAddress());
                o.put("strength", rssi);
                callbackfn.event(o);
            }
        }
    };

    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    getContext().registerReceiver(mReceiver, filter);

}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:33,代碼來源:PBluetooth.java


注:本文中的android.content.Intent.getShortExtra方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。