-1

The code

startActivity(Intent.createChooser(shareIntent,"text..text"));

works fine, but the code

startActivity(Intent.createChooser(shareIntent,R.string.listen));

Gives me the error "Wrong 2nd argument type. Found 'int', required 'java.lang.CharSequence'."

But my R.string.listen isn't a int, it is a string.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
SilverBlue
  • 239
  • 2
  • 13

3 Answers3

2
startActivity(Intent.createChooser(shareIntent,getString(R.string.listen)));
Emran
  • 1,031
  • 11
  • 25
2

R.string.listen is an int not a String. All elements under R are ints (ids, strings, layouts, raws...). They are identifiers for the resources inside the APK, not the real resource itself.

startActivity(Intent.createChooser(shareIntent, getString(R.string.listen)));
m0skit0
  • 25,268
  • 11
  • 79
  • 127
2

Everything in the R class is a reference, hence it's just defined as an int.

Thus R.string.* is a reference to an int in R.java that points to your actual String.

Therefore in your case R.string.listen gives you the reference index of that string resource, you will need to call getString() method to get the value of that string.

You can use either getString(int) or getText(int) to retrieve a string.

getText(int) retains any rich text styling applied to the string

See the Documentation and this similar SO Question for more information

warl0ck
  • 3,356
  • 4
  • 27
  • 57