Android Question Android Market In-App Billing service

nicolino33

Active Member
Licensed User
Longtime User
Hello all, I'm trying to use the service, but when start it returns this error:
B4X:
acquistiinapp_service_create (java line: 180)
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.MarketBillingService.BIND }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1357)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1466)
at android.app.ContextImpl.bindService(ContextImpl.java:1434)
at android.content.ContextWrapper.bindService(ContextWrapper.java:636)
at com.android.vending.billing.BillingGate.bindToMarketBillingService(BillingGate.java:380)
at com.android.vending.billing.BillingGate.access$0(BillingGate.java:375)
at com.android.vending.billing.BillingGate$BillingRequest.runRequest(BillingGate.java:103)
at com.android.vending.billing.BillingGate.checkBillingSupported(BillingGate.java:401)
at anywheresoftware.b4a.inappbilling.BillingManager.Initialize(BillingManager.java:49)
at com.OlaLove.acquistiinapp._service_create(acquistiinapp.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.OlaLove.acquistiinapp.onCreate(acquistiinapp.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3253)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1617)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
the name of my service is AcquistiInApp, I' have the google key and the app is registered on google, I have put this on manifest:

B4X:
AddReceiverText(AcquistiInApp,  <intent-filter>
                <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
                <action android:name="com.android.vending.billing.RESPONSE_CODE" />
                <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
            </intent-filter>)

and this is the service code:

B4X:
#Region  Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
 Dim Manager As BillingManager
 Dim PublicKey As String
 PublicKey = "here my google key…." 'From the developer console
End Sub
Sub Service_Create
 Manager.Initialize("manager", PublicKey)
End Sub
Sub Service_Start (StartingIntent As Intent)
 Manager.HandleIntent(StartingIntent)
End Sub
Sub Manager_BillingSupported (Supported As Boolean)
 Log("BillingSupported: " & Supported)
End Sub
Sub Manager_PurchaseStateChange (PurchaseState As Int, ProductId As String, OrderId As String, PurchaseTime As Long, ExtraData As String)
 Log("PurchaseStateChange: " & PurchaseState & ", " & ProductId& ", " & OrderId & ", " & DateTime.Time(PurchaseTime) & ", " & ExtraData)
 If PurchaseState = Manager.PURCHASE_STATE_PURCHASED Then
  'Here you should store the purchase information
  'and then notify the activity about the purchase.
  'In most cases the activity will be running at this state. However it is possible that it will be paused.
  'In that case the following call will be ignored.
  'CallSub2(Main, "ThankYouForPurchasing", ProductId)
 End If
End Sub
Sub Service_Destroy
 Manager.UnbindMarketService
End Sub
 

nicolino33

Active Member
Licensed User
Longtime User
Hi Erel, I'v solved by using the V1.31, but now I'v another problem: when I try to buy a product it tells me it's not available, answer from google ... What could it be? I have published some products on the Play Store and they are all active, with ID and name, but can not be bought.
 
Upvote 0

nicolino33

Active Member
Licensed User
Longtime User
look here:

Starting async operation: launchPurchaseFlow
Constructing buy intent for TestProduct, item type: inapp
requestCode = 1
** Activity (acquisto) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Arrived: 1, 1
Ending async operation: launchPurchaseFlow
Purchase canceled - Response: 4:Item unavailable
User canceled. (response: -1005:User cancelled) <----- ???
** Activity (acquisto) Resume **
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
If you click to cancel the purchase you'll see this message.
You'll also see that message for any canceled transaction - even if it's not explicitly canceled by the user. It seems that it's just a generic cancel message.

@nicolino33 - as Erel said, you should be using the InAppBilling3 Library.

It sometimes takes a while after you've made the product active before it's available.

- Colin.
 
Upvote 0

nicolino33

Active Member
Licensed User
Longtime User
Hello, I'm using the InAppBilling3 library ... I found the cause of this problem: can not make purchases using an app version that is not on play store: if loading release from B4A does not work, if loading from the Play Store works.
 
Upvote 0

nicolino33

Active Member
Licensed User
Longtime User
aiaiaiaiai…… this payment system is really problematic... now everything is working, but when the payment is made, the Manager_PurchaseCompleted event does not flow, the money is credited but no event! Do you have any idea what the cause might be?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
aiaiaiaiai…… this payment system is really problematic... now everything is working, but when the payment is made, the Manager_PurchaseCompleted event does not flow, the money is credited but no event! Do you have any idea what the cause might be?
Can you post your code?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Fyi - the PurchaseCompleted callback needs to be in the same activity that you made your Manager.RequestPayment call in - so if you currently have PurchaseCompleted in your Starter service, you need to move it.

- Colin.
 
Upvote 0

nicolino33

Active Member
Licensed User
Longtime User
Hi Colin thanks for you reply, the code already posted look up in this thread, ok I try your solution, but I have a doubt, since in the previous version it was necessary to use a service, I still use it, but I removed the intent from the manifest, perhaps it is necessary to perform all the operations in an activity and not in a service?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi Colin thanks for you reply, the code already posted look up in this thread
The code you posted doesn't have your PurchaseCompleted callback in it. In fact the code you posted doesn't seem to be related to In-App Billing 3 at all.

ok I try your solution, but I have a doubt, since in the previous version it was necessary to use a service, I still use it, but I removed the intent from the manifest, perhaps it is necessary to perform all the operations in an activity and not in a service?

You can initialize your BillingManager3 object, check that billing is supported (Manager_BillingSupported callback) & check for owned products (Manager_OwnedProducts callback) in a service, but if you initiate a purchase from an activity (which you will have to do), then the callbacks need to be in that activity. So for example, I think even if you have a "Purchase" button in an activity that calls Starter.Manager.RequestPayment, the PurchaseCompleted callback needs to be in the same activity as the button.

That's why I asked you to post your code that initiates the purchase & also the PurchaseCompleted callback.

Did you read the In-App Billing V3 tutorial (https://www.b4x.com/android/forum/threads/android-in-app-billing-v3-tutorial.29997/)?

- Colin.
 
Upvote 0

nicolino33

Active Member
Licensed User
Longtime User
Yes, I read it, but I did not notice that the callback must be in the same activity, if the problem is this I just move it .... And I can also launch an activity dedicated to payment, the user will select an object among the many, therfore this is not problem.
 
Upvote 0
Top