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


Java ScanCallback類代碼示例

本文整理匯總了Java中android.bluetooth.le.ScanCallback的典型用法代碼示例。如果您正苦於以下問題:Java ScanCallback類的具體用法?Java ScanCallback怎麽用?Java ScanCallback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: onCreate

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // initialize the right scan callback for the current API level
    if (Build.VERSION.SDK_INT >= 21) {
        mScanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                super.onScanResult(callbackType, result);
                mRecyclerViewAdapter.addDevice(result.getDevice().getAddress());
            }
        };
    } else {
        mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
            @Override
            public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) {
                mRecyclerViewAdapter.addDevice(bluetoothDevice.getAddress());
            }
        };
    }

    // initialize bluetooth manager & adapter
    BluetoothManager manager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = manager.getAdapter();
}
 
開發者ID:martindisch,項目名稱:SensorTag-Accelerometer,代碼行數:27,代碼來源:ScanFragment.java

示例2: errorCodeToBleErrorCode

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@BleScanException.Reason private static int errorCodeToBleErrorCode(int errorCode) {
    switch (errorCode) {
        case ScanCallback.SCAN_FAILED_ALREADY_STARTED:
            return BleScanException.SCAN_FAILED_ALREADY_STARTED;
        case ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
            return BleScanException.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED;
        case ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED:
            return BleScanException.SCAN_FAILED_FEATURE_UNSUPPORTED;
        case ScanCallback.SCAN_FAILED_INTERNAL_ERROR:
            return BleScanException.SCAN_FAILED_INTERNAL_ERROR;
        case 5: // ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES
            return BleScanException.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES;
        default:
            RxBleLog.w("Encountered unknown scanning error code: %d -> check android.bluetooth.le.ScanCallback");
            return BleScanException.UNKNOWN_ERROR_CODE;
    }
}
 
開發者ID:Polidea,項目名稱:RxAndroidBle,代碼行數:18,代碼來源:ScanOperationApi21.java

示例3: startDiscoveringBle

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
private boolean startDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ startDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "startDiscoveringBle() : Already in classic discovering mode");
		return true;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "startDiscoveringBle() : Choose startScan()");
		mLeScanner = mAdapter.getBluetoothLeScanner();
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).startScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.startScan(mScanCallback); ???
	} else {
		Log.i(TAG, "startDiscoveringBle() : Choose startLeScan()");
		return mAdapter.startLeScan(mLeScanCallback);
	}
	return true;
}
 
開發者ID:BohanLu,項目名稱:NobleAries,代碼行數:27,代碼來源:Chores.java

示例4: onListItemClick

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
protected void onListItemClick(ListView l, View v, int position, long id) {
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null) return;
    final Intent intent = new Intent(this, DeviceControlActivity.class);
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
    if (mScanning) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBluetoothLeScanner.stopScan(new ScanCallback() {});
        } else {
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
        mScanning = false;
    }
    startActivity(intent);
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:20,代碼來源:DeviceScanActivity.java

示例5: BluetoothLeScanL21Proxy

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BluetoothLeScanL21Proxy(BluetoothAdapter bluetoothAdapter) {

    mBluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();

    mLeScanCallback = new ScanCallback() {

        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            super.onScanResult(callbackType, result);
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:24,代碼來源:BluetoothLeScanL21Proxy.java

示例6: cancelDiscoveringBle

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
private boolean cancelDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ cancelDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "cancelDiscoveringBle() : In classic discovering mode");
		return false;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopScan()");
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).stopScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.stopScan(mScanCallback); ???
	} else {
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopLeScan()");
		mAdapter.stopLeScan(mLeScanCallback);
	}
	return true;
}
 
開發者ID:BohanLu,項目名稱:NobleAries,代碼行數:26,代碼來源:Chores.java

示例7: scanFailureToString

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
/**
 * Returns the corresponding constant name for a
 * given {@code ScanCallback#SCAN_FAILED_*} value.
 */
public static String scanFailureToString(int scanFailure) {
    switch (scanFailure) {
        case ScanCallback.SCAN_FAILED_ALREADY_STARTED:
            return "SCAN_FAILED_ALREADY_STARTED";

        case ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
            return "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED";

        case ScanCallback.SCAN_FAILED_INTERNAL_ERROR:
            return "SCAN_FAILED_INTERNAL_ERROR";

        case ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED:
            return "SCAN_FAILED_FEATURE_UNSUPPORTED";

        default:
            return "UNKNOWN: " + scanFailure;
    }
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:23,代碼來源:LowEnergyScanException.java

示例8: startScan

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
public static void startScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.startScan(callback);
}
 
