انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
فورس کلوز دادن برنامه اندروید در صورت کار کردن سریع

فورس کلوز دادن برنامه اندروید در صورت کار کردن سریع

#4
این کل کد هایی هستش که در این فورس کلوز می ده
کد پی‌اچ‌پی:
package ir.windroid.erfannj;

import android.annotation.*;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import com.util.*;
import com.util.IabHelper.*;
import java.util.*;



@
SuppressLint("NewApi") public class BuyPremiumActivity extends Activity
{

/////***************
    
protected static final int BUY_REQUEST_CODE 12345;
    
    private 
IabHelper buyHelper;
    private 
Button butBuy;
    
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener;
    
IabHelper.QueryInventoryFinishedListener mGotInventoryListener;
////***************

    
@Override
    
protected void onCreate(Bundle savedInstanceState)
    {
        
super.onCreate(savedInstanceState);
        
requestWindowFeature(Window.FEATURE_NO_TITLE);
        
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
                             
WindowManager.LayoutParams.FLAG_FULLSCREEN); 
        
setContentView(R.layout.buy_premium_activity);



///////////******************

//  1
//*** amadesazi

        
butBuy = (ButtonfindViewById(R.id.button_buy);
        
butBuy.setEnabled(false);
        
butBuy.setText("لطفا صبر کنید");
        
buyHelper = new IabHelper(thisBilling.PUBLIC_KEY);

        
buyHelper.startSetup(new OnIabSetupFinishedListener() {
                @
Override

                
public void onIabSetupFinished(IabResult result)
                {
                    if (
result.isSuccess())
                    {            

                        final 
ArrayList<StringmoreSkus = new ArrayList<String>();
                        
moreSkus.add(Billing.SKU_NAME_PREMIUM);

                        
//buyHelper.queryInventoryAsync(true, moreSkus, mGotInventoryListener);
                        
final TextView tvPrice = (TextViewfindViewById(R.id.price);
                        
tvPrice.setText("در حال انتظار جهت دریافت قیمت");

                        
// Start the query for the details for the SKUs. This runs asynchronously, so
                        // it may be that the price appears a bit later after the rest of the Activity is shown.
                        
buyHelper.queryInventoryAsync(truemoreSkus, new QueryInventoryFinishedListener() {
                                @
Override
                                
public void onQueryInventoryFinished(IabResult resultInventory inv) {
                                    if(
result.isSuccess()) {


                                        
// If we successfully got the price, show it in the text field
                                        
SkuDetails details inv.getSkuDetails(Billing.SKU_NAME_PREMIUM);
                                        
String price details.getPrice();

                                        
tvPrice.setText(price);

                                        
// On successful init and price getting, enable the "buy me" button
                                        
butBuy.setEnabled(true);
                                    } else {
                                        
// Error getting the price... show a sorry text in the price field now
                                        
tvPrice.setText("قیمت دریافت نشد");
                                        
//
                                        
butBuy.setEnabled(true);
                                        
//
                                    
}
                                }


                            });
                        
                        
                        
butBuy.setEnabled(false);
                        
butBuy.setText("ارتقا به نسخه کامل");

                    }
                }
            });


//  2
        
butBuy.setOnClickListener(new OnClickListener()
            {
                @
Override
                
public void onClick(View v)
                {

                    if (
Billing.isPackageInstalled(getBaseContext(), "com.farsitel.bazaar"))
                    {
                        if (
Billing.isConnected(getBaseContext()))
                        {

                            
buyHelper.launchPurchaseFlow(BuyPremiumActivity.thisBilling.SKU_NAME_PREMIUMBilling.BUY_REQUEST_CODEmPurchaseFinishedListener"payload-string");

                        }
                        else
                        {
                            
Billing.toast(getBaseContext(), "لطفا ابتدا به اینترنت متصل شوید");


                        }
                    }
                    else
                    {
                        
Billing.toast(getBaseContext(), "لطفا برنامه بازار را بر روی دستگاه خود نصب نمایید!");

                    }
                }

            });
        
//////////////**********************        

        // kodhaye digar        





        // end of contenView۰
    
}



//////////////////////********************    
//  3
    
public BuyPremiumActivity()
    {

//  3-1
        
this.mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener(){
            @
Override
            
public void onIabPurchaseFinished(IabResult resultPurchase info)
            {
                if ((
result.isSuccess()))
                {
                    
SharedPreferences shared getSharedPreferences("Prefs"MODE_PRIVATE);
                    
SharedPreferences.Editor editor shared.edit();
                    
editor.putString(Billing.p_tokeninfo.getToken());
                    
editor.apply();




                    
String msg="در حال بررسی وضعیت خرید...";
                    
Billing.toast(getBaseContext(), msg);
                    
butBuy.setEnabled(false);
                    
butBuy.setText("بررسی خرید");

                    new 
verify_buying().execute(Billing.urls);

                }
                else
                {
                    
Billing.toast(getBaseContext(), "خرید ناموفق");
                }
            }
        };

//  3-2

        
mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener(){

            @
Override
            
public void onQueryInventoryFinished(IabResult iabResultInventory inventory)
            {

                if (
iabResult.isSuccess())
                {
                    
butBuy.setEnabled(true);
                    
butBuy.setText("ارتقا به نسخه کامل");
                    
boolean premium inventory.hasPurchase(Billing.SKU_NAME_PREMIUM);
                    if (
premium)
                    {
                        new 
verify_buying().execute(Billing.urls);
                    }
                }
                else
                {
                    
butBuy.setEnabled(true);
                    
butBuy.setText("ارتقا به نسخه کامل");
                }
            }
        };


    }    




//  4
    
@Override
    
protected void onActivityResult(int requestCodeint resultCodeIntent data)
    {
        
super.onActivityResult(requestCoderesultCodedata);

        
buyHelper.handleActivityResult(requestCoderesultCodedata);
    }

    @
Override
    
protected void onDestroy()
    {
        
super.onDestroy();
        
buyHelper.dispose();
    }

// 5
    
private class verify_buying extends AsyncTask<StringVoidString>
    {
        @
Override
        
protected String doInBackground(String... urls)
        {

            if (
Billing.isConnected(getBaseContext()))
            {

                
SharedPreferences shared getSharedPreferences("Prefs"MODE_PRIVATE);
                
int no=shared.getInt("no"0);                        

                return 
Billing.GET_Server_Response(nogetBaseContext());

            }

            return 
null;
        }

        
// onPostExecute displays the results of the AsyncTask.
        
@Override
        
protected void onPostExecute(String result)
        {
            
//---1
            
if (result.contains("purchase: ok"))
            {

                
Billing.saveData(getBaseContext());

            }
            
//---2
            
else if (result.isEmpty())
            {

                
butBuy.setEnabled(true);
                
butBuy.setText("ارتقا به نسخه کامل");

                
Billing.toast(getBaseContext(), "لطفا در صورت نصب لاکی پچر آن را حذف کنید.");

            }
            
//---3
            
else if (result.contains("HTML"))
            {
                
SharedPreferences shared getSharedPreferences("Prefs"MODE_PRIVATE);
                
SharedPreferences.Editor editor shared.edit();
                
editor.putInt("no"1);
                
editor.apply();

                
butBuy.setEnabled(true);
                
butBuy.setText("ارتقا به نسخه کامل");
                
Billing.toast(getBaseContext(), "خطا در ارتباط با سرور!!\nلطفا دوباره تلاش کنید..");
            }
        }
/////////************************************

    /// kodhaye digar
}
            
    @
Override
    
public void onBackPressed() {
        
// TODO Auto-generated method stub
        
    
        
final Dialog dialog = new Dialog(this);
        
        
dialog.getWindow();
        
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        
dialog.setContentView(R.layout.exit_menu_buy); 
        

        
Button notexit = (Buttondialog.findViewById(R.id.no);
        
// if button is clicked, close the custom dialog
        
notexit.setOnClickListener(new OnClickListener() {
                @
Override
                
public void onClick(View v) {
                    
dialog.dismiss();
                }
            }); 
            
        
Button yesexit = (Buttondialog.findViewById(R.id.yes);
        
// if button is clicked, close the custom dialog
        
yesexit.setOnClickListener(new OnClickListener() {
                @
Override
                
public void onClick(View v) {
                    
finish();
                }
            }); 
            
        
dialog.show();
    }} 
 باید این کد را کجاش بنویسم
کد پی‌اچ‌پی:
    BuyPremiumActivity.cancel(true); 

 
پاسخ
 سپاس شده توسط شماره مجازی امارات


پیام‌های این موضوع
RE: فورس کلوز دادن برنامه اندروید در صورت کار کردن سریع - توسط Erfannj - ۱۳۹۴/۰۵/۲۴, ۰۹:۴۵ ق.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان