how to open pdf file using pdfviewer in android

 i made one app in which you can open pdf  

here is the source code

Screenshots:


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">

<Button
android:id="@+id/quranInHindiBtn"
android:layout_width="272dp"
android:layout_height="67dp"
android:background="#393047"
android:fontFamily="cursive"
android:text="Quran in hindi"
android:onClick="quran"
android:textColor="#ECEC19"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.228" />

<Button
android:id="@+id/aboutBtn"
android:layout_width="272dp"
android:layout_height="67dp"
android:background="#393047"
android:fontFamily="cursive"
android:onClick="about"
android:text="Contact"
android:textColor="#ECEC19"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.469" />

<Button
android:id="@+id/ExitBtn"
android:layout_width="272dp"
android:layout_height="67dp"
android:background="#393047"
android:fontFamily="cursive"
android:text="About"
android:onClick="exit"
android:textColor="#ECEC19"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.561"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.709" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-8494578888352473/6553728778"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ExitBtn"
tools:ignore="MissingConstraints"></com.google.android.gms.ads.AdView>

<com.google.android.gms.ads.AdView
android:id="@+id/adView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-8494578888352473/6553728778"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints"></com.google.android.gms.ads.AdView>

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java

package com.maktech.quraninhindi;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {
private AdView mAdView;
private AdView mAdView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

mAdView1 = findViewById(R.id.adView1);
AdRequest adRequest1 = new AdRequest.Builder().build();
mAdView1.loadAd(adRequest);
}



public void quran(View view){
Intent i=new Intent(this,QuranActivity.class);
startActivity(i);
}
public void about(View view){

Intent i=new Intent(this,ContactActivity.class);
startActivity(i);
}

public void exit(View view){

Intent i=new Intent(this,ExitActivity.class);
startActivity(i);
}
}
    quarn_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".QuranActivity">


<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

QuranActivity.java
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".QuranActivity">


<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

gradle.build dependancey
implementation 'com.google.android.gms:play-services-ads:19.1.0'

Comments

  1. Assignment Help can cover all such prime necessities that are referenced in the student's educational plan and subsequently gives an extensive solution to different sorts of economics assignments. Along these lines, their nonappearance from the classes profoundly influences their studies and they find it exceptionally difficult to finish their economics assignment on time.

    ReplyDelete
  2. I'm appreciating your time used to share this piece of informative article. Just having a nice time going through your contents. Thanks for sharing. Also visit my site eub post utme question

    ReplyDelete
  3. I appreciate you taking the time to write this amazing article for us. I'm pretty delighted to read this because it's a terrific blog with a great topic. You can also take a look at our spacebar click counter article. I've written a piece on the subject of ==. When you're bored or alone, Spacebar Counter online is a great way to pass the time. For further information, go to this blog.

    ReplyDelete

Post a Comment