Dies ist der Code, der die Daten in die Zwischenablage kopiert:
Code: Select all
...
String data = convertToJSON(object); // the data that I want to copy-paste (an object representad as text using JSON syntax)
String mimeType = "application/vnd.myapp.items+json";
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(new ClipData("items", new String[] { mimeType }, new ClipData.Item(data)));
...
Code: Select all
...
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
ClipData.Item clipItem = clip.getItemAt(0);
ClipDescription clipDesc = clip.getDescription();
String[] availableMimeTypes = clipDesc.filterMimeTypes("*/*");
if (availableMimeTypes != null) {
Collection availableMimeTypesList = Arrays.asList(availableMimeTypes);
Log.v(TAG, "got " + clipDesc.getMimeTypeCount() + " MIME-types: " + availableMimeTypesList);
if (availableMimeTypesList.contains("application/vnd.myapp.items+json")) {
// *** the above check always fails and the data is never retrieved :-( ***
String clipboardContent = clipItem.coerceToText(this).toString();
Object x = convertFromJSON(clipboardContent);
...
}
...
}
}
...
kopiert habe
Code: Select all
"application/vnd.myapp.items+json"
Ich bin mir zu 100 % sicher, dass genau dieser Code bereits in früheren Versionen (also Android-Versionen und AndroidStudio-Versionen) funktioniert hat, aber aus irgendeinem seltsamen Grund funktioniert er nicht mehr und ich bin verblüfft, warum das so ist. Irgendjemand eine Idee oder Erklärung?
Die aktuelle Ziel-API meiner Anwendung ist „33“.
Mobile version