我按照指南进入应用内购买并解锁所有功能。购买程序运作良好。 我解释一下我做了什么:我在我的数据库中添加了一个检查,它会计算表格中的记录数量,如果数字是> = 1,我在应用程序中打开要购买的活动。一旦购买,通过方法getPurchases,控制购买,如果完成,我打开活动,否则我打开活动购买。我创建了这个代码peril控件,但是我收到了错误:
08-11 18:08:18.120: W/ContextImpl(19293): Implicit intents with startService
are not safe: Intent {
act=com.android.vending.billing.InAppBillingService.BIND }
android.content.ContextWrapper.bindService:529
main.Elenco_F_Fragment.Controlla_record_per_acquisto:243
main.Elenco_F_Fragment.access$9:233
这是第243行:
final boolean blnBind = getActivity().bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
这是控件的代码
private void Controlla_record_per_acquisto(){
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
String controllo = "SELECT COUNT(_id) FROM tbf";
Cursor c = db.rawQuery(controllo, null);
while (c.moveToNext()){
int numero_id = c.getInt(0);
if(numero_id >=1){
// Bind Service
final boolean blnBind = getActivity().bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
if (!blnBind) return;
if (mService == null) return;
Bundle ownedItems;
try {
ownedItems = mService.getPurchases(3, getActivity().getPackageName(), "inapp", null);
Intent intent = null;
intent = new Intent(getActivity(), Crea_e.class);
startActivity(intent);
} catch (RemoteException e) {
e.printStackTrace();
Toast.makeText(context, "getPurchases - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getPurchases() - fail!");
return;
}
int response = ownedItems.getInt("RESPONSE_CODE");
Toast.makeText(context, "getPurchases() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getPurchases() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) return;
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
Log.i(tag, "getPurchases() - \"INAPP_PURCHASE_ITEM_LIST\" return " + ownedSkus.toString());
Log.i(tag, "getPurchases() - \"INAPP_PURCHASE_DATA_LIST\" return " + purchaseDataList.toString());
Log.i(tag, "getPurchases() - \"INAPP_DATA_SIGNATURE\" return " + (signatureList != null ? signatureList.toString() : "null"));
Log.i(tag, "getPurchases() - \"INAPP_CONTINUATION_TOKEN\" return " + (continuationToken != null ? continuationToken : "null"));
}else {
Intent intent = null;
intent = new Intent(getActivity(), InAppBillingActivity.class);
startActivity(intent);
}
c.close();
db.close();
}
}
EDIT --------------------------------------------
private void Controlla_record_per_acquisto(){
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
String controllo = "SELECT COUNT(_id) FROM FTB";
Cursor c = db.rawQuery(controllo, null);
while (c.moveToNext()){
int numero_id = c.getInt(0);
if(numero_id >=1){
Intent intent = null;
intent = new Intent(getActivity(), InAppBillingActivity.class);
startActivity(intent);
}else {
Intent intent = null;
intent = new Intent(getActivity(), Cure.class);
startActivity(intent);
}
c.close();
db.close();
}
}
答案 0 :(得分:0)
我建议您使用新的结算系统,使用IabHelper
类,您可以执行上面描述的异步/同步,而不需要&#34;额外&#34;代码真的。
http://developer.android.com/training/in-app-billing/preparing-iab-app.html