Nikola Milovic
12/03/2019, 9:56 AMType inference failed: fun <T : Any!> getSystemService(context: Context, serviceClass: Class<T!>): T?
cannot be applied to
(String)
Type mismatch: inferred type is String but Context was expected
I just used the code provided here https://developer.android.com/guide/topics/text/copy-paste
var clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
var pasteData: String = ""
And i get this errorwasyl
12/03/2019, 9:59 AMgetSystemService
from core-ktx library and it’s a function with reified generic parameter. So you need to instead wrote getSystemService<ClipboardManager>()
Nikola Milovic
12/03/2019, 10:46 AMwasyl
12/03/2019, 11:11 AMNikola Milovic
12/03/2019, 11:26 AMoverride fun quoteClicked(quote: Quote) {
viewModel.copyText(quote)
}
in my fragment, but now I need a way to copy text in the viewmodel. Any pointers/ help/ article would be appreciated. Not sure what to do
Thanks by the way @wasylMark Murphy
12/03/2019, 12:15 PMClipboardManager
so you can supply a mock version in testing. Otherwise, you could have your viewmodel extend AndroidViewModel
and use the application
to call getSystemService()
.Nikola Milovic
12/03/2019, 12:49 PM