Androidは個人開発者向けbmob支払い
支付宝、微信などの支払いプラットフォームでは、SDKインタフェースの使用には資質認証が必要であり、個人開発者のアクセスは許されない.しかし、サードパーティプラットフォーム(ping++、bmob)の登場は、支払い機能の開発を試みた個人開発者に希望を見せ、税金を徴収する必要があるだけだ(bmobは低い).以下に紹介するのは、第三者bmob Android決済(bmob公式サイトトップページ)bmob公式サイトにも開発文書があり、決済に必要な前提条件(資料の整備、実名認証など)を実現するため、公式サイトにも紹介されていますが、ここでは挙げません.新版は旧版と異なり、以下では新版SDKの操作の具体的な手順を紹介します:1、Android支払いSDKをダウンロード(Android SDKをダウンロードする必要はありません)2、解凍、BmobPay_バージョン番号jarはプロジェクトルートディレクトリの下にlibsパッケージ(なければ新規)に置かれ、新版はjarパッケージが1つしかなく、旧版はjarパッケージが4つあります.3、あなたのプロジェクトでAndroidManifest.xmlで次の権限を宣言します.
4、AndroidManifest.xmlの「Application」タブには、次の内容が追加されています.
5、アプリケーションのメインActivityのonCreateで次の方法を呼び出します.
6、支払呼び出しを開始するには、次の方法を使用します.
受信した4つの結果の詳細は、公式サイトのドキュメントActivityコードを参照してください.
xmlコード:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
4、AndroidManifest.xmlの「Application」タブには、次の内容が追加されています.
<activity
android:name="c.b.a.A"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="c.b.a.B"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent" />
5、アプリケーションのメインActivityのonCreateで次の方法を呼び出します.
//(Application ID -> -> ->Application ID)
BP.init(context," Application ID");
6、支払呼び出しを開始するには、次の方法を使用します.
// 5 true , false
BP.pay(MainActivity.this, " ", " ", 0.02, true, new Plistener(){...});
受信した4つの結果の詳細は、公式サイトのドキュメントActivityコードを参照してください.
package com.hpu.bmobpay;
import c.b.BP;
import c.b.PListener;
import com.example.bmobpay.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
private Button Button_Pay;
private Thread th;
private Handler mHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("tag", " SDK ");
// SDK
BP.init(this, "debbad29b32cd9122fd9c513bf215c2a");
Init();
}
private void Init() {
Log.i("tag", " ");
//
Button_Pay = (Button) findViewById(R.id.button1);
Button_Pay.setOnClickListener(this);
}
@Override
public void onClick(View v) {
//
switch (v.getId()) {
case R.id.button1:
Pay();
break;
default:
break;
}
}
protected void Pay() {
// TODO Auto-generated method stub
Log.i("tag", "pay");
/**
* 5 true , false
*/
BP.pay(MainActivity.this, " ", " ", 0.02, true
,new PListener() {
@Override
public void unknow() {
// , , ( )
Log.i("tag", "unkonw");
Toast.makeText(MainActivity.this, " , , ( )", 2000).show();
}
@Override
public void succeed() {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, " ", 2000).show();
}
@Override
public void orderId(String orderid) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, " "+orderid, 2000).show();
}
@Override
public void fail(int arg0, String reason) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, " ,reason="+reason, 2000).show();
}
}
);
}
}
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">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="72dp"
android:text=" " />
RelativeLayout>