PDA

View Full Version : اجرای اکتیویتی از کلاسی دیگر



omid_student
سه شنبه 22 بهمن 1392, 16:36 عصر
سلام دوستان
من سورس درون پرداخت رو دانلود کردم
حالا کنارش یه کلاس درست کردم و میخوام یه یه نمونه از درون پرداخت ایجاد کنم و اجراش کنم
ولی خطا میده
کد زیر هم نمونش هست

Main m1 = new Main();
m1.startActivity(m1.getIntent());

amirarcs
سه شنبه 22 بهمن 1392, 16:45 عصر
به این صورت نمیتونی اجرا کنی.

به کد نمونه زیر یه نگاه بنداز




package com.hamed.billing;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.hamed.billing.util.IabHelper;
import com.hamed.billing.util.IabResult;
import com.hamed.billing.util.Inventory;
import com.hamed.billing.util.Purchase;
public class Main extends Activity {
Button btn1;
// Debug tag, for logging
static final String TAG = "testbilling";
// SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "hamed.test";
// Does the user have the premium upgrade?
boolean mIsPremium;
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001;
// The helper object
IabHelper mHelper;
SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sp = getSharedPreferences("setting", 0);
//وضعیت خریداری شده را از وضعیت ذخیره شده قبلی می خوانیم و در حالتی که بارا ول بود مقدارش false می شود
mIsPremium = sp.getBoolean("purchased", false);
setContentView(R.layout.main);
btn1 = (Button) findViewById(R.id.button1);
//با توجه به مقدار خریداری شده در ابتدا می توانیم صفحه را render کنیم
updateUi();
String base64EncodedPublicKey = "MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwDHPaX/2b58zYjvRygXQvYgvIWjCT7A0FirRkmt5Nm3FxnjsOnCu/6Yer9AoOFd+EYU+uORahbZXge39DzyMKwiatY0UcVycaI8bU+g JAAvwL+/BxSifJ+jrHRbWCg9Nd6dnIYSMuGyoFM/3cdX+6XSYh0R58adtGlWBVBUc0/GmGPMFCkx1JndO2wBZrzMc2eO+OTqoFY+EyLospMP3GHlGgI6w 1JvtAip7P+hD10CAwEAAQ==";
// You can find it in your Bazaar console, in the Dealers section.
// It is recommended to add more security than just pasting it in your source code;
mHelper = new IabHelper(this, base64EncodedPublicKey);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
return;
}
// Hooray, IAB is fully set up!
//بعد از راه اندازی موفقیت امیز آمیز می توانیم وضعیت خرید کاربر فعلی ار چک کنیم
mHelper.queryInventoryAsync(mGotInventoryListener) ;
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
//اگر کاربری لاگین نباشد یا هر خطایی دگیری رخ داده باشد
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
} else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
//مقدار جدید وضعیت خریداری شده را ذخیره می کنیم
savePurchaseStatus();
// و صفحه را اگر لازم بود مجددا render می کنیم
updateUi();
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}

setWaitScreen(false);
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
private void savePurchaseStatus() {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("purchased", mIsPremium);
editor.commit();
}
private boolean isPurchased() {
return sp.getBoolean("purchased", false);
}
public void onUpgradeAppButtonClicked(View arg0) {
Log.d(TAG, "Upgrade button clicked; launching purchase flow for upgrade.");
setWaitScreen(true);

/* TODO: for security, generate your payload here for verification. See the comments on
* verifyDeveloperPayload() for more info. Since this is a SAMPLE, we just use
* an empty string, but on a production app you should carefully generate this. */
String payload = "qwertyuiop";
mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST,
mPurchaseFinishedListener, "qwertyuiop");
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();

return true;
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
setWaitScreen(false);
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_PREMIUM)) {
Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
alert("Thank you for upgrading to premium!");
mIsPremium = true;
//وضعیت خریداری شده را برای استفاده در دفعات بعدی ذخیره می کنیم
savePurchaseStatus();
// صفحه را مجددا رندر می کنیم
updateUi();
setWaitScreen(false);
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Destroying helper.");
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
public void updateUi() {
// update the car color to reflect premium status or lack thereof
final Button btn2 = (Button) findViewById(R.id.btn2);
//اگر خریداری شده بود دکه قابل مشاهدهو در غیر اینوصورت ناپدید می شود
if (mIsPremium) {
btn2.setVisibility(View.VISIBLE);//
} else {
btn2.setVisibility(View.GONE);
}
}
// Enables or disables the "please wait" screen.
void setWaitScreen(boolean set) {
findViewById(R.id.screen_wait).setVisibility(set ? View.VISIBLE : View.GONE);
}
void complain(String message) {
Log.e(TAG, "**** testbilling Error: " + message);
alert("Error: " + message);
}
void alert(String message) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(message);
bld.setNeutralButton("OK", null);
Log.d(TAG, "Showing alert dialog: " + message);
bld.create().show();
}
}