当我在OnCreate中使用这行代码时:
bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
App无法启动,Logcat告诉我:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.niclas.myapplication/com.example.niclas.myapplication.MainActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND
我该如何解决这个问题?如果需要更多代码,我将编辑我的问题。
我想在这个上下文中使用这一行代码:
ServiceConnection mServiceConn = new ServiceConnection()
{
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{
mService = IInAppBillingService.Stub.asInterface(service);
Log.d("TEST", "mService ready to go!");
checkownedItems();
}
@Override
public void onServiceDisconnected(ComponentName name)
{
mService = null;
}
};
private void checkownedItems() {
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
if (ownedItems.getInt("RESPONSE_CODE") == 0) {
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");
if (purchaseDataList.size() > 0) {
//Item(s) owned
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
String signature = signatureList.get(i); //Note signatures do not appear to work with android.test.purchased (silly google)
String sku = ownedSkus.get(i);
}
} else {//Item(s) not owned
String base64EncodedPublicKey =
"myPublicKey";
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d("TEST", "In-app Billing setup failed: " + result);
} else {
Log.d("TEST", "In-app Billing is set up OK");
}
}
});
}
} else {
//Error checking owned items
}
} catch (RemoteException e) {
e.printStackTrace();
}
}