2

这是我实现 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

1 回答 1

1

究竟是什么行不通?Android 4.3 中有一个错误,如果您侦听 OnPrimaryClipChangedListener 回调,系统会崩溃。

于 2013-08-22T22:15:23.330 回答