app广告计费规范_如何在Android中集成到App购买计费中

app广告计费规范

你好朋友! 今天,我将分享一个非常有用的博客,供您在Android中进行应用内购买。 Google在Android中提供In App Billing系。 在应用内购买是一种非常简单安全的在线付款方式。 请分步关注我的博客:

屏幕截图

  1. 在Android中创建一个新项目。
  2. 创建MainActivity.java类。
  3. 在您的res / layout文件夹中添加activity_main.xml。
  4. 在Manifest.xml中添加计费服务和权限。

要做

  1. 为您的应用程序创建符号apk。
  2. 将您的apk上传到Google Play商店。
  3. 为您的应用程序创建产品。
  4. 请等待6到12个小时,以备存更新项目。
  5. 复制您Google帐户的密钥,并将其粘贴到BillingSecurity.java类行号135-
    String base64EncodedPublicKey = "PUT YOUR PUBLIC KEY HERE";
  6. 在Manifest.xml中授予计费权限
  7. IMarketBillingService.java in com.android.vending.billing package.

  1. 不要使用模拟器进行测试,它不支持Billing Services。
  2. 不要将未签名的apk用于计费服务。
  3. 不要与任何人共享密钥。

我的代码

1)MainActivity.java

package com.manish.inapppurchase;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
 Button btn1, btn2, btn3;
 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);
  btn2 = (Button) findViewById(R.id.button2);
  btn3 = (Button) findViewById(R.id.button3);
  btn1.setOnClickListener(this);
  btn2.setOnClickListener(this);
  btn3.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, "Shirt Button", Toast.LENGTH_SHORT).show();
  }
  if (v == btn2) {
   if(BillingHelper.isBillingSupported()){
    BillingHelper.requestPurchase(mContext, "android.test.purchased");
         } else {
          Log.i(TAG,"Can't purchase on this device");
          btn2.setEnabled(false); // XXX press button before service started will disable when it shouldnt
         }
   Toast.makeText(this, "TShirt Button", Toast.LENGTH_SHORT).show();
  }
  if (v == btn3) {
   if(BillingHelper.isBillingSupported()){
    BillingHelper.requestPurchase(mContext, "android.test.purchased");
         } else {
          Log.i(TAG,"Can't purchase on this device");
          btn3.setEnabled(false); // XXX press button before service started will disable when it shouldnt
         }
   Toast.makeText(this, "Denim Button", 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();
 }
}

2)activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099CC"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="150dp"
        android:layout_height="35dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:background="#FFFFFF"
        android:text="Shirt for 5.4$" />

    <Button
        android:id="@+id/button2"
        android:layout_width="150dp"
        android:layout_height="35dp"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:background="#FFFFFF"
        android:text="Tshirt for 7.4$" />

    <Button
        android:id="@+id/button3"
        android:layout_width="150dp"
        android:layout_height="35dp"
        android:layout_below="@+id/button2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:background="#FFFFFF"
        android:text="Denim for 10.7$" />

</RelativeLayout>

3)manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.manish.inapppurchase"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.manish.inapppurchase.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".BillingService" />

        <receiver android:name=".BillingReceiver" >
            <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>
        </receiver>
    </application>

</manifest>

4) 邮递区号

参考: 如何在我们博客的Android Hub 4上从我们的JCG合作伙伴 Manish Srivastava 集成到Android中的应用购买账单中

翻译自: https://www.javacodegeeks.com/2013/05/how-to-integrate-in-app-purchase-billing-in-android.html

app广告计费规范

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值