-1

我使用下面的代码在数据库中插入用户安装的应用程序包名称并成功插入在日志中显示我现在我想比较系统安装应用程序与此数据库值并仅显示数据酶中的值所以我如何比较?如果 (((p.packageName).equals("db.list???"))

    DatabaseHandler db;

                public boolean shouldOverrideUrlLoading(WebView view, String url) {

        String Standard = "https://play.google.com/store/apps/details?id=";
         String id= url.substring(Standard .length(), url.indexOf("&"));
         db.addContact(new Contact(id));


  public class FunActivity extends Activity implements OnItemClickListener {

     DatabaseHandler db;


                          private List<App> loadInstalledApps(boolean includeSysApps) {
  List<App> apps = new ArrayList<App>();

  // the package manager contains the information about all installed apps
  PackageManager packageManager = getPackageManager();

  List<PackageInfo> packs = packageManager.getInstalledPackages(0);    






     for(int i=0; i < packs.size(); i++) {
     PackageInfo p = packs.get(i);
     if ( ((p.packageName).equals("db.list???"))  //what i write here
     App app = new App();
     app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
     app.setPackageName(p.packageName);
     app.setVersionName(p.versionName);
     app.setVersionCode(p.versionCode);
     CharSequence description = p.applicationInfo.loadDescription(packageManager);
     app.setDescription(description != null ? description.toString() : "");
     apps.add(app);
4

1 回答 1

0

从数据库中获取列表

在您的数据库处理程序中添加此方法

public ArrayList<String> getAllApps() {

    String selectQuery = "SELECT  * FROM table";
     ArrayList<String> apps = new ArrayList<String>();
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            apps.add(cursor.getString("your column name"));
        } while (cursor.moveToNext());
    }

    // return list
    return apps;
}

首先从数据库中获取列表并添加到Arraylist
然后将您的应用名称与它们进行比较

arraylist = dbHelper.getAllApps();

在你的if ( ((p.packageName).equals("db.list???"))
替换

 if (arraylist.contains(p.packageName))
    {
       add();
    }
    else
    {
     donothing();
    }
于 2013-06-24T06:41:16.533 回答