I'm using this code to put items on the clipboard and it works fine, apps can paste what I put there just fine, but SwiftKey never shows on their history what I put on the clipboard. What am I doing wrong?
ClipboardManager clipboard = (ClipboardManager) context.
getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newRawUri("URL", Uri.parse(url));
if (clip != null) {
clipboard.setPrimaryClip(clip);
} else {
Log.w(TAG, "Failed to copy to clipboard");
}
} else {
Log.w(TAG, "Unexpected error because clipboard is null");
}
Edit: Made a sample project just to test it and still failed:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val clipboard: ClipboardManager =
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
if (clipboard != null) {
val clip = ClipData.newRawUri("URL", Uri.parse("http://google.com"))
if (clip != null) {
clipboard.setPrimaryClip(clip)
} else {
Log.w("MainActivity", "Failed to copy to clipboard")
}
} else {
Log.w("MainActivity", "Unexpected error because clipboard is null")
}
}
}
I can paste just fine but here is what SwiftKey shows: