Unable to get the major and minor values of an estimote beacon to persist into a database - estimote

I am trying to build an Enterprise App using ibeacons. I purchased Estimote Beacons Kit and trying to build an Android application to get the ID of each beacon, so that I can persist that ID into a Database and write my own business logic for the application.
Can any one help me out to range the beacons. I done with monitoring beacons and sending a Notification accordingly. Now I want only to range the Beacons and get the ID's. Please help with the code to get the beacon major and minor values so that I can kick start my app from there on-words.

You can use Estimote Android SDK for that. See quickstart which is beacon ranging:
private BeaconManager beaconManager = new BeaconManager(context);
// Should be invoked in #onCreate.
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
#Override public void onBeaconsDiscovered(Region region, List<Beacon> beacons) {
Log.d(TAG, "Ranged beacons: " + beacons);
}
});
// Should be invoked in #onStart.
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
#Override public void onServiceReady() {
try {
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
} catch (RemoteException e) {
Log.e(TAG, "Cannot start ranging", e);
}
}
});
// Should be invoked in #onStop.
try {
beaconManager.stopRanging(ALL_ESTIMOTE_BEACONS);
} catch (RemoteException e) {
Log.e(TAG, "Cannot stop but it does not matter now", e);
}
// When no longer needed. Should be invoked in #onDestroy.
beaconManager.disconnect();

Related

Gdx-Pay find previous purchases

