我正在使用Context来访问WifiManager和BluetoothManager等系统级服务.如何使用Mockito模拟这个getApplicationContext()?
我正在尝试使用Gimbal sdk创建一个Android应用程序来检测基于Gimbal的信标,但我的应用程序无法检测到信标.但如果我尝试使用BluetoothGATT,我就能够检测到信标.以下是我的代码中侦听信标事件的部分.API密钥验证成功,但仍然无法显示邻近度.
public class MainActivity extends Activity {
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
private BeaconEventListener beaconEventListener;
private BeaconManager beaconManager;
private String TAG = "beacon";
public ArrayAdapter<String> listAdapter;
public ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
Gimbal.setApiKey(getApplication(),
"MY API KEY ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
monitorPlace();
listenBeacon();
CommunicationManager.getInstance().startReceivingCommunications();
}
private void listenBeacon() {
BeaconEventListener beaconEventListener = getBeaconEventListener();
BeaconManager beaconManager = new BeaconManager();
beaconManager.addListener(beaconEventListener);
beaconManager.startListening();
}
private void monitorPlace() {
placeEventListener = getPlaceEventListener();
// placeManager = PlaceManager.getInstance();
// placeManager.addListener(placeEventListener);
placeManager = …
Run Code Online (Sandbox Code Playgroud) 我有两个多行字符串.我正在使用以下代码来确定其中两个之间的相似性.这利用了Levenshtein距离算法.
public static double similarity(String s1, String s2) {
String longer = s1, shorter = s2;
if (s1.length() < s2.length()) {
longer = s2; shorter = s1;
}
int longerLength = longer.length();
if (longerLength == 0) { return 1.0; /* both strings are zero length */ }
return (longerLength - editDistance(longer, shorter)) / (double) longerLength;
}
public static int editDistance(String s1, String s2) {
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
int[] costs = new int[s2.length() + 1];
for (int i …
Run Code Online (Sandbox Code Playgroud) 我创建了一个Android应用程序,使用蓝牙LE扫描程序扫描BLE.现在我需要我的应用程序来识别信标是否属于iBeacon或Eddystone.到目前为止,我通过解析AD帧成功地确定了ibeacon的UUID,MajorId,MinorId.