Rajath S
Rajath S

Reputation: 169

OnPrimaryClipChangedListener not working

This is my code for implementation of 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");                    
        }

}

My service which register the listener:

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");
}
}

I have an activity that starts this service. The purpose of this code is to listen to clipboard changes in the background. Where is the mistake?

Upvotes: 2

Views: 1287

Answers (1)

Todor Kolev
Todor Kolev

Reputation: 1482

What exactly doesn't work? There is a bug in Android 4.3 where the system crashes if you listen for OnPrimaryClipChangedListener callbacks.

Upvotes: 1

Related Questions