在列表视图显示present SQLite数据库 [英] Display present SQLite databases on listview

查看:168
本文介绍了在列表视图显示present SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Andr​​oid手机上的所有数据库present编程和显示这些都在列表视图,但我无法得到任何的解决方案。

我从谷歌这个code,但它并没有显示所有的列表视图present数据库。

 私人的ArrayList<字符串> getDBFILES()
{
    ArrayList的<字符串> ARR =新的ArrayList<字符串>();
    字符串DB_PATH,rand_name,str_tmp;

    //ad.1-2。对于数据库随机文件名

    。rand_name =新的随机()nextInt((4000000-2000 + 1)+2000)+分贝。
    DB_PATH = openOrCreateDatabase(rand_name,MODE_PRIVATE,空).getPath();

    //ad.3。
    deleteDatabase(rand_name);

    //ad.4。
    DB_PATH = db_path.replace(/+ rand_name,);

    //ad.5。
    文件[]文件=新的文件(DB_PATH).listFiles();
    如果(文件== NULL){返回NULL; }

    //所以现在我们得到的文件名一一
    的for(int i = 0; I< files.length;我++)
    {
       str_tmp =文件[I] .getName();
       如果(str_tmp.endsWith(! - 日记))
          {arr.add(str_tmp); }
    }
    返回ARR;
}
 

解决方案

好了,你不能!你只可以访问您的应用程序的数据库!如果你有一个以上的应用程序,您仍然可以使用一些三轮车从其他应用程序访问数据库! (在同一个沙箱中运行所有的)
虽然你没有权限访问其他应用程序数据库某些应用程序(包括Android系统本身)提供的内容提供商。你不能直接操作数据库,但您可以使用内容提供商为每个最终运行在数据库上查询应用程序。

I want to get all databases present on my Android phone programatically and display those all on listview, but I could not get any solution.

I got this code from Google, but it doesn't show all present databases on listview.

private ArrayList<String> getDBFILES() 
{
    ArrayList<String> arr = new ArrayList<String>();
    String db_path, rand_name, str_tmp;

    //ad.1-2. random file name for db

    rand_name = new Random().nextInt((4000000-2000+1)+2000)+".db";
    db_path = openOrCreateDatabase(rand_name, MODE_PRIVATE, null).getPath();

    //ad.3.
    deleteDatabase(rand_name);

    //ad.4.
    db_path = db_path.replace("/" + rand_name, "");

    //ad.5.
    File [] files = new File(db_path).listFiles();
    if (files == null) { return null; }

    //so now we get the filenames one by one
    for (int i = 0; i < files.length; i++)
    { 
       str_tmp = files[i].getName();
       if (!str_tmp.endsWith("-journal"))
          {  arr.add(str_tmp); }
    }
    return arr;
}

解决方案

Well you can't! you only can access to your app databases! If you have more than one application you still can access databases from your other apps using some trikes! (running all of them under the same sandbox)
although you have not permission to access other apps databases some applications (including android system itself) provided content providers. you can not directly manipulate the database but you can use the content provider for each app that eventually runs query on the database.

这篇关于在列表视图显示present SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