我正在尝试查询指定URL的书签/浏览器历史记录 - 然后在查询返回匹配项时启动新意图 - 但无论查询结果如何,意图都在运行。
我在设备上完成了工厂重置,以确保没有浏览器历史记录和书签[并确保不会将任何设置恢复到设备 - 这会恢复书签和可能的浏览器历史记录]但意图开始即使它在我的历史记录中找不到匹配条件(我已多次验证历史记录和书签是100%空白)。
如何防止这些误报发生?
import com.parse.ParseObject;
import android.app.AlertDialog;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.provider.Browser;
import android.util.Log;
import android.widget.Chronometer;
import android.widget.TextView;
import android.widget.Toast;
public class Service_class extends Service {
String Dirty1 = "playboy";
String Dirty2 = "penthouse";
String Dirty3 = "pornhub";
String Dirty4 = "playboy";
String Dirty5 = "playboy";
String Dirty6 = "playboy";
String Dirty7 = "playboy";
String Dirty8 = "playboy";
String Dirty9 = "playboy";
String Dirty10 = "playboy";
@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();
String[] projection = new String[] { Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL };
Cursor cursor = getContentResolver().query(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) || url.toLowerCase().contains(Dirty2))
{
Intent intent2 = new Intent(Service_class.this, Warning.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent2);
break;
} } while (cursor.moveToNext());
}
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
}
@Override
public void onCreate() {
super.onCreate();
}}