Android实现一键复制粘贴,兼容低版本系统(api 11以下)
来源:互联网 发布:淘宝直播刷人软件下载 编辑:程序博客网 时间:2024/05/20 21:59
/**
* 实现文本复制功能
* @param content
* @return true--复制成功
*/
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static boolean copy(String content, Context context) {
// 得到剪贴板管理器
try {
String n1 = content.trim();
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(n1);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip_data = android.content.ClipData.newPlainText(
"TSMS", n1);
clipboard.setPrimaryClip(clip_data);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 实现粘贴功能
* @param context
* @return null--粘贴失败
*/
@SuppressLint("NewApi")
public static String paste(Context context) {
// 得到剪贴板管理器
try {
String n1 = null;
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
n1 = clipboard.getText().toString();
}else{
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
n1 = (String) clipboard.getPrimaryClip().getItemAt(0) .getText();
}
return n1;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
- Android实现一键复制粘贴,兼容低版本系统(api 11以下)
- android api实现高斯模糊,且兼容低版本
- android api实现高斯模糊,且兼容低版本
- android api实现高斯模糊,且兼容低版本
- android 兼容包(可兼容低版本系统)
- android 兼容包(可兼容低版本系统)
- 4.Android与JS的交互(兼容API 17以下版本)
- android 复制、粘贴字符串 (判断API 11 )
- android兼容低版本Fragment
- Android Fragment兼容低版本
- Android实现复制粘贴
- android低版本(4.4以下)sip无法接受
- Material Designer的低版本兼容实现(一)—— 简介 & 目录
- Android 实现高斯模糊效果及低版本兼容
- Android 实现高斯模糊效果及低版本兼容
- Android 实现高斯模糊效果及低版本兼容
- Android 实现高斯模糊效果及低版本兼容
- Android 自定义一个好看的dialog,并实现水波纹特效(兼容低版本)
- myEclipse安装svn插件
- svn 合并的问题
- android webview无法加载网址
- 【bzoj2820】YY的GCD 莫比乌斯反演
- Safe string concatenation
- Android实现一键复制粘贴,兼容低版本系统(api 11以下)
- Win10 Ubuntu14.04 双系统 开机提示 error:no such partition grub rescue
- html5缓存(二)localStorage
- shiro安全框架
- switch语句能否作用在byte上,能否作用在long上,能否作用在String上?
- android相关下载
- java中for方法执行的正确顺序
- 复习iOS沙盒目录结构解析
- java中 .currentTimeMillis的用法和含义