I've been trying to create an auto-paste feature in my downloader app. My app has an editText and when a user opens the app the app will automatically check for a copied link that matches certain parameters. The main page has two fragments, one of them has this feature.
Problem is when I use bottomNavigationView with NavController using Navigation UI, that feature doesn't work. It shows null as a result when checking for clipboard data.
But when I use an adapter extending FragmentStateAdapter instead of navigation UI then it works properly.
if (!this.clipboardManager.hasPrimaryClip()) {
Log.d("ContentValues", "PasteText");
} else if (this.clipboardManager.getPrimaryClipDescription().hasMimeType("text/plain")) {
ClipData.Item itemAt = this.clipboardManager.getPrimaryClip().getItemAt(0);
if (itemAt.getText().toString().contains(TikTok)) {
inputLink.setText(itemAt.getText().toString());
resetButton.setVisibility(View.VISIBLE);
pasteButton.setVisibility(View.GONE);
if (Util.getAuto(requireContext())) {
String string = inputLink.getText().toString();
getDownloadLink(string);
Util.showProgress(requireContext());
}
}
} else if (this.clipboardManager.getPrimaryClip().getItemAt(0).getText().toString().contains(TikTok)) {
inputLink.setText(this.clipboardManager.getPrimaryClip().getItemAt(0).getText().toString());
resetButton.setVisibility(View.VISIBLE);
pasteButton.setVisibility(View.GONE);
if (Util.getAuto(requireContext())) {
String string = inputLink.getText().toString();
getDownloadLink(string);
Util.showProgress(requireContext());
}
}
I don't know what is the issue here. It works in fragment when I use Adapter but not with Navigation UI. Any explanation is appreciated. Thanks.