App that changes estimote beacon uuid, major and minor - android

I know how to use the estimote sdk to alter the beacon's uuid, major and minor values but I was wondering if there exists an .apk that already does this to save me time.

You can change Major, Minor, Broadcasting Power, Advertising interval at official app by Estimote.
But changing of UUID is possible only by SDK.

I leave the code here, maybe someone will find it usefull, It'a pretty much the same for the three of them, only changes the writeMajor.
private void setMajorID(final int majorid,final Beacon beacon) {
mMajorsConnection = new BeaconConnection(this, beacon, new BeaconConnection.ConnectionCallback() {
#Override
public void onAuthenticated(BeaconConnection.BeaconCharacteristics chars) {
Log.d(TAG, "Authenticated to beacon: " + chars);
mMajorsConnection.writeMajor(majorid, new BeaconConnection.WriteCallback() {
#Override
public void onSuccess() {
runOnUiThread(new Runnable() {
#Override
public void run() {
mAdapter.update(beacon);
}
});
Log.d(TAG, "Successfully writted the major id!");
mMajorsConnection.close();
}
#Override
public void onError() {
Log.d(TAG, "Error while writting the major id!");
}
});
}
#Override
public void onAuthenticationError() {
Log.d(TAG, "Authentication Error");
}
#Override
public void onDisconnected() {
Log.d(TAG, "Disconnected");
}
});
mMajorsConnection.authenticate();
}

Related

call to DJISDKManager.getInstance() hangs

I am trying to register a app with the DJI android SDK, but the call to DJISDKManager.getInstance() just hangs.
I am following the tutorial here: https://developer.dji.com/mobile-sdk/documentation/application-development-workflow/workflow-integrate.html
After the app verifies it has all the required permissions it calls startSDKRegistration:
I have the call to DJISDKManager.getInstance() on a single line for testing. It hangs on the call, and doesn't throw any errors.
private void startSDKRegistration() {
if (isRegistrationInProgress.compareAndSet(false, true)) {
Thread registrationThread = new Thread() {
#Override
public void run() {
showToast("registering, pls wait...");
try {
DJISDKManager temp = DJISDKManager.getInstance();
} catch (InterruptedException e) {
e.printStackTrace();
}
DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), new DJISDKManager.SDKManagerCallback() {
#Override
public void onRegister(DJIError djiError) {
if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
showToast("Register Success");
DJISDKManager.getInstance().startConnectionToProduct();
} else {
showToast("Register sdk fails, please check the bundle id and network connection!");
}
Log.v(TAG, djiError.getDescription());
}
#Override
public void onProductDisconnect() {
Log.d(TAG, "onProductDisconnect");
showToast("Product Disconnected");
notifyStatusChange();
}
#Override
public void onProductConnect(BaseProduct baseProduct) {
Log.d(TAG, String.format("onProductConnect newProduct:%s", baseProduct));
showToast("Product Connected");
notifyStatusChange();
}
#Override
public void onProductChanged(BaseProduct baseProduct) {
// there was nothing in the tutorial for this method
}
#Override
public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
BaseComponent newComponent) {
if (newComponent != null) {
newComponent.setComponentListener(new BaseComponent.ComponentListener() {
#Override
public void onConnectivityChange(boolean isConnected) {
Log.d(TAG, "onComponentConnectivityChanged: " + isConnected);
notifyStatusChange();
}
});
}
Log.d(TAG,
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
componentKey,
oldComponent,
newComponent));
}
#Override
public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
}
#Override
public void onDatabaseDownloadProgress(long l, long l1) {
}
});
}
};
GlobalParams.getInstance().getThreadPool().submit (registrationThread);
}
private void notifyStatusChange() {
mHandler.removeCallbacks(updateRunnable);
mHandler.postDelayed(updateRunnable, 500);
}
private Runnable updateRunnable = new Runnable() {
#Override
public void run() {
Intent intent = new Intent(FLAG_CONNECTION_CHANGE);
sendBroadcast(intent);
}
};
private void showToast(final String toastMsg) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(), toastMsg, Toast.LENGTH_LONG).show();
}
});
}
The problem occurs after Android Gradle plugin version 3.6.0+
https://developer.android.google.cn/studio/releases/gradle-plugin#3-6-0-behavior
Native libraries packaged uncompressed by default
When you build your app, the plugin now sets extractNativeLibs to "false" by default. That is, your native libraries are page aligned and packaged uncompressed. While this results in a larger upload size, your users benefit from the following:
Smaller app install size because the platform can access the native libraries directly from the installed APK, without creating a copy of the libraries.
Smaller download size because Play Store compression is typically better when you include uncompressed native libraries in your APK or Android App Bundle.
If you want the Android Gradle plugin to instead package compressed native libraries, include the following in your app's manifest:
<application
android:extractNativeLibs="true">
</application>
Question: What is the setting for minSdkVersion and targetSdkVersion?
I ask because there is a known issue with the values. I don't remember exactly but setting the following should work.
minSdkVersion 22
targetSdkVersion 29

