美文网首页
剪切板调用

剪切板调用

作者: 神大人korose | 来源:发表于2020-01-16 11:50 被阅读0次

    ios

    +(void)iosCopy:(NSString *) text
    { //把char*转换成OC的NSString
        NSString *nsMessage= text;
        //获得ios的剪切板
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        //改变剪切板的内容
        pasteboard.string = nsMessage; return ;
        
    }
    
    +(NSString *)iosPaste{
        //获得ios的剪切板
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        return pasteboard.string;
    }
    

    Android

        static public void JavaCopy(String str){
            //final AppActivity app = new AppActivity();
            System.out.println(str);
            final  String text = str;
            activity.runOnUiThread(new Runnable(){
                @Override
                public void run() {
                    android.content.ClipboardManager cm = (android.content.ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("kk",text);
                    cm.setPrimaryClip(clip);
                }
            });
        };
    
        public static String JavaPaste(){
    //        activity.runOnUiThread(new Runnable(){
    //            @Override
    //            public void run() {
            // TODO Auto-generated method stub
            android.content.ClipboardManager clipboardManager=(android.content.ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            if(clipboardManager==null){
                Log.i("cp","clipboardManager==null");
            }
            if(clipboardManager.getText()!=null){
                tempStr=clipboardManager.getText().toString();
            }
    //            }
    //        });
            return tempStr;
        }
    

    相关文章

      网友评论

          本文标题:剪切板调用

          本文链接:https://www.haomeiwen.com/subject/kidfzctx.html