Categories: ANDROID APP

The right way to fetch information from SQLite database and put that in a PDF File in your Android App? – supply code



This video exhibits the steps to create a SQLite database from scratch. Then it exhibits how one can write (Insert or replace) the information within the database. Additional, it exhibits the code to question the database and fetch the required information from the database. Lastly, it exhibits how you can use the fetched information to show it on a textual content view within the App’s structure and likewise to create a PDF file to write down that textual content within the PDF.

We hope you want this video. For any question, strategies or appreciations we might be glad to listen to from you at: programmerworld1990@gmail.com or go to us at: https://programmerworld.co

Supply Code at:

https://programmerworld.co/android/how-to-fetch-data-from-sqlite-database-and-put-that-in-a-pdf-file-in-your-android-app-source-code/

bundle com.instance.mysqlitedbtopdffile;

import android.content material.ContentValues;
import android.content material.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.os.Bundle;
import android.os.Atmosphere;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;

public class MainActivity extends AppCompatActivity {

personal mySQLiteDBHandler sqlLiteDBHandler;
personal EditText editTextSerialNumberInsert;
personal EditText editTextSerialNumberFetch;
personal EditText editTextInsert;
personal TextView textViewDisplay;

personal SQLiteDatabase sqLiteDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
tremendous.onCreate(savedInstanceState);
setContentView(R.structure.activity_main);
ActivityCompat.requestPermissions(this,new String[]{READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);

attempt {
sqlLiteDBHandler = new mySQLiteDBHandler(this,”PDFDatabase”, null,1);
sqLiteDatabase = sqlLiteDBHandler.getWritableDatabase();
sqLiteDatabase.execSQL(“CREATE TABLE PDFTable(SerialNumber TEXT, Textual content TEXT)”);
}
catch (Exception e){
e.printStackTrace();
}
editTextInsert = findViewById(R.id.editText2);
editTextSerialNumberInsert = findViewById(R.id.editText);
editTextSerialNumberFetch = findViewById(R.id.editText3);
textViewDisplay = findViewById(R.id.textView);
}

public void InsertUpdatedButton(View view){
ContentValues contentValues = new ContentValues();
contentValues.put(“SerialNumber”, editTextSerialNumberInsert.getText().toString());
contentValues.put(“Textual content”, editTextInsert.getText().toString());
sqLiteDatabase.insert(“PDFTable”,null,contentValues);
sqLiteDatabase.replace(“PDFTable”, contentValues, null,null);
}

public void CreatePDF(View view){
String question = “Choose Textual content from PDFTable the place SerialNumber=” + editTextSerialNumberFetch.getText().toString();
Cursor cursor = sqLiteDatabase.rawQuery(question,null);
attempt {
cursor.moveToFirst();
textViewDisplay.setText(cursor.getString(0));
}
catch (Exception e){
e.printStackTrace();
textViewDisplay.setText(“”);
return;
}

PdfDocument pdfDocument = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(300, 600,1).create();
PdfDocument.Web page web page = pdfDocument.startPage(pageInfo);
web page.getCanvas().drawText(cursor.getString(0),10, 25, new Paint());
pdfDocument.finishPage(web page);
String filePath = Atmosphere.getExternalStorageDirectory().getPath()+”/Obtain/”+editTextSerialNumberFetch.getText().toString()+”.pdf”;
File file = new File(filePath);
attempt {
pdfDocument.writeTo(new FileOutputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.shut();
}
}

————–

bundle com.instance.mysqlitedbtopdffile;

import android.content material.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;

public class mySQLiteDBHandler extends SQLiteOpenHelper {
public mySQLiteDBHandler(@Nullable Context context, @Nullable String title, @Nullable SQLiteDatabase.CursorFactory manufacturing facility, int model) {
tremendous(context, title, manufacturing facility, model);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}

source

linda

Recent Posts

Interactive Chat Games Inspired by Thrones

Have you ever found yourself wishing you could dive into the thrilling world of Westeros,…

1 day ago

Revive Your Memories: Free AI Photo Restoration

In this digital age, preserving memories has become more accessible than ever. However, many of…

4 days ago

Top Horrible Therapist Games to Try

In the ever-evolving landscape of party games, where humor and creativity collide, the "Horrible Therapist"…

4 days ago

How Visors Enhance Player Safety in Football

Football visors are transparent or tinted shields attached to the helmet's face mask. They're primarily…

2 weeks ago

Timeless Wonders Await: Exploring Beijing’s Rich Heritage on Your Trip

Introduction to Beijing Beijing, the capital of China, is a city that beautifully intertwines the…

2 weeks ago

Bangla NewsPaper Surge: 15 Game-Changing Strategies

Introduction to Bangla Newspaper Industry The Bangla newspaper sector has witnessed an incredible transformation over…

3 weeks ago