askIT

Stetho database browser (Android SQLite)

To browse databases in Android you need to enter a code in your main Java class.

Please download and install Chrome:

chrome.png Chrome web browser


01 build.gradle

You need to find the file build.gradle and update it.

mainactivity_build_gradle.jpg

Inside dependencies add
compile 'com.facebook.stetho:stetho:1.2.0'
and
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'


dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
                exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:26.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        testCompile 'junit:junit:4.12'

        compile 'com.facebook.stetho:stetho:1.2.0'
        compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
}

02 MainActivity

Find MainActivity class and update it.

mainactivity_build_gradle.jpg

Add the code for Stetho inside the onCreate method.

/* Stetho */
Stetho.initializeWithDefaults(this);

new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();

package com.nettport.stramdiet.stramdiet;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp3.StethoInterceptor;

import okhttp3.OkHttpClient;

public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);

                /* Stetho */
                Stetho.initializeWithDefaults(this);

                new OkHttpClient.Builder()
                                .addNetworkInterceptor(new StethoInterceptor())
                                .build();

        }
}

03 Run code

Run your code in a emulator.


04 Open Chrome

Go to Chrome and open the URL chrome://inspect/

chrome_inspect.jpg

Click on Inspect.

Now you can browse your database.

web_sql.jpg

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

1_180303121314.jpg.png

Administrator

18 May 2018

With the new Android you would like to write this:

implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'