I am new in Android and I was getting a different "PackageName" from:
context.getPackageName() --> (return the application id?)
instead of using getClass().getPackage().toString()
But I cannot change that part of the code.
So my workaround was to change the applicationId from build.gradle, and package in manifest.
The context.getPackageName() method is used to identify the application using the application id, like com.whatsapp or com.facebook.orca it may be used during interprocess communication.
If you want to identify the package that your class is located you should use getClass().getPackage().toString().
Notice that the application id may not be the same as the package name of your class.
I also recommend that you DON'T change the application id on the manifest if the app is already on the Playstore, since it is an unique indentifier and it will probably don't let you update the app with a different id
Related
I've recently started creating an app for Android. but i do not have a Website.
how to get Package name. Can i make it com.example.(app name) ?
and how to know if it is available or not ?
package name have no concern with any website. It is used to identify your application uniquely in your mobile phone and in any App store. You can set any name or string in your package name i.e com.example.myfirstapplication
it is not necessary that there should be com.example in the package name you can change them also i.e my.first.application.packagename
You can set whatever package name you like, as long as it isnt already taken when you publish it on the playstore.
More good reading: https://stackoverflow.com/a/6273935/5644761
What is the difference between changing package name vs applicationId to the final apk.
I know it is different for aspect of keeping source code, but lets say I got some app with package name a.b.c.d.
What will be the difference in the builded apk file
if I rename the a.b.c.d into q.w.e.r and then build the apk file
vs
change the applicationId into gradle with q.w.e.r
The package name is just to organize your code.
The applicationId, on the other hand, is used to identify your app in the Play Store. You will change this only if you plan to generate another app based on same code.
From docs (https://developer.android.com/studio/build/application-id.html):
When you create a new project in Android Studio, the applicationId
exactly matches the Java-style package name you chose during setup.
However, the application ID and package name are independent of each
other beyond this point. You can change your code's package name (your
code namespace) and it will not affect the application ID, and vice
versa (though, again, you should not change your application ID once
you publish your app). However, changing the package name has other
consequences you should be aware of, so see the section about
modifying the package name.
Some Android API like google map and firebase ask for your package name when you create the key. That package name they refer to is actually your applicationId. Yup Google insist on using the term package name for these API key. Don't get it confuse.
Taken from doc (https://developer.android.com/studio/build/configure-app-module#set_the_application_id):
"Note: The application ID used to be directly tied to your code's package name; so some Android APIs use the term "package name" in their method names and parameter names, but this is actually your application ID. For example, the Context.getPackageName() method returns your application ID. There's no need to ever share your code's true package name outside your app code."
Application id mostly used for:
Change the application ID for testing
Change the application ID for build variants
In this case, each build variant should be defined as a separate
product flavor. For each flavor inside the productFlavors {} block,
you can redefine the applicationId property, or you can instead append
a segment to the default application ID using applicationIdSuffix, as
shown here:
Every Android app has a unique application ID that looks like a Java
package name, such as com.example.myapp. This ID uniquely identifies
your app on the device and in Google Play Store. If you want to upload
a new version of your app, the application ID (and the certificate you
sign it with) must be the same as the original APK—if you change the
application ID, Google Play Store treats the APK as a completely
different app. So once you publish your app, you should never change
the application ID.
And package name is:
Although your project's package name matches the application ID by
default, you can change it. However, if you want to change your
package name, be aware that the package name (as defined by your
project directory structure) should always match the package attribute
in the AndroidManifest.xml file, as shown here:
The Android build tools use the package attribute for two things:
1- It applies this name as the namespace for your app's generated R.java
class.
Example: With the above manifest, the R class will be
com.example.myapp.R.
2- It uses it to resolve any relative class names
that are declared in the manifest file.
Example: With the above
manifest, an activity declared as is resolved to be
com.example.myapp.MainActivity.
Know more from Source
Once you upload the app on Play store you can't change the application id for that project , if you want to do then google play store consider as a different application.
In case of package name you can change it as you want.
I have uploaded my first application to google playstore
as you see in this image in manifest in package it says auc.visorimagenes.ssssss
in the left part you could see my structure code where it is as
auc.visorimagenes.
in playstore
you see it:
but What it says auc.visorimagenes
if in my manifest I had set auc.visorimagenes.sssss
I want to up a new app with same code (only changing some resources) this is would be a new app not an update.
then I must to change auc.visorimagenes.sssss ???
Contains information about a Java package. This includes implementation and specification versions. Typically this information is retrieved from the manifest.
Packages are managed by class loaders. All classes loaded by the same loader from the same package share a Package instance.
Hope this helps!
Could you try and change the android:name attribute of your application entry in the manifest as follows and see if it helps?
<application
....
android:name=".App" (or android:name=".Application.App")
/>
This will ensure that the app uses the same package name as the one declared in the manifest.
The package in android is the name of the application that makes it unique from any other android apps, therefore allow the production of multiple apps with the same product name.
I wanted to know whether I can use 'in.' in in the app id.
For example.. can i create my app id like this
in.example.myapp
As I am unable to create it using cordova CLI. But I have changed it in the config.xml
here is the error i am getting
cordova create MyApp in.example.myapp MyApp -d
CordovaError: App id contains a reserved word, or is not a valid identifier.
at C:\Users\USer\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\create.js:106:19
at Promise.apply (C:\Users\USer\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1078:26)
at Promise.promise.promiseDispatch (C:\Users\USer\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:741:41)
at C:\Users\USer\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1304:14
at flush (C:\Users\USer\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
Can I publish such app on play store?
Please reply guys..
thanks in advance
From official documentation:
A full Java-language-style package name for the application. The name
should be unique. The name may contain uppercase or lowercase letters
('A' through 'Z'), numbers, and underscores ('_'). However, individual
package name parts may only start with letters.
To avoid conflicts with other developers, you should use Internet
domain ownership as the basis for your package names (in reverse). For
example, applications published by Google start with com.google. You
should also never use the com.example namespace when publishing your
applications.
The package name serves as a unique identifier for the application.
It's also the default name for the application process (see the
element's process process attribute) and the default
task affinity of an activity (see the element's
taskAffinity attribute).
Caution: Once you publish your application, you cannot change the
package name. The package name defines your application's identity, so
if you change it, then it is considered to be a different application
and users of the previous version cannot update to the new version.
yes, you can use "in." on it... the "com." thing is like a domain ownership, that's all. Read: http://developer.android.com/guide/topics/manifest/manifest-element.html
EDIT: This is Cordova documentation
The element's id attribute provides the app's reverse-domain
identifier, and the version its full version number expressed in
major/minor/patch notation.
Is not an Android limitation neither Play Store limitation if is Cordova limitation there is nothing you could do... if not, post the error; but, again... is not an Android/Play Store limitation.
"in" is a reserved keyword in Javascript. Since Cordova is built using JS, you can't use it in your package name. As noted by Mariano above, it is not an Android/Play Store limitation.
Here's a list of all reserved keywords:
break case class catch const continue debugger default delete do else
export extends finally for function if import in instanceof let new
return super switch this throw try typeof var void while with yield
I would like to know an uid from application's own pamameter.
I know how to get an uid from PackageManager with package name, however I have noticed that an application can send a fake package name or context which is created with fake package name. How can I create an API to determine exactly an uid from any app's own parameter? Or how to check this app is system app?
Sounds like you want to get the current app id. This should do the trick. Get the result of http://developer.android.com/reference/android/os/Process.html#myUid() and give it to http://developer.android.com/reference/android/content/pm/PackageManager.html#getPackagesForUid(int)