using clipboard inside of service in android
i have a thread class inside of service for check clipboard.
that's work well in INT_SDK < API 11 but when use this in upper API 11 get
error
my clipboard paste code is work well in under API 11 and new API.(i test
in android 4.3 and 2.3.5)
error logcat :
FATAL EXCEPTION: Thread-248
java.lang.RuntimeException: Can't create handler inside thread that has
not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:197)
at android.os.Handler.<init>(Handler.java:111)
at android.content.ClipboardManager$2.<init>(ClipboardManager.java:71)
at android.content.ClipboardManager.<init>(ClipboardManager.java:71)
at android.app.ContextImpl$9.createService(ContextImpl.java:327)
at android.app.ContextImpl$ServiceFetcher.getService(ContextImpl.java:230)
at android.app.ContextImpl.getSystemService(ContextImpl.java:1514)
at android.content.ContextWrapper.getSystemService(ContextWrapper.java:519)
at
com.jafaripur.kalamehdictionary.clipboard.ClipboardMonitor$MonitorTask.getData(ClipboardMonitor.java:100)
at
com.jafaripur.kalamehdictionary.clipboard.ClipboardMonitor$MonitorTask.doTask(ClipboardMonitor.java:73)
at
com.jafaripur.kalamehdictionary.clipboard.ClipboardMonitor$MonitorTask.run(ClipboardMonitor.java:60)
example of thread class :
class thread example extends Thread {
run(){getData()}
.
.
.
}
example of access to clipboard:
getData(){
if (API < 11){
.
.
.
}
else{
android.content.ClipboardManager clipboard =
(android.content.ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);
.
.
.
}
}
i wrote above code inside of running service .
No comments:
Post a Comment