Bluetooth scanning for devices

I have a problem with my code:
private ScanCallback mLeScanCallback = new ScanCallback(){
//Callback when a BLE advertisement has been found.
#Override
public void onScanResult(int callbackType, final android.bluetooth.le.ScanResult result) {
super.onScanResult(callbackType, result);
new Thread(){
#Override
public void run() {
final BluetoothDevice device = result.getDevice();
runOnUiThread(new Runnable() {
#Override
public void run() {
if (device != null){
mDevices.add(device);
}
}
});
}
}.start();
}
//Callback when batch results are delivered.
#Override
public void onBatchScanResults(List<android.bluetooth.le.ScanResult> results) {
super.onBatchScanResults(results);
}
//Callback when scan could not be started.
#Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
currently I am using this code to get the results of my scan. This was based on: https://github.com/RedBearLab/Android/blob/master/Examples/Chat/src/com/redbear/chat/Main.java#L138
The app where is was based on had a lower API level, and my app has a higher one. So I changed it to on startScan() method.
I am honestly stuck, because when I run the app i get no errors. I checked if the mDevices array is empty and it is. Meaning that the code doesn't add the devices to the array or that there aren't any devices to be found by my app specifically.
Any help would be greatly appreciated.
Code of activating scanning
private void scanDevice(){
new Thread() {
#Override
public void run(){
BTScanner.startScan(mLeScanCallback);
try {
Thread.sleep(SCAN_PERIOD);
} catch (InterruptedException e){
e.printStackTrace();
}
BTScanner.stopScan(mLeScanCallback);
}
}.start();
}
Found the problem. It has to do with the permissions for ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION to get the scan results.

Android NSD onServiceFound() not getting called

First time trying to do IP Discovery in Android. I used the http://developer.android.com/training/connect-devices-wirelessly/nsd.html#discover and wrote the code. I am not registering the device, just Discovering Services in the network. When I run the project in emulator or device the onDiscoveryStarted() gets called, but the onServiceFound() is never called. Please find my Code below. Any input is much appreciated. Thanks!
public class MainActivity extends AppCompatActivity {
private Button discoverButton;
Context mContext;
NsdManager mNsdManager;
NsdManager.ResolveListener mResolveListener;
NsdManager.DiscoveryListener mDiscoveryListener;
NsdManager.RegistrationListener mRegistrationListener;
public static final String SERVICE_TYPE = "_http._tcp.";
public static final String TAG = "MyApp_MAIN_CLIENT";
public String mServiceName = "MyApp";
/*
* public static final String SERVICE_TYPE = "_http._tcp.";
public static final String TAG = "NsdHelper";
public String mServiceName = "NsdChat";
* */
NsdServiceInfo mService;
private Handler mUpdateHandler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNsdManager = (NsdManager) this.getSystemService(Context.NSD_SERVICE);
discoverButton = (Button) findViewById(R.id.netButton);
discoverButton.setOnClickListener(new View.OnClickListener() {
public void onClick(android.view.View v) {
initializeDiscoveryListener();
initializeResolveListener();
discoverServices();
}
});
}
public void discoverServices() {
mNsdManager.discoverServices(
SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
}
public void initializeDiscoveryListener() {
// Instantiate a new DiscoveryListener
mDiscoveryListener = new NsdManager.DiscoveryListener() {
// Called as soon as service discovery begins.
#Override
public void onDiscoveryStarted(String regType) {
Log.d(TAG, "Service discovery started");
}
#Override
public void onServiceFound(NsdServiceInfo service) {
// A service was found! Do something with it.
Log.d(TAG, "Service discovery success" + service);
if (!service.getServiceType().equals(SERVICE_TYPE)) {
// Service type is the string containing the protocol and
// transport layer for this service.
Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
} /*else if (service.getServiceName().equals(mServiceName)) {
// The name of the service tells the user what they'd be
// connecting to. It could be "Bob's Chat App".
Log.d(TAG, "Same machine: " + mServiceName);
}
//else if (service.getServiceName().contains("NsdChat")){*/
else{
mNsdManager.resolveService(service, mResolveListener);
}
}
#Override
public void onServiceLost(NsdServiceInfo service) {
// When the network service is no longer available.
// Internal bookkeeping code goes here.
Log.e(TAG, "service lost" + service);
}
#Override
public void onDiscoveryStopped(String serviceType) {
Log.i(TAG, "Discovery stopped: " + serviceType);
}
#Override
public void onStartDiscoveryFailed(String serviceType, int errorCode) {
Log.e(TAG, "Discovery failed: Error code:" + errorCode);
mNsdManager.stopServiceDiscovery(this);
}
#Override
public void onStopDiscoveryFailed(String serviceType, int errorCode) {
Log.e(TAG, "Discovery failed: Error code:" + errorCode);
mNsdManager.stopServiceDiscovery(this);
}
};
}// end of initializeListener()
public void initializeResolveListener() {
mResolveListener = new NsdManager.ResolveListener() {
#Override
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
Log.e(TAG, "Resolve failed" + errorCode);
}
#Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
if (serviceInfo.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same IP.");
return;
}
mService = serviceInfo;
int port = mService.getPort();
InetAddress host = mService.getHost();
Log.d(TAG,host.toString());
}
};
}//end of initializeResolveListener
#Override
protected void onPause() {
super.onPause();
stopDiscovery();
tearDown();
}
#Override
protected void onResume() {
super.onResume();
discoverServices();
}
#Override
protected void onDestroy() {
tearDown();
super.onDestroy();
}
public void stopDiscovery() {
mNsdManager.stopServiceDiscovery(mDiscoveryListener);
}
public void tearDown() {
mNsdManager.unregisterService(mRegistrationListener);
}
}
From NdsManager documentation page:
The API currently supports DNS based service discovery and discovery
is currently limited to a local network over Multicast DNS.
From this Local networking limitations emulator docs page:
Currently, the emulator does not support IGMP or multicast.
Hope this will help you
Probably due to the age of this post, I hope you already found a solution.
If not, my experience is that the Android Emulator (API level 25) does not provide a full network stack and the service discovery through NSD isn't working.
I switched to debugging on a real device (like an Android TV or tablet) and then my whole NSD/Bonjour-like setup was working. The methods of the DiscoveryListener and the ResolveListener were called and an IP and port (in my case) were retrieved.
After some hours working with Android NSD, I discovered that this library does not work with routers that don't support Multicast. While the other answers may are correct, this could also be the cause of your problem. Possible solutions: enable Multicast on your router if possible, or use another network library.
The Network Service Discovery Manager class provides the API to discover services on a network.
This will work when your device is connected to the same WIFI network as that of the device providing the service.
Hope this helps!!
Happy Coding!!

