【发布时间】:2013-07-07 09:21:13
【问题描述】:
这是我实现 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");
}
}
我有一个启动此服务的活动。这段代码的目的是在后台监听剪贴板的变化。错误在哪里?
【问题讨论】:
-
您对此有解决方案吗?我在我的 4.3 设备上遇到了同样的问题。没有崩溃,但也没有任何日志。就像它根本没有注册一样。但同样的代码似乎可以在其他设备上运行。
标签: java android clipboard copy-paste clipboardmanager