how to implement find friends with fabric digits?
i have successfully implemented mobile number verification but i m unable to upload contacts and get matched contacts .. every time i get same error
error : Rate limit exceeded
below is implementation
registerReceiver(new MyResultReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (ContactsUploadService.UPLOAD_COMPLETE.equals(intent.getAction())) {
ContactsUploadResult result = intent.getParcelableExtra(ContactsUploadService.UPLOAD_COMPLETE_EXTRA);
Log.e("upload", result.totalCount + " " + result.successCount);
}
}
}, new IntentFilter("com.digits.sdk.android.UPLOAD_COMPLETE"));
sharedPreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
Ref = FirebaseDatabase.getInstance().getReference().child("Users");
DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);
digitsButton.setCallback(new AuthCallback() {
#Override
public void success(DigitsSession session, String phoneNumber) {
// TODO: associate the session userID with your user model
phone = session.getPhoneNumber();
digitsId = String.valueOf(session.getId());
Toast.makeText(getApplicationContext(), "Authentication successful for "
+ phoneNumber, Toast.LENGTH_LONG).show();
Log.e("number", "Mobile Number: " + phoneNumber);
Log.e("digit", "DigitsID " + session.getAuthToken() + " " + session.getId());
// Digits.getInstance().getActiveSession();
sendDigitANdNumber(String.valueOf(session.getId()), phoneNumber);
// startService(new Intent(PhoneVerification.this, MyResultReceiver.class));
startActivity(new Intent(PhoneVerification.this, RecentsTab.class));
finish();
}
#Override
public void failure(DigitsException exception) {
Log.d("Digits", "Sign in with Digits failure", exception);
}
});
}
Receivr
public class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (ContactsUploadService.UPLOAD_COMPLETE.equals(intent.getAction())) {
ContactsUploadResult result = intent.getParcelableExtra(ContactsUploadService.UPLOAD_COMPLETE_EXTRA);
}
}
}
Contacts class
find.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ContactMatch();
}
});
private void ContactMatch() {
Digits.uploadContacts();
progressDialog.show();
Digits.findFriends(new ContactsCallback<Contacts>() {
#Override
public void success(Result<Contacts> result) {
if (result.data.users != null) {
// Process data
progressDialog.dismiss();
linearLayout.setVisibility(View.GONE);
Log.e("data", result.toString());
}
}
#Override
public void failure(TwitterException exception) {
progressDialog.dismiss();
// Show error
}
});
}
Twitter limits the number of requests you can make to their API within a certain timeframe. So you are hitting this limit. You need to modify your logic to either throttle your requests or wait for a set amount of time if the Rate Limit exception is thrown.
Their docs page on rate limiting is pretty thorough, so I recommend checking that out.
Related
I want to create a service that should listens for hotword in background such that when i say hello it should invoke an activity, how can i do this, about voiceInteractionService but I have read that Its not available to use, is it true? could anyone tell me the way i should solve this problem? Its about hotword detector
I have been following this
Tried this:
public class InteractionService extends VoiceInteractionService {
static final String TAG = "InteractionService" ;
private AlwaysOnHotwordDetector mHotwordDetector;
#Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "service started");
}
#Override
public void onReady() {
super.onReady();
Log.i(TAG, "Creating " + this);
mHotwordDetector = createAlwaysOnHotwordDetector("Hello"
, Locale.forLanguageTag("en-US"), mHotwordCallback);
Log.i(TAG, "onReady");
}
private final AlwaysOnHotwordDetector.Callback mHotwordCallback =
new AlwaysOnHotwordDetector.Callback() {
#Override
public void onAvailabilityChanged(int status) {
Log.i(TAG, "onAvailabilityChanged(" + status + ")");
hotwordAvailabilityChangeHelper(status);
}
#Override
public void onDetected(AlwaysOnHotwordDetector
.EventPayload eventPayload) {
Log.i(TAG, "onDetected");
}
#Override
public void onError() {
Log.i(TAG, "onError");
}
#Override
public void onRecognitionPaused() {
Log.i(TAG, "onRecognitionPaused");
}
#Override
public void onRecognitionResumed() {
Log.i(TAG, "onRecognitionResumed");
}
};
private void hotwordAvailabilityChangeHelper(int status) {
Log.i(TAG, "Hotword availability = " + status);
switch (status) {
case AlwaysOnHotwordDetector.STATE_HARDWARE_UNAVAILABLE:
Log.i(TAG, "STATE_HARDWARE_UNAVAILABLE");
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNSUPPORTED:
Log.i(TAG, "STATE_KEYPHRASE_UNSUPPORTED");
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNENROLLED:
Log.i(TAG, "STATE_KEYPHRASE_UNENROLLED");
Intent enroll = mHotwordDetector.createEnrollIntent();
Log.i(TAG, "Need to enroll with " + enroll);
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_ENROLLED:
Log.i(TAG, "STATE_KEYPHRASE_ENROLLED - starting recognition");
if (mHotwordDetector.startRecognition(0)) {
Log.i(TAG, "startRecognition succeeded");
} else {
Log.i(TAG, "startRecognition failed");
}
break;
}
// final static AlwaysOnHotwordDetector.Callback
}}
Porcupine's service demo does exactly this.
private Button clickButton;
private Button buyButton;
private static final String TAG =
"InAppBilling";
IabHelper mHelper;
static final String ITEM_SKU = "tips";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buyButton = (Button)findViewById(R.id.buybutton);
clickButton = (Button)findViewById(R.id.clickbutton);
clickButton.setEnabled(false);
String base64EncodedPublicKey =
" "
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new
IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " +
result);
} else {
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
}
public void button2 (View v)
{
Intent intent = new Intent(getApplicationContext(), vtoriFra
gment.class);
startActivity(intent);
}
public void buttonClicked (View view)
{
clickButton.setEnabled(false);
buyButton.setEnabled(true);
Intent intent = new Intent(getApplicationContext(), purviFragment.class);
startActivity(intent);
}
public void buyClick(View view) {
mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
mPurchaseFinishedListener, "mypurchasetoken");
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
if (!mHelper.handleActivityResult(requestCode,
resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
// Handle error
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
consumeItem();
buyButton.setEnabled(false);
}
}
};
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
clickButton.setEnabled(true);
} else {
// handle error
}
}
};
#Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}
}
Hi, i have a trouble mit my app. The case is:
I want when the people pay in my app to unlock one button but i want to pay only one thime but when they pay they unlock the button for only one time. Sorry for my bad english. This is my source code
Your code is a bit messy, but this is your flow:
when the user clicks the button you start the purchasing flow
when when purchasing flow ends, you query for the list of purchased items
if the purchased item exists, you consume it
When you consume an item, you "delete" it, so it is no more on the purchased items list. If you want so sell something just once (for example to remove ads) you don't have to consume it.
Your flow should be this:
query for the purchased items
if the list contains the purchase item, disable the button
if the list doesn't contain che purchase item, enable the button
on click, start the purchase flow
when when purchasing flow ends, you query for the list of purchased items
if the purchased item exists, disable the button and provide the extra feature
if the purchased item doesn't exists, the purchase procedure failed
You should read carefully this page:
https://developer.android.com/training/in-app-billing/purchase-iab-products.html
I'm trying to use google Fit API to get heartrate from sony smartband2. Problem is, I don't get any readings(i.e. onDataPoint method is not called). Heart Rate sensor is being found properly, whole code also is working properly if I try to look for step data.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
authInProgress = savedInstanceState.getBoolean(AUTH_PENDING);
}
mApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
protected void onStart() {
super.onStart();
mApiClient.connect();
}
#Override
public void onConnected(Bundle bundle) {
final DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_HEART_RATE_BPM)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build();
Fitness.SensorsApi.findDataSources(mApiClient, dataSourceRequest)
.setResultCallback(new ResultCallback<DataSourcesResult>() {
#Override
public void onResult(DataSourcesResult dataSourcesResult) {
for(DataSource dataSource : dataSourcesResult.getDataSources())
{
Log.i(TAG, "Data source found: " + dataSource.toString());
Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());
registerFitnessDataListener(dataSource, DataType.TYPE_HEART_RATE_BPM);
}
}
});
// dataSourceRequest = new DataSourcesRequest.Builder()
// .setDataTypes(DataType.TYPE_STEP_COUNT_CUMULATIVE)
// .setDataSourceTypes(DataSource.TYPE_RAW)
// .build();
// Fitness.SensorsApi.findDataSources(mApiClient, dataSourceRequest)
// .setResultCallback(dataSourcesResultCallback);
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (!authInProgress) {
try {
authInProgress = true;
connectionResult.startResolutionForResult(MainActivity.this, REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
}
} else {
Log.e("GoogleFit", "authInProgress");
}
}
#Override
public void onDataPoint(DataPoint dataPoint) {
for (final Field field : dataPoint.getDataType().getFields()) {
final Value value = dataPoint.getValue(field);
Log.i("DATASOURCE", field.getName());
Log.i("DATASOURCE", value.toString());
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView tv = (TextView) findViewById(R.id.tv1);
tv.setText("Field: " + field.getName() + " Value: " + value);
Toast.makeText(getApplicationContext(), "Field: " + field.getName() + " Value: " + value, Toast.LENGTH_SHORT).show();
}
});
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_OAUTH) {
authInProgress = false;
if (resultCode == RESULT_OK) {
if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
mApiClient.connect();
} else {
TextView tv = (TextView) findViewById(R.id.tv1);
tv.setText("connected");
}
} else if (resultCode == RESULT_CANCELED) {
Log.e("GoogleFit", "Result_Canceled");
}
} else {
Log.e("GoogleFit", "Request not OAUTH");
}
}
private void registerFitnessDataListener(final DataSource dataSource, DataType dataType) {
SensorRequest request = new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(2, TimeUnit.SECONDS)
.build();
Fitness.SensorsApi.add(mApiClient, request, this)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
if (!status.isSuccess()) {
Log.e("DATASOURCES", "register " + dataSource.getName() + " failed");
} else {
Log.i("DATASOURCES", "register " + dataSource.getName() + " succeed");
}
}
});
}
}
Do You have any ideas why i can't get the data?
Ok, After I found that this code was working on someone's phone, I found out that You need to enable SmartBand2 application option to share data to Google Fit. For some reason smartband 2 can't connect to Google Fit independently from it's application.
I have an Activity class with quite a lot web services running and want to make my program more "object oriented",so it can be maintainable and easy to read . For example look at the following example.
public class Welcome extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_sample);
buildFitnessClient();
showUser(username,password);
}
private void buildFitnessClient() {
// Create the Google API Client
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(
new GoogleApiClient.ConnectionCallbacks() {
#Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Connected!!!");
// Now you can make calls to the Fitness APIs. What to do?
// Look at some data!!
//showUser(username,password);
new InsertAndVerifyDataTask().execute();
}
#Override
public void onConnectionSuspended(int i) {
// If your connection to the sensor gets lost at some point,
// you'll be able to determine the reason and react to it here.
if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
Log.i(TAG, "Connection lost. Cause: Network Lost.");
} else if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
Log.i(TAG, "Connection lost. Reason: Service Disconnected");
}
}
}
)
.addOnConnectionFailedListener(
new GoogleApiClient.OnConnectionFailedListener() {
// Called whenever the API client fails to connect.
#Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "Connection failed. Cause: " + result.toString());
if (!result.hasResolution()) {
// Show the localized error dialog
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),
Welcome.this, 0).show();
return;
}
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized, and an
// authorization dialog is displayed to the user.
if (!authInProgress) {
try {
Log.i(TAG, "Attempting to resolve failed connection");
authInProgress = true;
result.startResolutionForResult(Welcome.this,
REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG,
"Exception while starting resolution activity", e);
}
}
}
}
)
.build();
}
#Override
protected void onStart() {
super.onStart();
// Connect to the Fitness API
Log.i(TAG, "Connecting...");
mClient.connect();
}
#Override
protected void onStop() {
super.onStop();
if (mClient.isConnected()) {
mClient.disconnect();
//showUser(username,password);
}
}
#Override
protected void onDestroy() {
super.onDestroy();
//showUser(username,password);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_OAUTH) {
authInProgress = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mClient.isConnecting() && !mClient.isConnected()) {
mClient.connect();
}
}
}
}
private void showUser(final String username, final String password) {
HttpsTrustManager.allowAllSSL();
String tag_json_obj = "json_obj_req";
location = getResources().getConfiguration().locale.getCountry();
final HashMap<String, String> postParams = new HashMap<String, String>();
postParams.put("username", username);
postParams.put("password", password);
Response.Listener<JSONObject> listener;
Response.ErrorListener errorListener;
final JSONObject jsonObject = new JSONObject(postParams);
//{"password":"larissa","username":"samsungtest"}
//{"password":"larissa","username":"theo81developer#gmail.com"}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(AppConfig.URL_USER_CHECK, jsonObject,
new com.android.volley.Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
// {"message":"User Information found.","user":{"username":"samsungtest","league_points":null,"team_id":"189","location":"GB","latest_steps":"0","user_type":"LEADER","nickname":"samsungtest"},"status":"success"}
//{"message":"User Information found.","user":{"username":"theo81developer#gmail.com","league_points":null,"team_id":"228","location":"GB","latest_steps":"5033","user_type":"LEADER","nickname":"Samsung User"},"status":"success"}
Log.d("TAG", response.toString());
try {
if (response.getString("status").equals("success")){
userTable(response);
localRanking(username,password,location);
globalRanking(username,password);
}
} catch (JSONException e) {
Log.e("TAG", e.toString());
}
}
}, new com.android.volley.Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
//VolleyLog.d("TAG", "Error: " + error.getMessage());
}
}) {
#Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
}
How can I make it work if I was calling buildFitnessClient() and showUser(...) from another class? I tried some different ways like instastiating a Class called Fitness with buildFitnessClient() method inside,but I am getting null pointer exception on View objects.
You can implement your methods as static so that you can call them from another class or activity and simply pass the required parameters that it may need (such as context, views, etc). And simply use them as something like Fitness.buildFitnessClient( < variables > )
OR
Implement a singleton where you can set variables to be used by your methods and do what you want to do. This, however, is much more complex (at least for me)
** Just be careful with memory leaks **
I finally figured out how to consume an IAP in v3 of the InAppBilling API. The user can now constantly consume as many products as they please.
Now I want the GUI for the user to be updated once the purchase is confirmed complete. I have put Toasts all over the below code to try and find out where to update the GUI at but I have yet to have a Toast appear yet. But remember that the consuming of the IAPs work.
I have identified in my code below the snippet that updates the GUI for the user. That snippet of code is what I want run AFTER a successful purchase is complete.
So my question is where to put that snippet of code so that the GUI is updated for the user after a successful purchase.
public class Levels extends SwarmActivity {
//static final String SKU_BUYLIVES = "buy5lives";
static final String SKU_BUYLIVES = "android.test.purchased";
IabHelper mHelper;
IInAppBillingService mService;
#Override
public void onCreate(Bundle savedInstanceState) {
moreLives = (Button)findViewById(R.id.moreLives);
moreLives.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
buyLives();
}
});
}
public void buyLives() {
final Dialog dialog = new Dialog(c);
dialog.setContentView(R.layout.buylives);
String base64EncodedPublicKey = a + b + d + e + f + g + h + i + j + k;
TextView title = (TextView)dialog.findViewById(R.id.question);
Button no = (Button)dialog.findViewById(R.id.no);
Button yes = (Button)dialog.findViewById(R.id.yes);
title.setText(c.getResources().getString(R.string.buyLivesQuestion));
no.setText(c.getResources().getString(R.string.maybelater));
yes.setText(c.getResources().getString(R.string.buy));
// Create the helper, passing it our context and the public key to verify signatures with
mHelper = new IabHelper(Levels.this, base64EncodedPublicKey);
// start setup. this is asynchronous and the specified listener will be called once setup completes.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// there was a problem.
complain("An error has occurred. We apologize for the inconvenience. " + c.getResources().getString(R.string.problem1) + " " + result);
return;
}
// IAB is fully set up. Now, let's get an inventory of stuff we own.
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
yes.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
mHelper.launchPurchaseFlow(Levels.this, SKU_BUYLIVES, 10001, mPurchaseFinishedListener, "payload");
dialog.dismiss();
// the below ~14 lines is the code that I want to call to update the GUI for the user. this block of code has been all over the place. this is just the last spot I tested it at.
SharedPreferences settings = getSharedPreferences("level_SP", 0);
livesCount = settings.getInt("livesTotal1", 0);
remainderTimeStamp = settings.getLong("remainderTimeStamp1", 0);
livesCount = 5;
remainderTimeStamp = 0;
SharedPreferences.Editor editor = settings.edit();
editor.putInt("livesTotal1", livesCount);
editor.putLong("remainderTimeStamp1", remainderTimeStamp);
editor.commit();
livesCountTV.setText(c.getResources().getString(R.string.livesCount) + " " + livesCount);
livesCounterTV.setText(c.getResources().getString(R.string.livesCounter) + " FULL!");
}
});
no.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.show();
}
// listener that's called when we finish querying the items and subscriptions we own.
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if(result.isFailure()) {
complain(c.getResources().getString(R.string.sorryerror) + c.getResources().getString(R.string.failedtoquery) + " " + result);
return;
} else if(inventory.hasPurchase(SKU_BUYLIVES)) {
mHelper.consumeAsync(inventory.getPurchase(SKU_BUYLIVES), null);
}
}
};
// callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
// this appears to the user immediately after purchasing.
if(result.isFailure()) {
complain(c.getResources().getString(R.string.sorryerror) + result);
} else if(purchase.getSku().equals(SKU_BUYLIVES)) {
alert(c.getResources().getString(R.string.livesbought));
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
// success
Toast.makeText(Levels.this, "SUCCESS", Toast.LENGTH_LONG).show();
try {
mService.consumePurchase(3, getPackageName(), SKU_BUYLIVES);
// this Toast is never seen.
Toast t = Toast.makeText(Levels.this, "PURCHASE CONSUMED", Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// error
// this Toast is never seen.
Toast.makeText(Levels.this, "ERROR", Toast.LENGTH_LONG).show();
}
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return;
}
};
void complain(String message) {
alert("Error: " + message);
}
void alert(String message) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(message);
bld.setNeutralButton("OK", null);
bld.create().show();
}
#Override
public void onDestroy() {
super.onDestroy();
if(mHelper != null) mHelper.dispose();
mHelper = null;
}
}
To open Google Play purchase dialog you should have used startIntentSenderForResult() method with your purchase intent. Once user is done with this dialog, onActivityResult() gets called on your activity. This is the place where you should verify the purchase and update GUI if needed.
This is an example of how you open purchase dialog.
public void buyProduct() {
PendingIntent buyIntent = ... // create your intent here
IntentSender sender = buyIntent.getIntentSender();
try {
startIntentSenderForResult(sender, REQ_BUY_PRODUCT, new Intent(), 0, 0, 0);
} catch (SendIntentException e) {
Log.e(TAG, "", e);
}
}
This is example of how to handle purchase intent
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQ_BUY_PRODUCT && resultCode == Activity.RESULT_OK) {
// here you verify data intent and update your GUI
...
return;
}
}
Both methods belong to your activity.