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;
}
网友评论