The pit of Android's android meta data value acquisition

Today, when I read a long string of numbers in Android's meta data, I found a pit, using the ordinary method

applicationInfo.metaData.get(key)+""

The number string that was read out was wrong. Later, it turned out to be a very typical problem. Please refer to the post: 

https://my.oschina.net/u/990728/blog/673959

method one:

<meta-data
    android:name="appkey"
    android:value="\ 1234567890" />

 

Method Two:

Use the resources property to get the resource id through getInt, and then get the value corresponding to the resource id. This method is highly scalable and can get all resources instead of just strings, as in

<meta-data
    android:name="appkey"
    android:resource="@string/AppKey" />

Define the value of AppKey in strings.xml as

<string name="AppKey">1234567890</string>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326452992&siteId=291194637