For my testing I used:
private static final String SKU_PRO = "android.test.purchased";
Now I want to release my app and create the purchasable item in the developer console. Before releasing the apk I have to know how to name the SKU.
In a tutorial I read they used this:
"com.example.buttonclick"
But my packagename looks like this:
"com.myname.myapp"
My suggestion is:
"com.myname.myapp.purchasedpro"
Is this the correct way?
From developer docs:
Product ID
Product IDs are unique across an app's namespace. A product
ID must start with a lowercase letter or a number and must be composed
of only lowercase letters (a-z), numbers (0-9), underscores (_), and
periods (.). The product ID android.test is reserved, as are all
product IDs that start with android.test.
Note: Be sure to plan your
product ID namespace carefully. You cannot modify an item's product ID
after the item is created, and you cannot reuse a product ID within an
app.
Related
I am developing a cross platform game for which I needs to generate unique identifier (User ID) for each user. I known some platform (Android or iOS) specific approaches to get device related identifiers but I am looking for a solution independent of the device identifiers.
User ID Requirements:
Independent of the device's platform
Offline implementation (no communication with any servers)
Without sign-up process
I have implemented one approach to create User IDs where I store the system time when the game was launched for the first time on the device.
I have following questions:
Are there any other approaches to generate User IDs (which will meet the above requirements)?
What are the common approaches to create unique identifiers with taking any information from the user?
Are there any third party plug-ins to implement User IDs?
I would appreciate any suggestions and thoughts on this topic.
EDIT:
There are lot of responses to use UUID/GUID. Generally, this approach looks fine but I am looking for a solution which can generate same User ID even if the user reinstall the game.
Have you looked at UUID from Java?
https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html
EDIT: The following links might help using UUID for unique identifiers.
Best practices for permissions & Identifiers
Instance ID
When you say user id, are you talking about a public id such as an username, or a database id?
If you are talking about a database id, go for a GUID/UUID. T-sql for example have the NEWID() method that will return a GUID that doesn't exist in the database yet. I am sure that whichever database you go for you will find some way to use a GUID.
https://learn.microsoft.com/en-us/sql/t-sql/functions/newid-transact-sql
As per my opinion your System current time is the best method for generating Unique User Id.
For Android :
System.currentTimeMillis() returns you the unique 13 digit number which can be used as User Id.
But When you get current time in iOS then it is 10 digit number which generates. So you can multiply it by 1000 to make User Id platform Independent.
Happy Coding...
Assuming that your usernames are unique, you could simply takje the md5 hash of your usernames to get an unique ID (string). e.g. in php:
$userID = md5($username);
because m5 hash functions exist in nearly every programming language you should be able to use this ID on all possible plattforms.
And if you arer looking for a numeric ID, you even can calculate a qunique number from md5.
See represent md5-hash as an integer - stack question for more details
Just generate a long string of random characters. For example, generates a 10 long string of alphanumerics ...
private String GetId(){
String[] chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};
StringBuilder s = new StringBuilder(10);
for(int i = 0;i<10;i++){
int pos = (int) (Math.random() * 62);
String c = "";
if (pos > chars.length-1){
pos = pos - chars.length;
c = chars[pos].toUpperCase();
}else{
c = chars[pos];
}
s.append(c);
}
return s.toString();
}
I'd like the use the getSkuDetails() call from the In-app Billing v3 API to dynamically display a list of inapp purchase options with properly translated titles and relevant price.
However, the "title" property from getSkuDetails() seems to always be of the form "<item title> (app name)", which is less than useful. How can I get only the item title itself without the app name without hacking the string?
That is the way it is. I mean even I didn't like it, obviously user knows that he is buying from the app but I think Google is going to reply it in this way only
As no one has replied with an actual regex pattern to match the app name in parentheses in the SKU title I thought I just post the code here for further reference:
// matches the last text surrounded by parentheses at the end of the SKU title
val skuTitleAppNameRegex = """(?> \(.+?\))$""".toRegex()
val titleWithoutAppName = skuDetails.title.replace(skuTitleAppNameRegex, "")
The regex is as strict as possible to allow for additional text in parentheses within your SKU title without removing it as well (e.g. SKU titles like Premium (Subscription) would stay as they are). The only thing you should avoid is parentheses in your app name, but with a little tweaking of the regex you could work around that as well.
As regexes are notoriously expensive to build it is advisable to store it in a field and avoid constructing them each time over when you are parsing your SKUs.
Adapting #ubuntudroid answer to Java, I made it work like this:
String skuTitleAppNameRegex = "(?> \\(.+?\\))$";
Pattern p = Pattern.compile(skuTitleAppNameRegex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(skuDetails.getTitle());
String titleWithoutAppName = m.replaceAll("");
String productTitleWithAppName=skuDetails.getTitle();
String productTitleWithoutAppName = productTitleWithAppName.substring(0, productTitleWithAppName.indexOf("("));
You don't need to use regex for this. The following should work. This is in C# but you can guess how you can do it in Java or any other language.
string title = getTitle(); // get title
int appNameStartIndex = title.LastIndexOf("("); // find last index of (.
string titleWithoutAppName = title.Substring(0, appNameStartIndex); // and :)
In fact, the name of the SKU without the app name in parantheses is transfered with the SKU, but there is no getter to retrieve it.
If you have a deeper look into the implementation of SkuDetails class, then you see, that this whole thing is based on a json String (also debugging gives you this json).
And this json string contains not only the title with the apps name, but also a name field with the SKUs name only.
The SKUs json representation can be retrieved with SkuDetails.getOriginalJson().
So if it better fits your needs, then you can of course retrieve the SKU name directly from the data, returned from Google.
I found that in development builds, I'd get a value like My product (com.test.myapp (unreviewed)). Here's a version of the regex that handles the nested parentheses and keeps other parentheses in your product name intact:
const removeAppNameFromProductTitle = (title: string) => {
const regex = /( \([^()]*\)$)|( \([^)]*\)\)$)/im;
return title.replace(regex, '');
};
The code is in TypeScript (React Native), but I'm sure you can adapt. Here's a gist with test cases: https://gist.github.com/thmsobrmlr/732ecf958f600ec38e89c4e8ff57f3dd.
Android's PackageManager class has currentToCanonicalPackageNames() and canonicalToCurrentPackageNames() methods. What exactly is canonical package name? Where is it used (what's its purpose)? When does it differ from a current package name?
For example, on my Nexus S the current package name for browser app is "com.google.android.browser", and its canonical name is the same "com.google.android.browser". For some other applications I've checked I also get same current and canonical package names. Neither developer.android.com, nor source code gives me an explanation of what exactly is canonical package name. Hope this helps to better understand what I'm asking above.
Here is developer documentation:
http://developer.android.com/reference/android/content/pm/PackageManager.html
public abstract String[] currentToCanonicalPackageNames (String[] names)
Added in API level 8
Map from the current package names in use on the device to whatever the current canonical name of that package is.
Parameters
names Array of current names to be mapped.
Returns
Returns an array of the same size as the original, containing the canonical name for each package.
public abstract String[] canonicalToCurrentPackageNames (String[] names)
Added in API level 8
Map from a packages canonical name to the current name in use on the device.
Parameters
names Array of new names to be mapped.
Returns
Returns an array of the same size as the original, containing the current name for each package.
Check out this link of the source for a better understanding:
https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/app/ApplicationPackageManager.java
And please refer to this StackOverflow question: how do i get canonical names of packages of deafult apps in Android
I ask this because I have exceptions from reports (from users from the market), mentioning that I have duplicated views with id 0x2 (or 0x3).
Since all my generated ids are really big, I think that the views with duplicated ids are views with no specifically defined ids.
My question is what are the ids of the views, that the developer hasn't explicitly assigned ids to them.
Thanks in advance,
Danail
The AAPT constantly updates your R file to generate unique hexadecimal values for each of your own IDs. In terms of IDs YOU create, they only need to be unique within the parent viewgroup. As always please post your stacktrace.
According to the source code, a View for which you haven't set an ID, has an ID of -1.
public static final int NO_ID = -1;
I would say no id is created if you do not specify an id to a view. Try creating a very simple application and create components with no id's , you'll notice that no id's are created in the R.java file.
How my in-app product ID should look like?
If my application ID looks like com.example.test, then can I define product ID just as item? Or should it be com.example.test.item?
Ok, I've tested that.
Product ID should be unique within your application. So item can be used. Everywhere it will be reflected as com.example.test:item.
To be clear, you use exactly what you typed when creating the product.
It could be "productname" or "com.company.app.productname" depending on what your typed in. See the image.
http://i.imgur.com/5hKdziE.jpg