0

这可能是什么原因?我们只是尝试在以下服务类中查询浏览器历史记录,但是 eclipse 会生成错误The method managedQuery is undefined for the type Service_class Service_class.java

我们试图遵循日食的建议 - 但它完全打开了另一罐蠕虫。

例子:

public class Service_class extends Service {
       String Dirty1 = "www.playboy.com";
        String Dirty2 = "www.penthouse.com";
        String Dirty3 = "www.pornhub.com";
        String Dirty4 = "www.playboy.com";
        String Dirty5 = "www.playboy.com";
        String Dirty6 = "www.playboy.com";
        String Dirty7 = "www.playboy.com";
        String Dirty8 = "www.playboy.com";
        String Dirty9 = "www.playboy.com";
        String Dirty10 = "www.playboy.com";

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

        return START_STICKY;
    }

    @Override
    public void onDestroy() {

        super.onDestroy();
        Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onCreate() {
        super.onCreate();
        String[] projection = new String[] { Browser.BookmarkColumns.TITLE,
                Browser.BookmarkColumns.URL };
                Cursor cursor = managedQuery(android.provider.Browser.BOOKMARKS_URI,
                        projection, null, null, null);
                String urls = "";
                if (cursor.moveToFirst()) {
                String url1 = null;
                String url2 = null;
                do {
                String url = cursor.getString(cursor.getColumnIndex(Browser.BookmarkColumns.URL));

                if (url.toLowerCase().contains(Dirty1)) {
                } else if (url.toLowerCase().contains(Dirty2)) {
                } else if (url.toLowerCase().contains(Dirty3)) {
                } else if (url.toLowerCase().contains(Dirty4)) {
                } else if (url.toLowerCase().contains(Dirty5)) {
                } else if (url.toLowerCase().contains(Dirty6)) {
                } else if (url.toLowerCase().contains(Dirty7)) {
                } else if (url.toLowerCase().contains(Dirty8)) {
                } else if (url.toLowerCase().contains(Dirty9)) {
                } else if (url.toLowerCase().contains(Dirty10)) {
                //if (url.toLowerCase().contains(Filthy)) {
                urls = urls
                + cursor.getString(cursor.getColumnIndex(Browser.BookmarkColumns.TITLE)) + " : "
                + url + "\n";
                Intent intent = new Intent(Service_class.this, Warning.class);
                Service_class.this.startActivity(intent);
                }
                } while (cursor.moveToNext()); 
            //  tv.setText(urls);


    }

}}
4

2 回答 2

0

服务不存在 managedQuery 函数。它只存在于活动中。您仍然可以进行查询,但您必须管理光标并手动关闭它。

于 2013-04-16T02:37:00.023 回答
0

在您的 onCreate 方法中,第 3 行您正在使用托管查询方法。它在哪里定义?

于 2013-04-16T02:38:54.657 回答