I have implemented Billing Library from the following url
https://developer.android.com/google/play/billing/billing_library_overview#java
I am getting error on this line
if (billingResult.getResponseCode() == BillingResponse.OK) {
it says Cannot resolve symbol 'BillingResponse'
here is the complete code from above link
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingResponse.OK) {
// The BillingClient is ready. You can query purchases here.
}
}
#Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
I have added following dependency in my apps build.gradle file
dependencies {
...
implementation 'com.android.billingclient:billing:2.1.0'
}
but I am getting error
I cannot even import it manually
import com.android.billingclient.api.BillingClient.BillingResponse;
I know its simple solution is to just replace
BillingResponse.OK
with
BillingClient.BillingResponseCode.OK
but my question is why its not given in documentation then?
I checked the source codes and figured out the correct code.
Though the code on google documentation says billingResult.getResponseCode() == BillingResponse.OK it should be billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
So all you need to do is replace BillingResponse.OK with BillingClient.BillingResponseCode.OK
Related
I have an application live in google play store and have some problems when add billing 3V to handle subscriptions.
Any new subscribers can’t access in my application after payment and the payment done and appear in google console .
I hope to help me to handle in app purchase in my application and this is the code :
public static void isUserHasSubscription(Context context, onCheck onCheck) {
BillingClient billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(new PurchasesUpdatedListener() {
#Override
public void onPurchasesUpdated(#NonNull BillingResult billingResult, #Nullable List list) {
}
}).build();
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
Purchase.PurchasesResult purchasesResult=billingClient.queryPurchases(BillingClient.SkuType.SUBS);
billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,(billingResult1, list) -> {
Log.d("billingprocess","purchasesResult.getPurchasesList():"+purchasesResult.getPurchasesList());
// //here you can pass the user to use the app because he has an active subscription
// Intent myIntent=new Intent(context,MainActivity.class);
// startActivity(myIntent);
boolean isPrshees = billingResult1.getResponseCode() == BillingClient.BillingResponseCode.OK && !Objects.requireNonNull(purchasesResult.getPurchasesList()).isEmpty();
onCheck.onCheck(isPrshees,isPrshees?getOrderId(purchasesResult.getPurchasesList().get(0).getOriginalJson()):"");
});
}
#Override
public void onBillingServiceDisconnected() {
onCheck.onCheck(false,"") ;
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
Log.d("billingprocess","onBillingServiceDisconnected");
}
});
}
I used the below the library and it's working fine.
Please try it, hope its helps you.
https://github.com/anjlab/android-inapp-billing-v3
Thank you.
A simple implementation of the Android In-App Billing API.
dependencies {
implementation 'com.github.moisoni97:google-inapp-billing:1.0.5'
}
More Info. on Github :- https://github.com/Mahadev-code/Android-inApp-Billing
I am using Sendbird SDK for a chat in my application following the steps through official documentation. Everything is working fine but recently I wanted to implement a functionality in which I wanted to give access to admin to remove a member from the group. But, while going through the official documentation, I came to know there is no such functionality or method provided in SendBird. So, is there any workaround or better way to do the same.
Some time has passed since this question was posted, but here are the official guides for the ban functionality.
Group Channel
if (groupChannel.getMyRole() == Member.Role.OPERATOR) {
groupChannel.banUser(USER, DESCRIPTION, SECONDS, new GroupChannel.GroupChannelBanHandler() {
#Override
public void onResult(SendBirdException e) {
if (e != null) { // Error.
return;
}
// TODO: Custom implementation for what should be done after banning.
}
});
}
Open Channel
if (openChannel.isOperator(SendBird.getCurrentUser())) {
openChannel.banUser(USER, SECONDS, new OpenChannel.OpenChannelBanHandler() {
#Override
public void onResult(SendBirdException e) {
if (e != null) { // Error.
return;
}
// TODO: Custom implementation for what to do after banning.
}
});
}
Please keep in mind that an user should be an operator to ban or unban a user.
I'm using Google Play Services for my libgdx game. I created some dummy achievements to test and later wanted to remove them. On my phone I went to Google Play Games -> Settings -> Delete Play Games Data -> Deleted data from my game.
After going back into my game, I noticed that the game thought I was still signed in. I use the following code to check if a user is signed in:
#Override
public boolean isSignedIn(){
return GoogleSignIn.getLastSignedInAccount(androidLauncher) != null;
}
If the user is not signed in, I try to sign them in silently
private void signInSilently() {
signedInClient.silentSignIn().addOnCompleteListener(androidLauncher,
new OnCompleteListener<GoogleSignInAccount>() {
#Override
public void onComplete(#NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
signedInAccount = task.getResult();
}
}
});
}
If I can't sign them in silenty. I create a new intent and have them manually sign in and give access to the app:
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
signedInAccount = result.getSignInAccount();
showSignedInDialog();
}
The problem is, after deleting the Play Games Data, my method isSignedIn is always returning true. However, when I try to do something like display achievements, I get the following error:
com.google.android.gms.common.api.ApiException: 4: The user must be signed in to make this API call.
Code for showing achievements:
#Override
public void showAchievements(){
androidLauncher.runOnUiThread(new Runnable() {
#Override
public void run() {
if (isSignedIn()) {
loadingView.showLoadingView();
Games.getAchievementsClient(androidLauncher, signedInAccount)
.getAchievementsIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
#Override
public void onSuccess(Intent intent) {
androidLauncher
.startActivityForResult(intent, RC_ACHIEVEMENT_UI);
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Logger.error(e);
}
})
}
}
});
}
I'm curious as to why this is happening. According to the documentation, my isSignedIn method should be working correctly. However, because I'm getting the error that I'm getting when I actually try to make an API call, it appears that the method is not working. I can only assume that all of this is stemming from me deleting my Play Games Data as everything worked fine up until that point.
Something else I want to note - I tried having my isSignedIn method return false to force a silent sign in. My silent sign in returned the following error:
com.google.android.gms.common.api.ApiException: 8: 8:
I did a bit of research and found a bug report. It looks like a status code of 8 is an Internal Error. Google at least seems to be aware of the issue.
Update: After having my isSignedIn method return false, and after disabling my silent sign in, I forced a manual sign in. After forcing the manual sign in, and signing in, it now works. However, I won't be able to do that for users if they run into the same issue. They would be stuck as the isSignedIn method seems to always return true after deleting the Play Games Data.
I had a similar issue and what worked for me was enabling the Google Drive API for my project. Not sure why this worked, but it did.
Go to https://console.developers.google.com/apis, then open the "Library" menu option. From there, search for "Drive" and click on the "Google Drive API" item. You should then see an enable button.
I'm trying to implement a Google Fit Listener when data is updated into Google Fit services.
In this link of Google Fit documentation there is a simple example, however, it is not 100% clear. For that reason, I have two problems:
I don't know how to implement mResultCallback variable (there aren't any examples in this documentation).
When I define a simple ResultCallback (it seems to work but I'm not sure) and I launch the application, it gives me a result error code: java.lang.SecurityException: Signature check failed
The code within the HistortyApi lists one of android.permission.ACCESS_FINE_LOCATION or android.permission.BODY_SENSORS as being required.
Adding those permissions to my code hasn't resolved the same problem though.
Confirmed bug in Google Fit services. See discussion in https://plus.google.com/110141422948118561903/posts/Lqri4LVR7cD
mResultCallback is a ResultCallback<Status> so you need to implement a class of that type. Documentation is here, but there's only one method you need to implement:
public abstract void onResult (Status result)
The standard way is to do this using an anonymous class either when you declare mResultCallback or when you're using it as a parameter. Below is an example from Google's BasicRecordingAPI example:
Fitness.RecordingApi.subscribe(mClient, DataType.TYPE_ACTIVITY_SAMPLE)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
if (status.isSuccess()) {
if (status.getStatusCode()
== FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
Log.i(TAG, "Existing subscription for activity detected.");
} else {
Log.i(TAG, "Successfully subscribed!");
}
} else {
Log.i(TAG, "There was a problem subscribing.");
}
}
});
If you want to use a member variable you can simply make an assignment instead:
ResultCallback<Status> mResultCallback = new ResultCallback<Status>() {
#Override
public void onResult(Status status) {
...
}
});
Of course you can define a non-anonymous class, but if you did that for every callback you had you would end up creating a LOT of classes.
I'm doing an android app and trying to integrate social login into the application using Azure Mobile Services.
public class SocialLogin extends Activity implements UserAuthenticationCallback {
#Override
protected void onCreate(Bundle savedInstanceState) {
// on create code
}
// All the code
#Override
public void onCompleted(MobileServiceUser user, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
//Take user to the logged in view
cacheUserToken(user);
} else {
Log.e("SocialLogin", "User did not login successfully");
}
}
}
I'm getting two errors because of the onCompleted method.
Error:(176, 5) error: method does not override or implement a method from a supertype
Error:(37, 8) error: SocialLogin is not abstract and does not override abstract method onCompleted(MobileServiceUser,Exception,ServiceFilterResponse) in UserAuthenticationCallback
Edit: Fixed the problem by deleting away the .jar file in my lib.
Per my understanding, 'UserAuthenticationCallback' is not an interface since many of samples are coding like this:
MobileServiceClient mClient = new MobileServiceClient(
"MobileServiceUrl",
"AppKey",
this).withFilter(new ProgressFilter());
mClient.login(MobileServiceAuthenticationProvider.MicrosoftAccount,
new UserAuthenticationCallback() {
#Override
public void onCompleted(MobileServiceUser user,
Exception exception, ServiceFilterResponse response) {
synchronized(mAuthenticationLock)
{
if (exception == null) {
cacheUserToken(mClient.getCurrentUser());
} else {
createAndShowDialog(exception.getMessage(), "Login Error");
}
}
}
});
Since it is not an interface, we cannot implement it as you did. You can either create a class that inherits UserAuthenticationCallback (but the class cannot inherit Activity as we can only inherit one class), or simply create a new instance of UserAuthenticationCallback like the code in the sample.
Also, I'd like to suggest you to check https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-users/ and https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-data/ for a completed sample of how to add authentication to your Mobile Services Android app.