Caution : It's install one aditional app to show PDF
STEP - 1 : First Create a new application in android studio
File --> New ---> New Project ---> ' Enter App Name and Package Name' ---> Next ---> Target Devices ---> Next ---> Add an Activity to Mobile ( Choose Empty Activity) ---> Next --->
Activity Name ---> Finish.
STEP - 2 : First, Download the sample module from below link
////// https://drive.google.com/file/d/0BzTjcv17QPlwY25HY2FNb0hzREE/view?usp=sharing
After download,import this module in app.
File ---> New ---> Import Module ---> Click on [...] three dot icon to browse module ----> Select it ---> OK
After few minute, it import the module
STEP - 3 : Now, add dependency to your Project level gradle
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Project Gradle : Before
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir}
Project Gradle : After added dependency
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir}
STEP - 4 : Paste below code in your activity page
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="file.download.app.com.pdfreader1.MainActivity"> <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Click to view PDF" /></RelativeLayout>
MainActivity.java
import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.os.Bundle;import android.view.View;import android.widget.Button; public class MainActivity extends Activity { Button btnPDF; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnPDF = (Button)findViewById(R.id.btn1); btnPDF.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i; PackageManager manager = getPackageManager(); try { i = manager.getLaunchIntentForPackage("com.github.barteksc.sample"); if (i == null) throw new PackageManager.NameNotFoundException(); i.addCategory(Intent.CATEGORY_LAUNCHER); i.putExtra("file","sample.pdf"); startActivity(i); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }); } }
STEP - 5 : Now Run the app then you unable to see 'MainActivity' because Sample Module Activity ' PDFViewActivity' replaced it, like this -
STEP - 6 : To show first, App MainActivity, need to configure app ( In EditConfiguration ).
follow the image
A. Click on sample ( Left tab of Run )
B. Now, Click on Edit Configuration
C. Open Genral Tab ---> Module ----> Click on Sample
D. Select App --->OK
////
No comments:
Post a Comment