creator中的一件復(fù)制qq號(hào),文字的功能

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語(yǔ)言中的內(nèi)容:

.h

+ (void)copyToClipBoard:(NSString*)path;

.mm

+ (void)copyToClipBoard:(NSString*)path

{

? ? UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

? ? pasteboard.string=path;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容