SpeechRecognizer throws onError on the first listening

In the Android 5 I faced with strange problem. The first call to the startListening of SpeechRecognizer results to the onError with error code 7 (ERROR_NO_MATCH).
I made test app with the following code:
if (speechRecognizer == null) {
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizer.setRecognitionListener(new RecognitionListener() {
#Override
public void onReadyForSpeech(Bundle bundle) {
Log.d(TAG, "onReadyForSpeech");
}
#Override
public void onBeginningOfSpeech() {
Log.d(TAG, "onBeginningOfSpeech");
}
#Override
public void onRmsChanged(float v) {
Log.d(TAG, "onRmsChanged");
}
#Override
public void onBufferReceived(byte[] bytes) {
Log.d(TAG, "onBufferReceived");
}
#Override
public void onEndOfSpeech() {
Log.d(TAG, "onEndOfSpeech");
}
#Override
public void onError(int i) {
Log.d(TAG, "onError " + i);
}
#Override
public void onResults(Bundle bundle) {
Log.d(TAG, "onResults");
}
#Override
public void onPartialResults(Bundle bundle) {
Log.d(TAG, "onPartialResults");
}
#Override
public void onEvent(int i, Bundle bundle) {
Log.d(TAG, "onEvent");
}
});
}
final Intent sttIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en");
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
speechRecognizer.startListening(sttIntent);
And have this log messages after first startListening call:
onError 7
onReadyForSpeech
onBeginningOfSpeech
onEndOfSpeech
onResults
And following messages after another startListening calls:
onRmsChanged
...
onRmsChanged
onReadyForSpeech
onRmsChanged
...
onRmsChanged
onBeginningOfSpeech
onRmsChanged
...
onRmsChanged
onEndOfSpeech
onRmsChanged
onRmsChanged
onRmsChanged
onResults
So, what is the reason of this error and how do I fix it?
As soon as you configure the "Okay Google" function to every screen the error appears.
So this seems to be the reason!
Deactivate the function and the problem should be solved
Done one workaround.
This is a regular flow
onReadyForSpeech -->onBeginningOfSpeech-->onEndOfSpeech -->onResults
But weired flow
onError(no match) -->onReadyForSpeech -->onBeginningOfSpeech-->onEndOfSpeech -->onResults
So set a boolean on the end of speech to true. and check onError to make sure that it has thrown an error after an end of speech!
speech.startListening(recognizerIntent);
isEndOfSpeech = false;
#Override
public void onError(int error) {
if (!isEndOfSpeech)
return;
}
#Override
public void onEndOfSpeech() {
isEndOfSpeech = true;
}
I had the same problem but I couldn't find a workaround, so I ended up just calling return inside onError if the time between startListening and onError is unreasonably short.
protected long mSpeechRecognizerStartListeningTime = 0;
protected synchronized void speechRecognizerStartListening(Intent intent) {
if (mSpeechRecognizer != null) {
this.mSpeechRecognizerStartListeningTime = System.currentTimeMillis();
RLog.d(this, "speechRecognizerStartListening");
this.mSpeechRecognizer.startListening(intent);
}
}
...
#Override
public synchronized void onError(int error) {
RLog.i(this, this.hashCode() + " - onError:" + error);
// Sometime onError will get called after onResults so we keep a boolean to ignore error also
if (mSuccess) {
RLog.w(this, "Already success, ignoring error");
return;
}
long duration = System.currentTimeMillis() - mSpeechRecognizerStartListeningTime;
if (duration < 500 && error == SpeechRecognizer.ERROR_NO_MATCH) {
RLog.w(this, "Doesn't seem like the system tried to listen at all. duration = " + duration + "ms. This might be a bug with onError and startListening methods of SpeechRecognizer");
RLog.w(this, "Going to ignore the error");
return;
}
// -- actual error handing code goes here.
}
I had the same problem on several devices. It seems onError(7) is always called before onReadyForSpeech(), so if to avoid using ugly times, you can do something like:
public void start(){
performingSpeechSetup = true;
speechRecognizer.startListening(intent);
}
and in the RecognitionListener:
public void onReadyForSpeech(Bundle bundle) {
performingSpeechSetup = false;
}
#Override
public void onError(int error) {
if (performingSpeechSetup && error == SpeechRecognizer.ERROR_NO_MATCH) return;
// else handle error
}
Turned out to be very easy in my case. The launching sound of the voice recognition was too loud and triggered the listening process at the very beginning. Turn down the system sound would help. (The volume key)

Android Estimote sdk is not able to scan other beacons than the estimote ones

I am trying to see beacons with the estimote sdk in android but with no luck!I can see all the estimote beacons but with all other beacons is not working (fobo beacons etc.) I am using the uuid for the fobo beacons inside the Region constructor and i can see in the logcat that the bluetooth can see the devices but estimode sdk is not collecting it as a beacon!Any ideas why this is happening? I m posting the code below:
private static final String FOBO_PROXIMITY_UUID = "00158800-587d-2206-d52b-fb6d6e2f0001";
private static final Region FOBOBEACONS = new Region("rid", FOBO_PROXIMITY_UUID , null, null);
public void BeaconManager(){
beaconManager = new com.estimote.sdk.BeaconManager(this);
beaconManager.setBackgroundScanPeriod(5000, 30000);
beaconManager.setForegroundScanPeriod(7000, 5000);
beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener() {
#Override
public void onBeaconsDiscovered(final Region arg0, final List<Beacon> arg1) {
// TODO Auto-generated method stub
runOnUiThread(new Runnable() {
#Override
public void run() {
// Note that beacons reported here are already sorted by estimated
// distance between device and beacon.
int test=0;
if(arg1.size()<=0){
Toast.makeText(MainActivity.this, "No beacon found",
Toast.LENGTH_SHORT).show();
}else{
for (int i = 0; i < arg1.size(); i++) {
String beac=arg1.get(i).getProximityUUID();
Toast.makeText(MainActivity.this, "I found a beacon with UUID; "+beac,
Toast.LENGTH_SHORT).show();
}
}
// adapter.replaceWith(beacons);
}
});
}
});
connectToService();
}
private void connectToService() {
beaconManager.connect(new com.estimote.sdk.BeaconManager.ServiceReadyCallback() {
#Override
public void onServiceReady() {
try {
com.estimote.sdk.utils.L.enableDebugLogging(true);
beaconManager.startRanging(FOBOBEACONS);
} catch (RemoteException e) {
Toast.makeText(MainActivity.this, "Cannot start ranging, something terrible happened",
Toast.LENGTH_LONG).show();
}
}
});
}
This is Wojtek Borowicz, I'm a community evangelist at Estimote. Actually, Estimote SDK does not support Beacons from other vendors - that's why you cannot detect them.
Cheers.
Maybe check this link.. not tried it yet myself but plan to at some point.
https://github.com/AlvinBert
An Android source code of iBeacon SDK. without any limit on Android.
It can detect all iBeacons.

Categories

Resources