Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use package name in XML

I'm using Android Studio to build my application. I would like to use gradle buildTypes. I add a suffix to the package name with applicationIdSuffix to modify the package name for a test build type.

buildTypes {       
    debug {
        runProguard false
        proguardFile 'proguard-rules.txt'
        applicationIdSuffix  '.dev'
        versionNameSuffix  '-dev'
    }
}

Is it possible to use this information in a xml file. My plan is to modify the account type:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType=<<PACKAGE NAME HERE ??>>
    android:icon="@drawable/icon"
    android:label="@string/app_name"/> 

Thanks!

like image 220
speedy1034 Avatar asked Jun 22 '14 23:06

speedy1034


People also ask

Is application ID and package name same?

Java. The applicationId exactly matches the Java-style package name you chose during project setup in android studio. However, the application ID and package name are independent of each other beyond this point.

How do I launch an app using package name?

Just use these following two lines, so you can launch any installed application whose package name is known: Intent launchIntent = getPackageManager(). getLaunchIntentForPackage("com. example.

What is a package name?

The package name of an Android app uniquely identifies your app on the device, in Google Play Store, and in supported third-party Android stores.

Does package name matter Android studio?

No it wont have any change. You follow the same steps as before but with your new package. Just upload it as a new app. That's all.


1 Answers

Here's another temporary workaround until the Android Gradle plugin gets support for placeholders in resource files.

You can dynamically create a String resource via Gradle in the defaultConfig and/or buildTypes and/or productFlavors closure:

android {
    defaultConfig {
        applicationId 'com.foo.bar'
        resValue 'string', 'package_name', applicationId
    }
}

You can then reference it in your authenticator.xml file just like you do for the label:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/package_name"
    android:icon="@drawable/icon"
    android:label="@string/app_name"/> 
like image 178
jenzz Avatar answered Oct 05 '22 22:10

jenzz