Android复制功能

xiaoxiao2021-02-27  389

int sdkInt = Build.VERSION.SDK_INT; if (sdkInt > Build.VERSION_CODES.HONEYCOMB) {// api11 ClipboardManager copy = (ClipboardManager) MainActivity.this .getSystemService(Context.CLIPBOARD_SERVICE); copy.setText(getDeviceInfo(this)); Toast.makeText(MainActivity.this, "成功复制到粘贴板", Toast.LENGTH_SHORT).show(); } else if (sdkInt <= Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager copyq = (android.text.ClipboardManager) MainActivity.this .getSystemService(Context.CLIPBOARD_SERVICE); copyq.setText(getDeviceInfo(this)); Toast.makeText(MainActivity.this, "成功复制到粘贴板", Toast.LENGTH_SHORT).show(); }

api 11之后用的是android.content.ClipboardManager;而在api11之前用的是android.text.ClipboardManager

项目地址 https://github.com/lknlll/DemoCollection

转载请注明原文地址: https://www.6miu.com/read-4593.html

最新回复(0)