[英]Error: incomplete SQL: ls
I am trying to access the database of another application and print it's contents to the console (USING ROOT), but for some reason I am getting this response: 我试图访问另一个应用程序的数据库并将其内容打印到控制台(使用ROOT),但是由于某种原因,我得到了以下响应:
E/[Error]: Error: incomplete SQL: ls
E/[Error]: exit
I don't really understand why this is happening. 我真的不明白为什么会这样。 I tried to put my syntax in escaped quotations, I tried other sqlite commands, but it doesn't seem to work properly.
我试图将语法放在转义的引号中,我尝试了其他sqlite命令,但是它似乎无法正常工作。
I can access the database and print it contents using ADB through my PC with the same path, and if I press the button in my application it asks me for root access, so those 2 are not the issues. 我可以通过PC以相同的路径通过PC使用ADB访问数据库并打印其内容,如果按应用程序中的按钮,它会要求我进行root访问,所以这2不是问题。
My dumbed down code: 我愚蠢的代码:
onCreate
onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCon = (Button)findViewById(R.id.button1);
btnCon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RunWithRoot("su shell -c sqlite3 \"data/data/app.package/databases/Database.db\" \"select * from messages;\"");
}
});
}
RunWithRoot
用根运行
private void RunWithRoot(String textView) {
try {
String line;
Process process = Runtime.getRuntime().exec(textView);
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
stdin.write(("ls\n").getBytes());
stdin.write("exit\n".getBytes());
stdin.flush();
stdin.close();
BufferedReader br =
new BufferedReader(new InputStreamReader(stdout));
while ((line = br.readLine()) != null) {
Log.d("[Output]", line);
}
br.close();
br =
new BufferedReader(new InputStreamReader(stderr));
while ((line = br.readLine()) != null) {
Log.e("[Error]", line);
}
br.close();
process.waitFor();
process.destroy();
} catch (Exception ex) {
}
}
Does someone know what I'm doing wrong? 有人知道我在做什么错吗? I am very new to Android development, and even newer to root.
我对Android开发非常陌生,甚至对root来说也比较新。 If someone could throw me in the right direction with this, that would be MUCH appreciated.
如果有人可以以此向我正确的方向前进,那将非常感激。
PS: This app will be for personal use only, so I don't need checks to see if people have root, or if the path exists, etc.. I already heard a few developer's minds worrying heh PS:此应用程序仅供个人使用,因此我不需要检查别人是否有root或路径是否存在等。我已经听过一些开发人员的想法,担心吗?
I fixed it using the following code. 我使用以下代码修复了它。
private void RunWithRoot(){
String line;
Process process = Runtime.getRuntime().exec("su shell");
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
stdin.write("su -c 'sqlite3 \"/data/data/app.pkge/databases/Database.db\" \"select * from messages;\"'\n".getBytes());
stdin.flush();
stdin.close();
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while ((line = br.readLine()) != null) {
Log.d("[Output]", line);
}
br.close();
br = new BufferedReader(new InputStreamReader(stderr));
while ((line = br.readLine()) != null) {
Log.e("[Error]", line);
}
br.close();
process.waitFor();
process.destroy();
}
And now it works correctly! 现在,它可以正常工作了! Mostly thanks to @ScaryWombat!
多亏了@ScaryWombat!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.