Android clipboard code that works on all API levels

后端 未结 4 959
[愿得一人]
[愿得一人] 2020-12-09 07:05

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

The clipboard code that work for API level >= 11 crashes on devices wi

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 07:37

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

    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).

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

    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.

    Not really.

    One needs: import android.text.ClipboardManager;

    That works on all API levels.

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

    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).

提交回复
热议问题