Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android find all hardcoded strings in code using Android Studio

Tags:

android

I want to find all hard-coded strings in my code to move them into strings.xml file for future localization. Such as :

Toast.makeText(context,"Hardcoded text",LENGTH_SHORT).show();

I using Android Studio.

like image 904
Sergey Shustikov Avatar asked Jun 12 '15 09:06

Sergey Shustikov


People also ask

How to find Hardcoded string in android Studio?

To run lint inside Android Studio just go to the Analyze menu and select Inspect code… select your scope (e.g. Workspace) then click Ok. The hardcoded strings you search for will be present in two groups: Hardcoded text — reports all the hardcoded text in xml layout files. e.g.

What are Hardcoded strings?

The term hardcoded string refers to a string that doesn't depend on the input to the program but it also has connotations of being hard to change, meaning that you might have to edit the code in one or more places to change it.


2 Answers

Go to Analyze > Run Inspection By Name... (Ctrl+Alt+Shift+I)

and type:

  • Hardcoded Text to find the hardcoded strings in the .xml files;
  • Hardcoded Strings to find the hardcoded strings in the .java files.

Run it against the whole project, and you should get an inspection results panel that will show the hardcoded text instances.

like image 135
Ryan Amaral Avatar answered Oct 21 '22 19:10

Ryan Amaral


This answer hasn't getting to me any result.

Nonetheless, for future searches :

In Android Studio 1.2.2 added new Option Hardcoded strings(not a Hardcoded text) and this getting to me perfect searches result.

like image 16
Sergey Shustikov Avatar answered Oct 21 '22 21:10

Sergey Shustikov