gpt4 book ai didi

android - 如何显示来自数据库的html页面

转载 作者:行者123 更新时间:2023-11-30 03:41:14 25 4
gpt4 key购买 nike

I try to store the htmlpage in db as string.then i need display that page in webview. here i paste my code pls help me....... How do you store an html page in a sqlite database in android? I tried to convert the html page into bytes array to store in database. Please help me how to store insert that into db and then open that load in webview...

public class AndroidOpenDbHelper extends SQLiteOpenHelper  {
public static final String DB_NAME = "html_db";
public static final int DB_VERSION = 1;
public static final String TABLE_NAME = "html_table";
public static final String COLUMN_NAME_ID = "html_id_column";
public static final String COLUMN_NAME_PAGE = "page_column";


public AndroidOpenDbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
//"create table if not exists TABLE_NAME ( BaseColumns._ID integer primary key autoincrement, FIRST_COLUMN_NAME text not null, SECOND_COLUMN_NAME integer not null);"
String sqlQueryToCreateTable = "create table if not exists " + TABLE_NAME + " ( " + BaseColumns._ID + " integer primary key autoincrement, "
+ COLUMN_NAME_PAGE + " HTML STRING, "
;

// Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
db.execSQL(sqlQueryToCreateTable);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
if(oldVersion == 1 && newVersion == 2){
// Upgrade the database
}
}

}

and this my code to display page.

 public class MainActivity extends Activity {
WebView browser;
private static String inp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

browser=(WebView)findViewById(R.id.w1);




}


private void loadTime(SQLiteDatabase db) {
// TODO Auto-generated method stub

browser.getSettings().setJavaScriptEnabled(true);

browser.loadDataWithBaseURL("x-data://base",inp,"text/html", "UTF-8",null);

// browser.loadUrl(inp);

}
public static String main(String args[]) throws FileNotFoundException {
FileInputStream fis = new FileInputStream("D:/mo.html");
inp = new Scanner(fis,"UTF-8").useDelimiter("\\A").next();
return inp;
}
public void insertUndergraduate(){
AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(this);
SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(AndroidOpenDbHelper.COLUMN_NAME_PAGE,inp);

}

pls help me.....

最佳答案

你试过这个例子吗:

http://mobile.tutsplus.com/tutorials/android/android-sdk-embed-a-webview-with-the-webkit-engine/

这看起来不错:

WebView engine = (WebView) findViewById(R.id.web_engine); 

String data = "<html>" +
"<body><h1>Yay, Mobiletuts+!</h1></body>" +
"</html>";

engine.loadData(data, "text/html", "UTF-8");

现在,如果可行,我只需从数据库中的普通文本字段中选择 html 到字符串中。

请让我知道这是否可行并且是答案。

关于android - 如何显示来自数据库的html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15704881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com