I integrated inappPurchase code to my android application.its working fine but i need handle
purchase data because if user buy my products after he uninstalled,after some days he again installed in the senario no need to purchase again.For this purpose how to handle data
Most of the data that you place is removed when user Uninstalls the file, so basically create a file or folder with details of his accounts in an encrypted format either on the phone or on the SD card (preferably use Phone storage)
but again if user does a factory reset on his phone then all information will be lost
So
Either create a web service and pass all the account information , you can use the Phones IMEI number to act as a unique ID or use login info for the user so you can identify him or her even if he or she changes her phone
or use Google's GCM to target individual customers
EDIT
Ya restoring is there Android In-app billing RESTORE_TRANSACTION usage
but what if your not using in built, but are using paypal SDK or some other methods then we have such the above mentioned options
You should maintain all the purchase data on the server side for each device.
You have to use RestoreTransactions function for getting the purchase data of the particular user.
mBillingService.restoreTransactions();
And in ResponseHandler.java file you will get all details in
public static void purchaseResponse(final Context context,
final PurchaseState purchaseState, final String productId,
final String orderId, final long purchaseTime,
final String developerPayload, final String purchaseToken) {
}
Items that are managed per user account can be purchased only once per user account. When an item is managed per user account, Google Play permanently stores the transaction information for each item on a per-user basis. This enables you to query Google Play with the RESTORE_TRANSACTIONS request and restore the state of the items a specific user has purchased.
Refer to this link:
http://developer.android.com/guide/google/play/billing/billing_admin.html
And read the section 'Choosing a Purchase Type'.
Related
I have read the google provided In-app billing sample for billing library v3, link is as follow:
https://github.com/android/play-billing-samples/tree/main/ClassyTaxiJava
In the sample, it use public class Constants
public static final String BASIC_SKU = "basic_subscription";
public static final String PREMIUM_SKU = "premium_subscription";
for the whole app.
I am wondering if a user can decompile or unpack the apk and change the product string or exchange the SKU string so that there may happen that the bought item A but receive bought item B function.
So I want to use getString(R.string.SKU_itemA) and getString(R.string.SKU_itemB) to try to make the text less explicit in code searching. Will I do this be safer to avoid user change?
If you have signature verification in your app, the only way to modify your app is to somehow defeat the signature verification. I suggest that you verify your app's signature, and it will protect you from any issues related to app cloning or app modification.
It does not make sense to just protect the SKU somehow: if the users are able to modify your app, they are also able to remove the check if the subscription has been purchased.
i have 2 different apps in the appstore, i am saving some data in a database (sql) like uid, ip, what page the user is on etc.
Is there a way to give a unique visitor an id or something like that so i can track the users activity in both apps.
And is it possible to see what buttons the user is clicking on.
I have added google analytics to the app but i only can see that there is a user on com.example.mainactivity and not the html pages that are the app.
Hope you guys understand what i mean.
You can use Google analytics to solve this problem with two different approaches. You can use the built in userId feature and it will even keep track of cross device sessions.
/**
* An example method called when a user signs in to an authentication system.
* #param User user represents a generic User object returned by an authentication system on sign in.
*/
public void onUserSignIn(User user) {
// Be careful when creating new trackers -- it is possible to create multiple trackers for the
// same tracking Id.
Tracker t = GoogleAnalytics.getInstance(context).newTracker("UA-XXXX-Y");
// You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
// sent with all subsequent hits.
t.set("&uid", user.getId());
// This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
t.send(new HitBuilders.EventBuilder().setCategory("UX").setAction("User Sign In").build());
}
Alternatively, you can use the Data Import feature to import external user infromation from multiple sources such as CRM data base and your SQL data base and you need to map their user representations to your own custom dimensions. You can follow the example in "Importing User Data to create AdWords Remarketing Lists" article. It shows how to use a custom dimension to represent a user id, and then upload even more custom dimensions about that user.
ga('create', 'UA-XXXX-Y', 'auto');
ga('require', 'displayfeatures');
ga('set', 'dimension1', 'NNNN'); // Where NNNN represents the CRM User Id.
ga('send', 'pageview');
Remember though Google Analytics does not support sending Personally Identifiable information, see the TOS.
I am working on In-App Prurchase in Android. After Purchasing an item, i set boolean value to be true using Shared Preference Api in Android.It works fine. Once i un-install and re-install my application,it make boolean value to be false.This is my code:
boolean buyUfo = false;
private static final String BUYUFO ="buyUfo";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
sharedPreference = this.getSharedPreferences(SHARED_PREFERENCE_ID, MODE_PRIVATE);
buyUfo = sharedPreference.getBoolean(BUYUFO, false);
}
//After In-App Purchase, when finish listener is called.
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener1 = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d("ufo", "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
Editor editor = sharedPreference.edit();
editor.putBoolean(BUYUFO, true);
editor.commit();
return;
}
}
I want this value to be true always for those who bought the item?..Please help
You can store it on the sdCard making a file for the same. But that can be deleted externally also.
For your concern, regarding:
I want this value to be true always for those who bought the item?
with the In-App purchase, after purchasing an item, you don't really Need to store whether it has been purchased or not. The API would do it for you, through which you can fetch the status of an item for a particular id.
To retrieve the list of product's owned by the user, your application
sends a getPurchases call to Google Play. Your application can make a
consumption request by sending a consumePurchase call. In the request
argument, you must specify the in-app product's unique purchaseToken
String that you obtained from Google Play when it was purchased.
Google Play returns a status code indicating if the consumption was
recorded successfully.
Read more on:
Consuming In-app Products, In-app Billing V3
OR
RESTORE_TRANSACTIONS in V2
See Storage options android. I recommend saving sensitive data in your server(also google recommends it). In device you could save data in Shared Preference(not secure in rooted device is deleted on uninstall) or internal storage(deleted on uninstall) or external storage and sqlite databases. Whatever you choose if your data is sensitive then always encrypt it.
Note There is no reliable way to save data in device that persists between multiple installations. If you save it in external storage it is always prone to user deletion.
That's not possible. If you tried implementing it that way, users would abuse your system by manually editing SharedPreferences.
User can clear his phone memory any time. You shouldn't rely on that. Instead, save value in your back end, and if user reinstalls app, check if it's the same user.
you have to store this value other than the sharedprefrences as,sharedprefrences are app specific and they are deleted when you uninstall and re-install the app.
What you can do is store this value on server and when the user installs the app again then you can retrieve the value and manipulate it according to its value
Saving the purchase information on sharedPreference is not the correct way. You should query the server to check if the user has purchased the item or not.
I have implement in app purchase (managed) in my application using billing services when ever user wants to buy item he will make purchase request that required internet even if user has already bought the item. so for user convenience i am doing that if user has bought the item then a value will be save in shared pref. and when ever user click on that particular item then 1st it will check shared pref. value that either user has bought item or not if not then go for purchase request else show him/her item.
My Question is that is it safe way? or i have to do something else?
This is not safe. I would discourage you from implementing such a check this way. You should rather go for standard approach and use getPurchases() method. You can call this method at any time (even offline) and if a user has purchases, they will be returned back from that method. Here is a sample code:
IInAppBillingService service; // initialize it first
Bundle response = service.getPurchases(3, "you app package", "inapp", null);
int responseCode = response.getInt(KEY_RESPONSE_CODE);
if (responseCode == RESPONSE_OK) {
ArrayList<String> purchases = response.getStringArrayList(KEY_INAPP_PURCHASE_ITEM_LIST);
...
}
Of curse you need to verify that purchases are signed with correct certificate and purchase state is not cancelled. But this is much safer than storing data in shared properties. Another advantage of this approach is that after user reinstalls the app, all purchases will be automatically available there too.
Complete example of this technique is within TrivialDrive sample app and it's work for me, but Im thinking about offline case. Google Play app caches purchases and gives responses to the getPurchases(3, "pkg", "inapp", null) offline but is this works infinitly or there is something like a timeout for this cache...
I have made an android app for amazon with in-app feature. Now I need to make my app live. My question is do I need to change any SKU string or so before uploading my app online? While testing my app, I had added a json file and an Sku string in my code, what do I replace them with?
Set<String>skuList = new HashSet<String>(1);
skuList.add(getResources().getString(R.string.consumable_sku));
PurchasingManager.initiateItemDataRequest(skuList);
Also, while initiating Purchase Response this skuString is being used.
PurchasingManager.initiatePurchaseRequest(skuString);
You can change it or not. When you define your product in the Amazon developer portal you will have the ability to define the IAP items for the app. For each IAP item you have to define multiple properties one of which is the sku. What matters is that the sku string in the portal match the request you make from the app. Other properties include price, description, title, and various associated images.