2015-03-02 4 views
0

Я пытаюсь сделать приложение, которое я могу получить простой реализации в покупках приложений. Я падал с этого гида http://www.techotopia.com/index.php/Integrating_Google_Play_In-app_Billing_into_an_Android_Application_%E2%80%93_A_TutorialInAppBilling аварии при запуске

но это чревато, вероятно, устаревшей информацией и пренебрегает включением всех имен пакетов, которые необходимо загрузить из диспетчера SDK. Основные ошибки, которые я получал от этой программы, были, по-видимому, справочными ошибками, например, я не импортировал определенную библиотеку или файлы совместимости. Мне удалось разрешить все из них в eclipse и ошибок нет, когда я запускаю код, но пытаюсь его на устройстве или в виртуальной машине, приложение падает, когда я пытаюсь запустить его там.

Я исключил ключ, который вам нужен для игрового соединения google по понятным причинам.

package com.a.inappbilling; 

import com.a.inappbilling.util.IabHelper; 
import com.a.inappbilling.util.IabResult; 
import com.a.inappbilling.util.Inventory; 
import com.a.inappbilling.util.Purchase; 

import android.support.v7.app.ActionBarActivity; 
import android.support.v7.app.ActionBar; 
import android.support.v4.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.os.Build; 
import android.widget.Button; 
import android.content.Intent; 
import android.util.Log; 


public class InAppBillingActivity extends ActionBarActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_in_app_billing); 
    if (savedInstanceState == null) { 
     getSupportFragmentManager().beginTransaction() 
       .add(R.id.container, new PlaceholderFragment()).commit(); 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.in_app_billing, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

/** 
* A placeholder fragment containing a simple view. 
*/ 
public static class PlaceholderFragment extends Fragment { 

    public PlaceholderFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_in_app_billing, 
       container, false); 
     return rootView; 
    } 
} 

private Button clickButton; 
private Button buyButton; 

@Override 
protected void onStart() { 
    super.onStart(); 
    buyButton = (Button)findViewById(R.id.buyButton); 
    clickButton = (Button)findViewById(R.id.clickButton); 
    clickButton.setEnabled(false); 

    String base64EncodedPublicKey = 
      "key here"; 

    mHelper = new IabHelper(this, base64EncodedPublicKey); 

    mHelper.startSetup(new 
      IabHelper.OnIabSetupFinishedListener() { 
       public void onIabSetupFinished(IabResult result) 
      { 
         if (!result.isSuccess()) { 
         Log.d(TAG, "In-app Billing setup failed: " + 
        result); 
         } else {    
         Log.d(TAG, "In-app Billing is set up OK"); 
        } 
        } 
    }); 
} 

public void buttonClicked (View view) 
{ 
    clickButton.setEnabled(false); 
    buyButton.setEnabled(true); 
} 

private static final String TAG = "com.a.inappbilling"; 
IabHelper mHelper; 

}

ответ

0

Добавить разрешение на файл манифеста

<uses-permission android:name="com.android.vending.BILLING" /> 

также добавить в файл манифеста под Application узла

<meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 

Кроме того, только удостовериться, что вы добавили InAppBillingActivity.java в ваш файл манифеста.

Смежные вопросы