二维码-clipboard的使用
来源:互联网 发布:高洛峰php 编辑:程序博客网 时间:2024/06/05 20:27
说明
原生的二维码使用了clipboard的功能.
代码ClipboardInterface.java
/* * Copyright (C) 2012 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.zxing.client.android.clipboard;import android.content.ClipData;import android.content.ClipboardManager;import android.content.Context;import android.util.Log;/** * Abstraction over the {@link ClipboardManager} API that manages copying and pasting. */public final class ClipboardInterface { private static final String TAG = ClipboardInterface.class.getSimpleName(); private ClipboardInterface() { } public static CharSequence getText(Context context) { ClipboardManager clipboard = getManager(context); ClipData clip = clipboard.getPrimaryClip(); return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null; } public static void setText(CharSequence text, Context context) { if (text != null) { try { getManager(context).setPrimaryClip(ClipData.newPlainText(null, text)); } catch (NullPointerException | IllegalStateException e) { // Have seen this in the wild, bizarrely Log.w(TAG, "Clipboard bug", e); } } } public static boolean hasText(Context context) { ClipboardManager clipboard = getManager(context); ClipData clip = clipboard.getPrimaryClip(); return clip != null && clip.getItemCount() > 0; } private static ClipboardManager getManager(Context context) { return (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); }}
0 0
- 二维码-clipboard的使用
- zero clipboard 使用
- clipboard使用总结
- clipboard.js基本使用
- clipboard.js使用总结
- 在无clipboard 的vim 中, 如何使用系统剪切板
- 解决使用SecureCRT出现的Generic clipboard failure错误
- 同时使用clipboard和layer时遇到的坑
- zBAR二维码的使用
- ZBarSDK二维码的使用
- iOS二维码的使用
- iOS7二维码的使用
- Android二维码的使用
- 关于二维码的使用
- zxing二维码的使用
- Android 二维码的使用
- 二维码的使用
- 二维码的使用
- App 模块化实战经验总结
- 使用springMVC AOP实现日记记录
- Spring 中关于@Resource注解,以及其和@Autowired注解的区别
- python获取当前工作目录
- Python 基础教程(好网站)——001
- 二维码-clipboard的使用
- 大数据:Spark Shuffle(二)Executor、Driver之间Shuffle结果消息传递、追踪
- FTS数据库优化(Android)原理与应用详解(1)
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 大三学前端第二阶段--js第一部分总结
- wireshark学习笔记(二)
- Python插件cx_Oracle的安装
- MFC判断指定路径下目标文件、目标文件夹是否存在
- 7.scala:继承