stranger!!!!
چهارشنبه 20 خرداد 1394, 16:53 عصر
سلام دوستان برنامه اماده کردم که حمایت درون برنامه ای هستش
چهارتا باتن حمایت وجود داره
اما همین مه برنامه اماده خرید میشه فورس کلوز میده و خارج میشه اینم کد BuyActivity
import java.util.ArrayList;
import java.util.Random;
import str.fekrbartar.tools.filter.whatsapp.R.id;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.util.IabHelper;
import com.util.IabHelper.OnIabPurchaseFinishedListener;
import com.util.IabHelper.OnIabSetupFinishedListener;
import com.util.IabHelper.QueryInventoryFinishedListener;
import com.util.IabResult;
import com.util.Inventory;
import com.util.Purchase;
import com.util.SkuDetails;
public class BuyActivity extends Activity {
TextView mes;
Button btn_1,btn_2,btn_3,btn_4;
String select_sku;
private IabHelper buyHelper;
// Getting the Price for the In-App SKU
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activiyt_buy);
mes = (TextView) findViewById(R.id.textView44);
btn_1 = (Button) findViewById(R.id.btn_1);
btn_2 = (Button) findViewById(R.id.btn_2);
btn_3 = (Button) findViewById(R.id.btn_3);
btn_4 = (Button) findViewById(R.id.btn_4);
btn_1.setEnabled(false);
btn_2.setEnabled(false);
btn_3.setEnabled(false);
btn_4.setEnabled(false);
try{buyHelper = new IabHelper(this,Billing. PUBLIC_KEY);}catch(Exception ex){return;}
buyHelper.startSetup(new OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if(result.isSuccess()) {
ArrayList<String> moreSkus = new ArrayList<String>();
moreSkus.add(Billing.SKU_Buy_1);
moreSkus.add(Billing.SKU_Buy_2);
moreSkus.add(Billing.SKU_Buy_3);
moreSkus.add(Billing.SKU_Buy_4);
mes.setText("....لطفا صبر کنید");
buyHelper.queryInventoryAsync(true, moreSkus, new QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
mes.setText("....آماده خرید");
btn_1.setEnabled(true);
btn_2.setEnabled(true);
btn_3.setEnabled(true);
btn_4.setEnabled(true);
}
});
}
}
});
}
public void click(View v) {
int reqCodeRandom;
try{
Random r=new Random();
reqCodeRandom = Math.abs(r.nextInt());
}
catch(Exception ex) {reqCodeRandom=100;}
switch (v.getId()) {
case id.btn_1: // btn_1
select_sku=Billing.SKU_Tea_1;
break;
case id.btn_2: // btn_2
select_sku=Billing.SKU_Buy_2;
break;
case id.btn_3: // btn_3
select_sku=Billing.SKU_Tea_3;
break;
case id.btn_4: // btn_4
select_sku=Billing.SKU_Tea_4;
break;
}
buyHelper.launchPurchaseFlow(this,select_sku, reqCodeRandom,
new OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isSuccess()) {
SharedPreferences shared = getSharedPreferences("log", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
if( select_sku.equals(Billing.SKU_Buy_1))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_2))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_3))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_4))
{
editor.putString("active","1");
}
else{
}
}
});
}
private void MasrafSeke(Purchase kala){
buyHelper.consumeAsync(kala, new IabHelper.OnConsumeFinishedListener() {
@Override
public void onConsumeFinished(Purchase purchase, IabResult result) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
buyHelper.handleActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
try{
super.onDestroy();
buyHelper.dispose();
}
catch (Exception e) {}
}
@Override
public void onBackPressed() {
backButtonHandler();
return;
}
public void backButtonHandler (){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
BuyActivity.this);
// set title
alertDialogBuilder.setTitle("خروج");
// set dialog message
alertDialogBuilder
.setMessage("از خرید منصرف شدید؟")
.setIcon(R.drawable.ic_launcher)
.setCancelable(false)
.setPositiveButton("بله",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
System.exit(id);
}
})
.setNegativeButton("ادامه میدهم",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
/*
@Override
public void onBackPressed() {
Intent ip=new Intent();
ip.setClass(BuyPremiumActivity.this,page3.class);
startActivity(ip);
Toast.makeText(getBaseContext(), "-----------------",Toast.LENGTH_SHORT).show();
}
*/
}
چهارتا باتن حمایت وجود داره
اما همین مه برنامه اماده خرید میشه فورس کلوز میده و خارج میشه اینم کد BuyActivity
import java.util.ArrayList;
import java.util.Random;
import str.fekrbartar.tools.filter.whatsapp.R.id;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.util.IabHelper;
import com.util.IabHelper.OnIabPurchaseFinishedListener;
import com.util.IabHelper.OnIabSetupFinishedListener;
import com.util.IabHelper.QueryInventoryFinishedListener;
import com.util.IabResult;
import com.util.Inventory;
import com.util.Purchase;
import com.util.SkuDetails;
public class BuyActivity extends Activity {
TextView mes;
Button btn_1,btn_2,btn_3,btn_4;
String select_sku;
private IabHelper buyHelper;
// Getting the Price for the In-App SKU
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activiyt_buy);
mes = (TextView) findViewById(R.id.textView44);
btn_1 = (Button) findViewById(R.id.btn_1);
btn_2 = (Button) findViewById(R.id.btn_2);
btn_3 = (Button) findViewById(R.id.btn_3);
btn_4 = (Button) findViewById(R.id.btn_4);
btn_1.setEnabled(false);
btn_2.setEnabled(false);
btn_3.setEnabled(false);
btn_4.setEnabled(false);
try{buyHelper = new IabHelper(this,Billing. PUBLIC_KEY);}catch(Exception ex){return;}
buyHelper.startSetup(new OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if(result.isSuccess()) {
ArrayList<String> moreSkus = new ArrayList<String>();
moreSkus.add(Billing.SKU_Buy_1);
moreSkus.add(Billing.SKU_Buy_2);
moreSkus.add(Billing.SKU_Buy_3);
moreSkus.add(Billing.SKU_Buy_4);
mes.setText("....لطفا صبر کنید");
buyHelper.queryInventoryAsync(true, moreSkus, new QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
mes.setText("....آماده خرید");
btn_1.setEnabled(true);
btn_2.setEnabled(true);
btn_3.setEnabled(true);
btn_4.setEnabled(true);
}
});
}
}
});
}
public void click(View v) {
int reqCodeRandom;
try{
Random r=new Random();
reqCodeRandom = Math.abs(r.nextInt());
}
catch(Exception ex) {reqCodeRandom=100;}
switch (v.getId()) {
case id.btn_1: // btn_1
select_sku=Billing.SKU_Tea_1;
break;
case id.btn_2: // btn_2
select_sku=Billing.SKU_Buy_2;
break;
case id.btn_3: // btn_3
select_sku=Billing.SKU_Tea_3;
break;
case id.btn_4: // btn_4
select_sku=Billing.SKU_Tea_4;
break;
}
buyHelper.launchPurchaseFlow(this,select_sku, reqCodeRandom,
new OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isSuccess()) {
SharedPreferences shared = getSharedPreferences("log", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
if( select_sku.equals(Billing.SKU_Buy_1))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_2))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_3))
{
editor.putString("active","1");
}
if( select_sku.equals(Billing.SKU_Buy_4))
{
editor.putString("active","1");
}
else{
}
}
});
}
private void MasrafSeke(Purchase kala){
buyHelper.consumeAsync(kala, new IabHelper.OnConsumeFinishedListener() {
@Override
public void onConsumeFinished(Purchase purchase, IabResult result) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
buyHelper.handleActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
try{
super.onDestroy();
buyHelper.dispose();
}
catch (Exception e) {}
}
@Override
public void onBackPressed() {
backButtonHandler();
return;
}
public void backButtonHandler (){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
BuyActivity.this);
// set title
alertDialogBuilder.setTitle("خروج");
// set dialog message
alertDialogBuilder
.setMessage("از خرید منصرف شدید؟")
.setIcon(R.drawable.ic_launcher)
.setCancelable(false)
.setPositiveButton("بله",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
System.exit(id);
}
})
.setNegativeButton("ادامه میدهم",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
/*
@Override
public void onBackPressed() {
Intent ip=new Intent();
ip.setClass(BuyPremiumActivity.this,page3.class);
startActivity(ip);
Toast.makeText(getBaseContext(), "-----------------",Toast.LENGTH_SHORT).show();
}
*/
}