适用于所有 API 级别的 Android 剪贴板代码 [英] Android clipboard code that works on all API levels

查看:24
本文介绍了适用于所有 API 级别的 Android 剪贴板代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用于 API 级别的剪贴板代码

在 API 级别 >= 11 的设备上发生 11 次崩溃.

The clipboard code that works for API levels < 11 crashes on devices with API levels >= 11.

适用于 API 级别 >= 11 的剪贴板代码在 API 级别小于等于 11 的设备上崩溃11.

The clipboard code that work for API level >= 11 crashes on devices with API levels < 11.

我无法为两个版本编译代码,因为它们的导入要求相互冲突.

I can not compile code for both versions because they have conflicting import requirements.

一个需要:导入 android.text.ClipboardManager;

One needs: import android.text.ClipboardManager;

而其他需要:导入 android.content.ClipboardManager;

while the other needs: import android.content.ClipboardManager;

当然有一种方法可以编写一些代码,可以在 API 级别 11 的两端都工作.我就是想不通.

Surely there is a way write some code that will work on both sides of API level 11. I just can't figure it out.

***已编辑(因为我无法回答自己的问题)*******

***Edited (Since I can't answer my own question) *******

我发现了问题.异常消息说,无法在没有调用 Looper.prepare() 的线程中创建处理程序."

I found the problem. The exception message says, "Can't create handler inside a thread that has not called Looper.prepare()."

显然,由于我是从异步任务中执行此代码,因此我必须跳过更多的障碍.

Apparently I have to jump through some more hoops since I am executing this code from an Async task.

推荐答案

适用于 API 级别的剪贴板代码

在 API 级别 >= 11 的设备上发生 11 次崩溃.

The clipboard code that works for API levels < 11 crashes on devices with API levels >= 11.

这个示例项目在之前的 API 级别上运行良好11 之后.我刚刚在 Android 2.3 (Nexus One) 和 Android 4.0 (Nexus S) 上重新测试了它.

This sample project works quite nicely on API levels before and after 11. I just retested it on Android 2.3 (Nexus One) and Android 4.0 (Nexus S).

适用于 API 级别 >= 11 的剪贴板代码在 API 级别小于等于 11 的设备上崩溃11.

The clipboard code that work for API level >= 11 crashes on devices with API levels < 11.

这并不奇怪.如果您指的是旧版 Android 中不存在的类或方法,您将收到 VerifyError 或类似的崩溃.

That is not surprising. If you are referring to classes or methods that do not exist in older versions of Android, you will get a VerifyError or similar crashes.

我无法为两个版本编译代码,因为它们的导入要求相互冲突.

I can not compile code for both versions because they have conflicting import requirements.

不是真的.

一个需要:import android.text.ClipboardManager;

One needs: import android.text.ClipboardManager;

这适用于所有 API 级别.

That works on all API levels.

而其他需要:import android.content.ClipboardManager;

while the other needs: import android.content.ClipboardManager;

已添加到 API 级别 11.如果您的应用仅在 API 级别 11 或更高级别上运行,请使用此类(方法签名都相同的 IIRC).

That was added to API Level 11. If your app will only run on API Level 11 or higher, use this class (method signatures are all the same IIRC).

这篇关于适用于所有 API 级别的 Android 剪贴板代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