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

The Ultimate Guide to YouTube to MP4 Converters

A YouTube to MP4 conversion software is a software or on-the-web tool designed to download…

2 days ago

Unox Equipment: A Chef’s Companion

Cooking is an art, and each artist needs the right equipment to bring their masterpiece…

2 days ago

Comparing Electric Scooters: Features and Performance

Hey there, scooter enthusiast! Whether you're a seasoned rider or just thinking about zipping around…

2 days ago

Discovering Affordable Massage Services throughout Busan

Hey there, massage fans! If you're in Busan and also searching for a way to…

2 days ago

Guide to Aroma Massage Services in Busan

Hey there! If you're planning a trip to Busan, or if you're already here and…

2 days ago

Is Instant Famous Worth It? A Detailed Review of Their Follower Services

Are you looking for ways to get more followers on your social media accounts to…

3 days ago