Reputation: 36654
I'm writing an android application.
It has some packages under src
.
how can I figure out which of them is my application package?
I want to add C@DM permissions:
<permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" />
how will my YOUR_PACKAGE_NAME
change if I create a custom MyApplication extends Application
class?
Upvotes: 8
Views: 34741
Reputation: 172
If you are trying to access it programmatically and use the gradle-android-plugin to build your app, then you can use
BuildConfig.APPLICATION_ID
to retrieve the package name from any scope, incl. a static one.
If you are looking in android studio, The above answers are also correct but you can also build your project and search for BuildConfig file and there you can something similar
ublic static final String APPLICATION_ID = "com.android.yourpackagename";
Upvotes: 0
Reputation: 1015
You can find it in MainActivity.kt and ManinApplication.kt file at the starting line of the code with other imports.
Upvotes: 0
Reputation: 1948
Newer Android Studio using Gradle do not have "package name" nor is it mentioned in "AndroidManifest.xml".
Please find instead the "applicationId" inside the "build.gradle.kts" file, at module level not project level.
I.e.:
android {
defaultConfig {
applicationId = "com.example.myapp"
Reference: https://developer.android.com/build/configure-app-module
Quote:
the applicationId is automatically assigned the package name you chose during setup.
Upvotes: 5
Reputation: 21
Upvotes: 2
Reputation: 2309
Your application name is actually defined in the AndroidManifest.xml, in its first lines. Ex:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.appname"
android:versionCode="66"
android:versionName="0.57" >
note the package="com.yourcompany.appname" - this is your package definition.
Other places which contain your package name can be resources, class paths, packages and much more. But all of them should be aligned according to the manifest because that what the package manager reads.
Upvotes: 28