開發者ID:pangliang,項目名稱:miband-sdk-android,代碼行數:14,代碼來源:MiBand.java

示例9: stopScan

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
public static void stopScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.stopScan(callback);
}
 
開發者ID:pangliang,項目名稱:miband-sdk-android,代碼行數:14,代碼來源:MiBand.java

示例10: BTLEScannerOld

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
public BTLEScannerOld(BluetoothAdapter bluetoothAdapter, Callback callback) {
    this.bluetoothAdapter = bluetoothAdapter;
    this.leScanCallback = callback::onScan;

    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        this.leScanner = bluetoothAdapter.getBluetoothLeScanner();

        this.scanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
                    callback.onScan(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());
                }

                super.onScanResult(callbackType, result);
            }
        };
    } else {
        this.leScanner = null;
        this.scanCallback = null;
    }
}
 
開發者ID:devicehive,項目名稱:android-ble,代碼行數:23,代碼來源:BTLEScannerOld.java

示例11: startScan

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
public void startScan() {
    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        leScanner.startScan(new android.bluetooth.le.ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {

                super.onScanResult(callbackType, result);
            }

            @Override
            public void onBatchScanResults(List<ScanResult> results) {
                super.onBatchScanResults(results);
            }
        });
    } else {
        bluetoothAdapter.startLeScan(leScanCallback);
    }
}
 
開發者ID:devicehive,項目名稱:android-ble,代碼行數:19,代碼來源:BTLEScannerOld.java

示例12: getScanCallback

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@NonNull
private ScanCallback getScanCallback(final byte[] serviceData) {
    return new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                processResult(result);
            }

            @Override
            public void onBatchScanResults(List<ScanResult> results) {
                for (ScanResult s: results) {
                    processResult(s);
                }
            }

            @Override
            public void onScanFailed(int errorCode) {
                Log.d(TAG, "Scan failed: " + String.valueOf(errorCode));
            }

            public void processResult(ScanResult sr) {
                Log.d(TAG, "Found device " + sr.getDevice().getName() + "(" + sr.getDevice().getAddress() + ")");

                /* confirm correct connection key */
                byte[] sd = sr.getScanRecord().getServiceData(Constants.SERVICE_pUUID);
                if (sd != null) {
                    if (Arrays.equals(sd, serviceData)) {
                        BTConnection.this.stopScan();
                        transfer.startServer(sr.getDevice());
                    } else {
                        Log.d(TAG, "Incorrect service data: " + new String(sd) + " instead of " + new String(serviceData) + ". Continuing.");
                    }
                } else {
                    Log.d(TAG, "No service data received -- continuing.");
                }
            }
        };
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:39,代碼來源:BTConnection.java

示例13: initCallbacks

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
private ScanCallback initCallbacks() {
    return new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            super.onScanResult(callbackType, result);

            if (result != null && result.getDevice() != null) {
                if (isAdded(result.getDevice())) {
                    // No add
                } else {
                    saveDevice(result.getDevice());
                }
            }

        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };
}
 
開發者ID:jphacks,項目名稱:KB_1711,代碼行數:28,代碼來源:MainActivity.java

示例14: bleStopScan

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
/**
 * Stop a BLE scan.
 *
 * @param callbackId The callbackId corresponding to the {@link
 *     BluetoothLeScannerSnippet#bleStartScan} call that started the scan.
 * @throws BluetoothLeScanSnippetException
 */
@RpcMinSdk(Build.VERSION_CODES.LOLLIPOP_MR1)
@Rpc(description = "Stop a BLE scan.")
public void bleStopScan(String callbackId) throws BluetoothLeScanSnippetException {
    ScanCallback callback = mScanCallbacks.remove(callbackId);
    if (callback == null) {
        throw new BluetoothLeScanSnippetException("No ongoing scan with ID: " + callbackId);
    }
    mScanner.stopScan(callback);
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:17,代碼來源:BluetoothLeScannerSnippet.java

示例15: shutdown

import android.bluetooth.le.ScanCallback; //導入依賴的package包/類
@Override
public void shutdown() {
    for (ScanCallback callback : mScanCallbacks.values()) {
        mScanner.stopScan(callback);
    }
    mScanCallbacks.clear();
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:8,代碼來源:BluetoothLeScannerSnippet.java


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