js中的内容:
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("已经复制到剪贴板",node);
}
else
{
jsb.reflection.callStaticMethod("WXApiManager","copyToClipBoard:",str);
App.popUpString("已经复制到剪贴板",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("已经复制到剪贴板",node);
document.body.removeChild(textArea);
}catch (err) {
App.popUpString("复制到剪贴板失败",node);
}
}
else if(App.isWechat)
{
//微信小程序
wx.setClipboardData({
data: str,
success(res) {
wx.getClipboardData({
success(res) {
App.popUpString("已经复制到剪贴板",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语言中的内容:
.h
+ (void)copyToClipBoard:(NSString*)path;
.mm
+ (void)copyToClipBoard:(NSString*)path
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string=path;
}
网友评论