I have android app and this string in resources:
Select up to %1$d people!
Thi
Make a function and put your code inside it and add this @SuppressLint("StringFormatInvalid")
just before the function. Hope it helps.
I had the same issue, but it has a different origin. My app has some languages and in one translation there was no "%" but a "$" sign instead. It still worked, except in this specific language and I received this hint at the respective line were I used the string.
You need String formatter. Please change below code from
getResources().getString(R.string.create_group_select_people, countMax);
to
String temp = String.format(getResources().getString(R.string.create_group_select_people), countMax);
For more detail information refer
For the sake of others who might find this thread, one possible cause of this warning is that you have multiple languages defined in string resource files and you did not specify format arguments in one or more of them.
For example, if you have a strings.xml in your values folder, and another strings.xml in your values-es folder, but you only added format arguments to the strings.xml in your values folder, then the warning will be triggered because of the lack of format arguments in the string resource of strings.xml in your values-es folder.
This error will be shown if you have the same string in multiple string files (translations), but one of them doesn't have proper format like missing "%s" or "%1$s", which will be used to place paramters passed (ex: "countMax") in below line.
getResources().getString(R.string.create_group_select_people, countMax)
So, please check that before you are going to try any other answers mentioned above.
Set parameter formatted to true in resources:
<string name="some_text" formatted="true">
Use for String.format method. Parameter one: %s1
</string>
and use this way:
String.format(context.getString(R.string.some_text,"value 1"))
or this way:
context.getString(R.string.some_text,"value 1"))
Note:formatted flag should be set to true only for strings with placeholders