Fortumo针对Android的应用内付款

时间:2012-04-10 09:56:54

标签: java android in-app-purchase fortumo

我正在尝试创建一个应用程序,您可以使用Fortumo服务购买应用内信用。我设法得到了makePayment();工作的方法,所以我可以付款,一切似乎都有效。唯一的是,它看起来像onReceive();永远不会被调用,因为成功付款后信用点数不会改变。积分数应增加32000,一次性支付0.32欧元。

这是java的主要活动:

package com.your.raha;
import com.your.raha.R;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class Soundboard extends Activity {
private SoundManager mSoundManager;
static int counter;
static TextView display;
SharedPreferences someData;
public static String filename = "rahafail";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    setContentView(R.layout.proov);
    display = (TextView) findViewById(R.id.tvKonto);
    someData = getSharedPreferences(filename, 0);
    int returnedInt = someData.getInt("sharedInt", 0);
    counter = returnedInt;

    mSoundManager = new SoundManager();
    mSoundManager.initSounds(getBaseContext());
    mSoundManager.addSound(1, R.raw.sound1);

    Button SoundButton1 = (Button)findViewById(R.id.sound1);
    SoundButton1.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
    mSoundManager.playSound(1);
    AddOne();           
}
});       

    Button bOsta = (Button)findViewById(R.id.bOsta);
    bOsta.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            onStop();
            startActivity(new Intent("com.uugudev.rahaboss.FORTUMOMAKSA"));


        }
    });
    ImageButton Abi = (ImageButton)findViewById(R.id.ibAbi);
    Abi.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            counter = 0;
          SharedPreferences.Editor editor = someData.edit();
        editor.putInt("sharedInt", counter);
        editor.commit();    
      display.setText(counter + " EEK");    

        }
    });


}
public static void AddOne() {
    // TODO Auto-generated method stub
    counter++;
    display.setText(counter + " EEK");
}

public static void Osteti() {
// TODO Auto-generated method stub
counter = counter + 32000;
display.setText(counter + " EEK");
}   

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub  
super.onDestroy();
SharedPreferences.Editor editor = someData.edit();
editor.putInt("sharedInt", counter);
editor.commit();

}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
SharedPreferences.Editor editor = someData.edit();
editor.putInt("sharedInt", counter);
editor.commit();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
int returnedInt = someData.getInt("sharedInt", 0);
counter = returnedInt;
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
SharedPreferences.Editor editor = someData.edit();
editor.putInt("sharedInt", counter);
editor.commit();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
display.setText(counter + " EEK");
}
}

付款活动类:

package com.your.raha;

import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;

import com.fortumo.android.Fortumo;
import com.fortumo.android.PaymentActivity;
import com.fortumo.android.PaymentRequestBuilder;
import com.fortumo.android.PaymentResponse;

public class FortumoMaksa extends PaymentActivity {
/** Called when the activity is first created. */

public int raha;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    Fortumo.enablePaymentBroadcast(this, Manifest.permission.PAYMENT_BROADCAST_PERMISSION);


        PaymentRequestBuilder builder = new PaymentRequestBuilder();
        builder.setDisplayString("Donate");
                                builder.setProductName("stars_myawesomeusername");
        makePayment(builder.build());
      }
    ;
    @Override
    protected void onResume() {
      super.onResume();

    }

    @Override
    protected void onPaymentCanceled(PaymentResponse response) {
        Toast.makeText(this, "Kasutaja katkestas makse", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    protected void onPaymentFailed(PaymentResponse response) {
        Toast.makeText(this, "Makse ebaõnnestus", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    protected void onPaymentPending(PaymentResponse response) {
        Toast.makeText(this, "Makse ootel", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    protected void onPaymentSuccess(PaymentResponse response) {
        Toast.makeText(this, "Makse õnnestus", Toast.LENGTH_SHORT).show();
        finish();
    }
}

PaymentStatusReceived类:

package com.your.raha;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.fortumo.android.Fortumo;


public class PaymentStatusReceiver extends BroadcastReceiver {
private static String TAG = "PaymentStatusReceiver";

@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();   
int billingStatus = extras.getInt("billing_status");
if(billingStatus == Fortumo.MESSAGE_STATUS_BILLED) {
  Soundboard.Osteti();
    } 
  }
}

AndroidManifest xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.your.raha"
android:installLocation="auto"
android:versionCode="2"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />

<permission
    android:name="com.your.domain.PAYMENT_BROADCAST_PERMISSION"
    android:label="Read Fortumo payment status"
    android:protectionLevel="signature" />

<uses-permission android:name="com.your.raha.PAYMENT_BROADCAST_PERMISSION" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <receiver android:name="com.fortumo.android.BillingSMSReceiver" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

    <service android:name="com.fortumo.android.FortumoService" />
    <service android:name="com.fortumo.android.StatusUpdateService" />

    <activity
        android:name="com.fortumo.android.FortumoActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <receiver
        android:name=".PaymentStatusReceiver"
        android:permission="com.your.raha.PAYMENT_BROADCAST_PERMISSION" >
        <intent-filter>
            <action android:name="com.fortumo.android.PAYMENT_STATUS_CHANGED" />
        </intent-filter>
    </receiver>

    <activity
        android:name="com.fortumo.android.FortumoActivity"
        android:configChanges="orientation|keyboardHidden"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    <activity
        android:name=".PaymentStatusReceiver"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.uugudev.rahaboss.PAYMENTSTATUSRECEIVER" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
    <activity
        android:name="com.fortumo.android.FortumoActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <service android:name="com.fortumo.android.FortumoService" />

    <activity
        android:name=".Soundboard"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />

            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name=".FortumoMaksa"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.uugudev.rahaboss.FORTUMOMAKSA" />

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

所以基本上我正在尝试启动Soundboard.Osteti();在Soundboard.java中,将32000添加到计数器int,然后更新TextView。但没有任何反应。 希望有人可以帮助我。谢谢!

1 个答案:

答案 0 :(得分:0)

我仍在尝试做这项工作。 有一件事我认为你的清单错了:

PaymentStatusReceiver它不是一个活动,你只需将其配置为收发器(就像你已经拥有的那样)。