gpt4 book ai didi

java - 适用于 Android 的 Fortumo 应用内支付

转载 作者:行者123 更新时间:2023-11-29 09:14:54 25 4
gpt4 key购买 nike

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

这是主要的 Activity 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");
}
}

支付 Activity 类:

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();在将 32000 添加到计数器 int 的 Soundboard.java 中,然后更新 TextView。但是没有任何反应。希望有人能帮助我。谢谢!

最佳答案

我仍在努力完成这项工作。我认为您的 list 中有这件事是错误的:

PaymentStatusReceiver 这不是一个 Activity ,您只需要将其配置为接收器(就像您已经拥有的那样)。

关于java - 适用于 Android 的 Fortumo 应用内支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10086587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com