mui 把内容复制到剪切板

时间:2022-09-14 20:43:25
function copyShareUrl(){
mui.plusReady(function(){
//复制链接到剪切板
var copy_content = "";
//判断是安卓还是ios
if(mui.os.ios){
//ios
var UIPasteboard = plus.ios.importClass("UIPasteboard");
    var generalPasteboard = UIPasteboard.generalPasteboard();
    //设置/获取文本内容:
    generalPasteboard.plusCallMethod({
        setValue:copy_content,
        forPasteboardType: "public.utf8-plain-text"
    });
    generalPasteboard.plusCallMethod({
        valueForPasteboardType: "public.utf8-plain-text"
    });
}else{
//安卓
var context = plus.android.importClass("android.content.Context");
  var main = plus.android.runtimeMainActivity();
  var clip = main.getSystemService(context.CLIPBOARD_SERVICE);
  plus.android.invoke(clip,"setText",copy_content);
}
});
}