Skip to content

Issue with onPurchaseStateChanged #111

@i1j1k1

Description

@i1j1k1

Hello.
I have a issue: I bought the item in my application, and it was success. But in fact my function for purchase is never called. Every time I open my BillingActivity it shows me a window with text, that I have this item, and cannot buy it twice.
As I see onPurchaseStateChanged is never called. And BillingController.isPurchased doesn't work in my case. I have read all topics with the same issues, but I don't understand, why it can be.
Please, tell me, what I can do to fix this.
And thank you for the library.

UPD: There is "W/BillingService(14265): Remote billing service crashed" In the logcat. Can my issue be because of this?

W/ActivityManager( 175): Trying to launch com.gravitrip/.BillingActivity
I/AndroidInput(14265): Pointer ID lookup failed: 0, 0:-1 1:-1 2:-1 3:-1 4:-1 5:-1 6:-1 7:-1 8:-1 9:-1
I/InputDispatcher( 175): Delivering touch to current input target: action: 1, channel '40a10008 com.gravitrip/com.gravitrip.GravitripActivity (server)'
V/b (14265): try to restore transaction
V/AudioPolicyManager( 8906): stopOutput() output 1, stream 3, session 1659
E/AudioPolicyManager( 8906): stopOutput stream = 3 , mHardwareOutput = 1, output = 1
V/AudioPolicyManager( 8906): getNewDevice() selected device 0
V/AudioPolicyManager( 8906): setOutputDevice() output 1 device 0 delayMs 0
V/AudioPolicyManager( 8906): setOutputDevice() setting same device 0 or null device for output 1
I/AndroidInput(14265): Pointer ID lookup failed: 0, 0:-1 1:-1 2:-1 3:-1 4:-1 5:-1 6:-1 7:-1 8:-1 9:-1
W/BillingService(14265): Remote billing service crashed
W/BillingService(14265): Remote billing service crashed
I/WindowManager( 175): CREATE SURFACE Surface(name=com.gravitrip/com.gravitrip.BillingActivity, identity=733, mNativeSurface=0) IN SESSION android.view.SurfaceSession@40af5908: pid=14265 format=-1 flags=0x0 / Window{40888708 com.gravitrip/com.gravitrip.BillingActivity paused=false}
E/DataRouter( 129): fd is 17 Content read is USB Switch : PDA_AP
E/DataRouter( 129): length is 20
E/DataRouter( 129): Content of Buf
I/GLThread(14265): noticed surfaceView surface lost tid=9
D/PowerManager( 175): release flags=0x0 tag=ActivityManager-Launch
I/ActivityManager( 175): Displayed com.gravitrip/.BillingActivity: +224ms

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import net.robotmedia.billing.BillingController;
import net.robotmedia.billing.BillingController.BillingStatus;
import net.robotmedia.billing.BillingRequest.ResponseCode;
import net.robotmedia.billing.helper.AbstractBillingActivity;
import net.robotmedia.billing.model.Transaction.PurchaseState;

public class BillingActivity extends AbstractBillingActivity{
    public static final String ANDROID_MARKET_ITEM = "allchapters"; 
    private boolean billingSupported = false;
    static boolean purchased;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        setContentView(com.gravitrip.R.layout.main);
        super.onCreate(savedInstanceState);
        purchased=false;
        if (checkBillingSupported() != BillingStatus.SUPPORTED) {
            Toast.makeText(getApplicationContext(), "Purchase is not supported", Toast.LENGTH_LONG).show();
            Log.v("b", "Purchase is not supported");
        } 
        else 
        {
            purchased = BillingController.isPurchased(getApplicationContext(), ANDROID_MARKET_ITEM);
            if (!purchased) {
                Log.v("b", "try to restore transaction");
                restoreTransactions();
                purchased = BillingController.isPurchased(getApplicationContext(), ANDROID_MARKET_ITEM);
                if (!purchased) {
                    requestPurchase(ANDROID_MARKET_ITEM);
                }
            }

            if (purchased) 
            {
                Log.v("b", "purchased #1");
                UIClass.purchase();
            }
        }


    }

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    purchased = BillingController.isPurchased(getApplicationContext(), ANDROID_MARKET_ITEM);
    if (purchased)        
    {
        Log.v("b", "purchased #2");
                UIClass.purchase();
    }
    super.onPause();
}

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

    }

    @Override
    public byte[] getObfuscationSalt() {
        // TODO Auto-generated method stub
        return new byte[] {-1, 5, -7, 4, 1, 2, 1, 8, -9, 1, 1, 2, 1, 14, -49, -21, 17, -8, 1, 22};

    }

    @Override
    public String getPublicKey() {
        // TODO Auto-generated method stub
    return ... //got from developer consol, RSA key.
    }

    @Override
    public void onBillingChecked(boolean arg0) {
        // TODO Auto-generated method stub
           billingSupported = arg0;
    }

    @Override
    public void onPurchaseStateChanged(String arg0, PurchaseState arg1) {
        // TODO Auto-generated method stub
            Log.v("b", "onPurchaseStateChanged");

        if (arg1==PurchaseState.CANCELLED) 
        {
            Toast.makeText(getApplicationContext(), "Transaction has been cancelled", Toast.LENGTH_LONG).show();
            Log.v("b", "PurchaseState.CANCELLED");
        }
        if (arg1==PurchaseState.PURCHASED) 
        {
            UIClass. purchase ();
            Log.v("b", "PurchaseState.PURCHASED");
        }
        if (arg1==PurchaseState.REFUNDED) 
        {
            Log.v("b", "PurchaseState.REFUNDED");
        }
        if (arg1==PurchaseState.EXPIRED) 
        {
            Log.v("b", "PurchaseState.EXPIRED");
        }
        if (arg1==PurchaseState.CANCELLED) 
        {
            Log.v("b", "PurchaseState.CANCELLED");
        }
    }

    @Override
    public void onRequestPurchaseResponse(String arg0, ResponseCode arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSubscriptionChecked(boolean arg0) {
        // TODO Auto-generated method stub

    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions