当前位置:   article > 正文

Android sutdio使用命令行adb shell时无法进入root,报错su:inaccessible or not found_su: inaccessible or not found

su: inaccessible or not found

问题描述

学习《第一行代码 Android (第2版)》第六章的数据库部分时遇到下列问题,特此进行记录。

Android sutdio使用命令行adb shell时无法进入root,报错su:inaccessible or not found。

无法进入root,就不能进入/data/data/*,所以需要解决这个问题。

使用命令行查看内部数据库时,出现此情况。

解决方法:

百度查了很多的解决方法,都不是很好用,也没有写到问题的关键。

解决方法其实非常简单,只需要使用Google APIs版本的模拟器,不要使用Google Play版本的模拟器即可。

使用下方红色框内的均可

我用的数据库创建与添加数据代码:

xml代码

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical"
  5. xmlns:android="http://schemas.android.com/apk/res/android">
  6. <Button
  7. android:id="@+id/button_db"
  8. android:layout_gravity="center"
  9. android:layout_width="140sp"
  10. android:layout_height="wrap_content"
  11. android:text="创建数据库"
  12. android:textSize="18sp"/>
  13. <Button
  14. android:id="@+id/button_add"
  15. android:layout_width="140sp"
  16. android:layout_height="wrap_content"
  17. android:layout_gravity="center"
  18. android:text="添加数据"
  19. android:textSize="18sp"/>
  20. </LinearLayout>

MainActivity.java代码

  1. package com.example.databasetest;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import android.content.ContentValues;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. public class MainActivity extends AppCompatActivity {
  9. private MyDatabaseHelper dbHelper;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. dbHelper = new MyDatabaseHelper(this,"BookStore.db", null, 2);
  15. Button button_db = (Button) findViewById(R.id.button_db);
  16. Button button_add = (Button) findViewById(R.id.button_add);
  17. button_db.setOnClickListener(new View.OnClickListener() {
  18. @Override
  19. public void onClick(View view) {
  20. dbHelper.getReadableDatabase();
  21. }
  22. });
  23. button_add.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View view) {
  26. SQLiteDatabase db = dbHelper.getWritableDatabase();
  27. ContentValues values = new ContentValues();
  28. values.put("name", "Java");
  29. values.put("author", "小林");
  30. values.put("pages", 450);
  31. values.put("price", 30.20);
  32. db.insert("Book", null, values);
  33. values.clear();
  34. values.put("name", "C++");
  35. values.put("author", "小李");
  36. values.put("pages", 430);
  37. values.put("price", 31.20);
  38. db.insert("Book", null, values);
  39. values.clear();
  40. }
  41. });
  42. }
  43. }

 MyDatabaseHelper.java文件

  1. package com.example.databasetest;
  2. import android.content.Context;
  3. import android.database.sqlite.SQLiteDatabase;
  4. import android.database.sqlite.SQLiteOpenHelper;
  5. import android.widget.Toast;
  6. public class MyDatabaseHelper extends SQLiteOpenHelper {
  7. public static final String CREATE_BOOK = "create table book("
  8. + "id integer primary key autoincrement, "
  9. + "author text, "
  10. + "price real, "
  11. + "pages integer, "
  12. + "name text)";
  13. public static final String CREATE_CATEGORY = "create table Category("
  14. + "id integer primary key autoincrement, "
  15. + "category_name text, "
  16. + "category_code integer)";
  17. private Context mContext;
  18. public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
  19. super(context, name, factory, version);
  20. mContext = context;
  21. }
  22. @Override
  23. public void onCreate(SQLiteDatabase db) {
  24. db.execSQL(CREATE_BOOK);
  25. db.execSQL(CREATE_CATEGORY);
  26. Toast.makeText(mContext, "创建成功",Toast.LENGTH_SHORT).show();
  27. }
  28. @Override
  29. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  30. db.execSQL("drop table if exists Book");
  31. db.execSQL("drop table if exists Category");
  32. onCreate(db);
  33. }
  34. }
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号