js中的內(nèi)容:
copyToClipBoard:function (str,node) {
if (cc.sys.isNative) {
if (cc.sys.OS_ANDROID == cc.sys.os) {
jsb.reflection.callStaticMethod("org/kele/djsudoku/wxapi/WXEntryActivity","JavaCopy","(Ljava/lang/String;)V", str);
App.popUpString("已經(jīng)復(fù)制到剪貼板",node);
}
else
? ? ? ? {
jsb.reflection.callStaticMethod("WXApiManager","copyToClipBoard:",str);
App.popUpString("已經(jīng)復(fù)制到剪貼板",node);
}
}
else if (cc.sys.isBrowser)
{
//瀏覽器
var textArea =null;
textArea =document.getElementById("clipBoard");
if (textArea ===null) {
textArea =document.createElement("textarea");
textArea.id ="clipBoard";
textArea.textContent = str;
document.body.appendChild(textArea);
}
textArea.select();
try {
const msg =document.execCommand('copy') ?'successful' :'unsuccessful';
App.popUpString("已經(jīng)復(fù)制到剪貼板",node);
document.body.removeChild(textArea);
}catch (err) {
App.popUpString("復(fù)制到剪貼板失敗",node);
}
}
else if(App.isWechat)
{
//微信小程序
wx.setClipboardData({
data: str,
success(res) {
wx.getClipboardData({
success(res) {
App.popUpString("已經(jīng)復(fù)制到剪貼板",node);
//console.log(res.data) // data
? ? ? ? ? ? ? ? ? ? }
})
}
})
return;
}
},
android studio中的代碼:
public static void JavaCopy(final String str){
AppActivity.instance.runOnUiThread(new Runnable(){
@Override
? ? ? ? public void run() {
ClipboardManager cm = (ClipboardManager)AppActivity.instance.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("kk",str);
cm.setPrimaryClip(clip);
}
});
}
oc語言中的內(nèi)容:
.h
+ (void)copyToClipBoard:(NSString*)path;
.mm
+ (void)copyToClipBoard:(NSString*)path
{
? ? UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
? ? pasteboard.string=path;
}