I am using following code to find weather this user is premium user or not. Weather the user has purchase in app billing or not. But when i call this method isPremium(). it gives right result first time only but when i do it after first time, it always give wrong result. The mService variable of IInAppBillingService is null. Can some one tell me what could be reason of it. The code is as below.
public boolean isPremium() {
boolean mIsPremium = false;
Log.d(TAG, "::isPremium:" + "mService:"+mService);
if(mService==null){
return mIsPremium;
}
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(),
"inapp", null);
if (ownedItems != null) {
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList ownedSkus = ownedItems
.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList purchaseDataList = ownedItems
.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList signatureList = ownedItems
.getStringArrayList("INAPP_DATA_SIGNATURE");
String continuationToken = ownedItems
.getString("INAPP_CONTINUATION_TOKEN");
for (int i = 0; i < purchaseDataList.size(); ++i) {
String signature = null;
String purchaseData = (String) purchaseDataList.get(i);
if (signatureList != null)
signature = (String) signatureList.get(i);
String sku = (String) ownedSkus.get(i);
Log.d(TAG, "::isPremium:" + "sku:" + sku);
Log.d(TAG, "::isPremium:" + "purchaseData:"
+ purchaseData);
Log.d(TAG, "::isPremium:" + "signature:" + signature);
if (sku.equalsIgnoreCase(SKU_PREMIUM)) {
Log.d(TAG, "::isPremium:" + "Already Purchased");
return true;
}
// do something with this purchase information
// e.g. display the updated list of products owned by
// user
}
// if continuationToken != null, call getPurchases again
// and pass in the token to retrieve more items
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mIsPremium;
}
The following is code to initialize service. where every time i come to service. i only get "onServiceConnected " log. and never got log ":onServiceDisconnected:"
ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "::onServiceDisconnected:" + "");
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "::onServiceConnected:" + "");
mService = IInAppBillingService.Stub.asInterface(service);
}
};
So can some one give me idea what could be reason of mService becoming null after first time ? Should we only call it 1 time only ? is my service getting disconnected ? But i could not see it in my log.