这是我实现OnPrimaryCLipChangedListener的代码:
public class PrimaryClipChangedListener implements OnPrimaryClipChangedListener {
@Override
public void onPrimaryClipChanged() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
Log.d("RAJATH", "copyclip reached");
}
}
我注册听众的服务:
package com.example.tryservice;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.ClipboardManager.OnPrimaryClipChangedListener;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MyService extends Service{
public MyService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Log.d("RAJATH", "Service Reached");
ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
cb.addPrimaryClipChangedListener(new PrimaryClipChangedListener());
return 0;
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}
我有一项启动此服务的活动。此代码的目的是在后台监听剪贴板更改。哪里出错了?
答案 0 :(得分:1)
究竟什么不起作用? Android 4.3中存在一个错误,如果您监听OnPrimaryClipChangedListener回调,系统会崩溃。