Я работаю над приложением Android, где я использую обмен намерение для обмена текстом. Если пользователь копирует текст вместо того, чтобы обмениваться им через приложение, я хочу обнаружить, когда изменяется контент буфера обмена, используя буферизащин. вызывается, когда текст копируется из намерения общего. Эта проблема не происходит на всех устройствах. < /P>
Вот соответствующий код: < /p>
private void setClipBoardManager() {
ClipboardManager clipboardManager = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
@Override
public void onPrimaryClipChanged() {
try {
CharSequence copiedData = clipboardManager.getPrimaryClip().getItemAt(0).getText();
Log.d(TAG, "onPrimaryClipChanged: " + copiedData);
} catch (RuntimeException ex) {
Log.e(TAG, ex.getLocalizedMessage(), ex);
ex.printStackTrace();
}
}
});
}
< /code>
public void share_text(String title, String subject, String text) {
int requestCode = 111;
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sharingIntent.putExtra(Intent.EXTRA_TEXT, text);
PendingIntent pi = PendingIntent.getBroadcast(this, requestCode, new Intent(this, ShareBroadCast.class),
PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
sharingIntent = Intent.createChooser(sharingIntent, title, pi.getIntentSender());
startActivity(sharingIntent);
}
< /code>
I verified that the clipboard manager is properly initialized.
onPrimaryClipChanged works fine in other scenarios outside of the sharing intent.
The issue appears to be device-specific, but I’m not sure why.
It also this error in tag:ClipboardService
Denying clipboard access to package.name, application is not in focus neither is a system service for user 0
< /code>
I expected onPrimaryClipChanged to be triggered whenever the user copies text from the share intent on all devices.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -text-from
Bulfboardmanager.onprimaryClipchangedListener не называется после копирования текста из общего намерения на некоторых ус ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение