Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have developing one application that based on purchasing books from a server.Almost all codes are completed. one problem is that inApp purchase.i got inApp purchase code from google. i apply that code singleone. its working.But i put it into my project code it doesnot working.please help me to solve this problem.


Codes i used that shown below


MainActivity.java
Java
public class MainActivity extends Activity implements OnClickListener {
	Button btn1;
	private Context mContext=this;
	private static final String TAG = "Android BillingService";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		btn1 = (Button) findViewById(R.id.button1);
		
		btn1.setOnClickListener(this);
		
		
		 startService(new Intent(mContext, BillingService.class));
	        BillingHelper.setCompletedHandler(mTransactionHandler);
	}
	public Handler mTransactionHandler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			Log.i(TAG, "Transaction complete");
			Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
			Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);
			
			if(BillingHelper.latestPurchase.isPurchased()){
				showItem();
			}
		};
	
};
	@Override
	public void onClick(View v) {
		if (v == btn1) {
			if(BillingHelper.isBillingSupported()){
				BillingHelper.requestPurchase(mContext, "android.test.purchased"); 
					        }
			else {
	        	Log.i(TAG,"Can't purchase on this device");
	        	btn1.setEnabled(false); // XXX press button before service started will disable when it shouldnt
	        }
			Toast.makeText(this, "Purchase Books", Toast.LENGTH_SHORT).show();
		}
		
	}

	private void showItem() {
		
		
		//purchaseableItem.setVisibility(View.VISIBLE);
	}

	@Override
	protected void onPause() {
		Log.i(TAG, "onPause())");
		super.onPause();
	}
	
	@Override
	protected void onDestroy() {
		BillingHelper.stopService();
		super.onDestroy();
	}
}

manifestfiles

XML
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.BILLING"/>
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Posted
Updated 20-Jun-14 18:21pm
v2

Check every pros and cons from mother resource:
1. Implementing In-app Billing[^]
2. Google Play In-app Billing[^]
 
Share this answer
 
Never, ever, accept code from a insecure website to handle anything to do with real money.
You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties.

Only get such code from Google - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be!

Talk to them! They don't make it too difficult...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900