I'm using Gdx-Pay for cross-platforming my IAP's.
Everything is set up from Libgdx's wiki like:
if(PurchaseSystem.hasManager()){
config = new PurchaseManagerConfig();
config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item1));
config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item2));
config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item3));
config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item4));
//Stores
config.addStoreParam(PurchaseManagerConfig.STORE_NAME_ANDROID_GOOGLE, base64EncodedKey);
config.addStoreParam(PurchaseManagerConfig.STORE_NAME_IOS_APPLE, base64EncodedKey); // <-- CHANGE KEY
PurchaseSystem.install(new PurchaseObserver() {
#Override
public void handleInstall() {
message(" - purchase manager installed: " + PurchaseSystem.storeName() + ".\n");
// restore purchases
message(" - do a restore to check inventory\n");
//PurchaseSystem.purchaseRestore();
}
#Override
public void handleInstallError(Throwable e) {
message(" - error installing purchase manager: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
#Override
public void handleRestore(Transaction[] transactions) {
// keep note of our purchases
message(" - totally " + transactions.length + " purchased products\n");
for (int i = 0; i < transactions.length; i++) {
if(transactions[i].getIdentifier().equals(item1)) {
item1_purchased = true;
}
if(transactions[i].getIdentifier().equals(item2)) {
item2_purchased = true;
}
if(transactions[i].getIdentifier().equals(item3)) {
item3_purchased = true;
}
if(transactions[i].getIdentifier().equals(item4)) {
item4_purchased = true;
}
}
}
#Override
public void handleRestoreError(Throwable e) {
message(" - error during purchase manager restore: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
#Override
public void handlePurchase(Transaction transaction) {
message(" - purchased: " + transaction.getIdentifier() + "\n");
// dispose the purchase system
Gdx.app.postRunnable(new Runnable() {
#Override
public void run () {
message(" - disposing the purchase manager.\n");
PurchaseSystem.dispose();
message("Testing InApp System: COMPLETED\n");
}
});
}
#Override
public void handlePurchaseError(Throwable e) {
message(" - error purchasing: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
#Override
public void handlePurchaseCanceled() {
message(" - purchase cancelled.\n");
// dispose the purchase system
Gdx.app.postRunnable(new Runnable() {
#Override
public void run () {
message(" - user canceled! - disposing the purchase manager.\n");
PurchaseSystem.dispose();
message("Testing InApp System: COMPLETED\n");
}
});
}
},config);
} else {
utils.toast_error("Connection failure, check your internet's connection");
}
This is executed on my "create()" method in core class.
What I cannot work out is the relation between Android & IOS IAP.
Apple have a strict rule that purchase can only be "restored" on a button.
But I find it extremely inconvenient to force the user into pressing a button every time they want to use a product in my app.
I have a table of products with buttons under each one saying either "Purchase"/"Use" , depending on if they have purchased the product or not.
So what I would find very pleasing is to have a method that simply "checks" if the user has ownership on each product when the app starts, and apply flags(booleans) as I iterate through the list.
I thought I could use "handleRestore()" for that as shown in my code. But apparently (I'm not sure), iterating through that list to check for purchases will make Apple decline my app since it will happen without the user's request.
So can I somehow just CHECK for purchases from the users Google/Apple account without executing a RESTORE request?
An alternate is to store the state of the purchases in a preference file and read from that when the app is launched. This will work both with android and ios.
On iOS you are supposed to keep track of what has been purchased yourself. e.g. when a user purchases something, write a file or a preference or some other persistent thing to keep track.
Apple spell it out here: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html#//apple_ref/doc/uid/TP40008267-CH5-SW3
After making the product available, your app needs to make a
persistent record of the purchase. Your app uses that persistent
record on launch to continue to make the product available. It also
uses that record to restore purchases, as described in Restoring
Purchased Products. Your app’s persistence strategy depends the type
of products you sell and the versions of iOS.
On Android you can do that as well, or on Android you can basically call 'Restore Purchases' on startup and let Android keep track of whats been bought.

Create delegate method for location status change event for windows phone 8.1

I am currently working with windows phone 8.1 [RT] application , I am using GeoLocation for map service , I want event that occur whenever device location is on/off , same as NetworkStatusChangedEventHandler for internet connection .
I have create following code for that
public static bool IsLocationOn
{
get
{
Geolocator locator = new Geolocator();
if (locator.LocationStatus == PositionStatus.Disabled)
{
return false;
}
else
{
return true;
}
}
}
but I want event that fire on entire application
Thank you
Geolocator has a StatusChanged event. From there, it's just a matter of subscribing to it.
locator.StatusChanged += Geolocator_StatusChanged;
private void Geolocator_StatusChanged(Geolocator locator, StatusChangedEventArgs e)
{
// Whatever
}

service.files().list().setQ("sharedWithMe") doesn't return files shared by my Android App

I have successfully uploaded a file to Drive and inserted permissions of another account to share. All this is working. But when I try from the other account to list out the shared files for download, it returns that there are no files.
Does anyone know how to retreive files that are shared from another user?
Here is what I've tried.
private class RetrieveAllShareFiles extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... arg0) {
Files.List request = null;
try {
request = service.files().list().setQ("sharedWithMe");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
do {
try {
FileList files = request.execute();
filesResult.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
} catch (IOException e) {
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
} while (request.getPageToken() != null &&
request.getPageToken().length() > 0);
return "Executed";
}
When using the drive.files scope your app will only be able to access files that you have created with it or that the user is opening from the Drive UI.
When the file is shared with another user, he won't be able to see it using the drive.files scope. For this use case you should request access to the full Drive scope.
Check the documentation for more details on the available OAuth scopes: https://developers.google.com/drive/scopes

Android App: Acquire Access Token for Google Drive API

I am writing an Android (version ICS) app. which uploads data to the Google Drive. The app
uses oauth2 to acquire the access token.
First step: acquire authorization token.
String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/drive";
// Step 1
accountManager.getAuthToken(
account, // Account retrieved using getAccountsByType("com.google")
AUTH_TOKEN_TYPE, // Auth Token Type
options, // Authenticator-specific options
this, // Your activity
new OnTokenAcquired(), // Callback called when a token is successfully acquired
new Handler(new OnAuthTokenError())); // Callback called if an error occurs
}
private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
#Override
public void run(AccountManagerFuture<Bundle> result) {
// Get the result of the operation from the AccountManagerFuture.
Bundle bundle;
try {
bundle = result.getResult();
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
Log.d(TAG,"authToken:" + authToken);
exchangeToken access = (exchangeToken) new exchangeToken().execute();
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Success. An authorization token is acquired.
Step 2: Exchange authorization token for Access Token.
private class exchangeToken extends AsyncTask<String, Void, Void> {
#Override
protected Void doInBackground(String... params) {
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new GsonFactory();
String CLIENT_ID = "999999999999.apps.googleusercontent.com";
String CLIENT_SECRET = "axXXXXXXXXXXXXXXX7";
try { // Step 2: Exchange for an access and refresh token
GoogleTokenResponse authResponse = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, authToken, CALLBACK_URL).execute();
accessToken = authResponse.getAccessToken();
Log.d("Get Access","Token:" + accessToken);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Fail. The LogCat shows the following:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error":"unauthorized_client"
}
I have been able to access "Google Drive" on my Android tablet using the "Drive" app. so
my email account is valid. May be the AUTH_TOKEN_TYPE is incorrect, but the Google Drive
SDK is not clear what it must be. What am I missing?
You do not need to do the second step of exchanging the token. Android grants you an access token directly, it does not grant you an auth code which you would have to exchange for tokens.
This page on the Android documentation explains everything really well.
You know that for using the Drive API your users have to install your app on the Chrome(!) Webstore?
Normally Documents List API is the better choice from Android.

NullPointerException error on Implementing Location API on J2me

I am trying to implement jsr-179 APi into Nokia Symbian phone for periodic location update using setLocationListener through J2me. In emulator it is working fine. While I installed Midlet on the device nokia 5230, it is given NullPointerException and the application is automatically terminating. What might be possible causes?
Below is my class, I am instantiating object for this class on a form in netbeans
class MovementTracker implements LocationListener {
LocationProvider provider;
Location lastValidLocation;
UpdateHandler handler;
boolean done;
public MovementTracker() throws LocationException
{
done = false;
handler = new UpdateHandler();
new Thread(handler).start();
//Defining Criteria for Location Provider
/*
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(500);
*/
//you can place cr inside getInstance
provider = LocationProvider.getInstance(null);
//listener,interval,timeout,int maxAge
//Passing -1 selects default interval
// provider.setLocationListener(MovementTracker.this, -1, -1, -1);
provider.setLocationListener(MovementTracker.this, -1, 30000, 30000);
}
public void locationUpdated(LocationProvider provider, Location location)
{
handler.handleUpdate(location);
batteryLevel = System.getProperty("com.nokia.mid.batterylevel");
sn = System.getProperty("com.nokia.mid.networksignal");
localTime = System.currentTimeMillis();
Send_Location();
}
public void providerStateChanged(LocationProvider provider, int newState)
{
}
class UpdateHandler implements Runnable
{
private Location updatedLocation = null;
// The run method performs the actual processing of the location
public void run()
{
Location locationToBeHandled = null;
while (!done)
{
synchronized(this)
{
if (updatedLocation == null)
{
try
{
wait();
}
catch (Exception e)
{
// Handle interruption
}
}
locationToBeHandled = updatedLocation;
updatedLocation = null;
}
// The benefit of the MessageListener is here.
// This thread could via similar triggers be
// handling other kind of events as well in
// addition to just receiving the location updates.
if (locationToBeHandled != null)
processUpdate(locationToBeHandled);
}
try
{
Thread.sleep(10000); //Sleeps for 10 sec & then sends the data
}
catch (InterruptedException ex)
{
}
}
public synchronized void handleUpdate(Location update)
{
updatedLocation = update;
notify();
}
private void processUpdate(Location update)
{
latitude = update.getQualifiedCoordinates().getLatitude();
longitude = update.getQualifiedCoordinates().getLongitude();
altitude = update.getQualifiedCoordinates().getAltitude();
}
}
}
public MovementTracker() throws LocationException
...
I have not written any code for handling LocationException.
No code is very dangerous practice, just search the web for something like "java swallow exceptions".
It is quite possible that because of implementation specifics Nokia throws LocationException where emulator does not throw it. Since you don't handle exception this may indeed crash you midlet at Nokia - and you wouldn't know the reason for that because, again, you have written no code to handle it.
How can I catch that exception?
The simplest thing you can do is to display an Alert with exception message and exit the midlet after user reads and dismisses alert