#IF B4A
#IF JAVA
import android.content.ClipboardManager;
import android.content.ClipData;
import android.content.Context;
import android.content.ClipDescription;
import android.graphics.Bitmap;
import android.net.Uri;
import java.io.File;
import java.io.FileOutputStream;
import android.graphics.BitmapFactory;
public Boolean SetTextToClipboard(Object objtxt, Object mObjContext) {
try {
String txt = (String) objtxt;
Context mContext = (Context) mObjContext;
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData myClip;
myClip = ClipData.newPlainText("text", txt);
myClipboard.setPrimaryClip(myClip);
return true;
} catch (Exception ex) {
return false;
}
}
public String GetTextFromClipboard(Object mObjContext) {
Context mContext = (Context) mObjContext;
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData myClip = myClipboard.getPrimaryClip();
ClipData.Item item = myClip.getItemAt(0);
String txt = item.getText().toString();
return txt;
}
public Boolean HasTextCopied(Object mObjContext) {
Context mContext = (Context) mObjContext;
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
if (!(myClipboard.hasPrimaryClip())) {
return false;
} else if (!(myClipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))) {
return false;
} else {
return true;
}
}
public Boolean HasBitmapCopied(Object mObjContext) {
Context mContext = (Context) mObjContext;
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
if (!myClipboard.hasPrimaryClip()) {
return false;
} else if (!myClipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
return false;
} else {
return true;
}
}
public Bitmap GetBitmapFromClipboard(Object mObjContext) {
try {
Context mContext = (Context) mObjContext;
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
if (!myClipboard.hasPrimaryClip()) {
return null;
}
ClipData clipData = myClipboard.getPrimaryClip();
ClipData.Item item = clipData.getItemAt(0);
// Prüfen, ob die URI vorhanden ist
Uri imageUri = item.getUri();
if (imageUri != null) {
// Bitmap aus der URI laden
return BitmapFactory.decodeStream(mContext.getContentResolver().openInputStream(imageUri));
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public Boolean SetBitmapToClipboard(Bitmap bitmap, Object mObjContext) {
try {
Context mContext = (Context) mObjContext;
File cachePath = new File(mContext.getCacheDir(), "images");
cachePath.mkdirs(); // Erstellen Sie das Verzeichnis, falls es nicht existiert
File file = new File(cachePath, "image.png");
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
// URI erstellen
Uri imageUri = Uri.fromFile(file);
// Bild in die Zwischenablage legen
ClipboardManager myClipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData myClip = ClipData.newUri(mContext.getContentResolver(), "Image", imageUri);
myClipboard.setPrimaryClip(myClip);
return true;
} catch (Exception ex) {
return false;
}
}
#End If
#End If