STEP - 1 : Create a New Project
STEP - 2 : Paste a library to lib folder
Click here to download : itsrts-pptviewer.jar
STEP - 3 : Add dependency to App level Gradle
build.gradle (App)
Inside dependency
compile files('libs/itsrts-pptviewer.jar')
STEP - 4 : Add permission to Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
STEP - 5 : Paste or Download a ppt into your phone download folder.
STEP - 6 : Inside your activity, paste your code which show ppt file
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="@dimen/activity_horizontal_margin" > <com.itsrts.pptviewer.PPTViewer android:id="@+id/pptviewer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="24dp" /> </RelativeLayout>
MainActivity.java
import android.os.Environment;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import com.itsrts.pptviewer.PPTViewer;import java.io.File; public class MainActivity extends AppCompatActivity { PPTViewer pptViewer; String path = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pptViewer = (PPTViewer) findViewById(R.id.pptviewer); File f = new File(Environment.getExternalStorageDirectory().getPath(), "/Download/fashion.ppt"); // File f = FileUtils.fileFromAsset(MainActivity.this, "junit.ppt"); path = f.getPath().toString(); pptViewer.setNext_img(R.drawable.next).setPrev_img(R.drawable.prev) .setSettings_img(R.drawable.settings) .setZoomin_img(R.drawable.zoomin) .setZoomout_img(R.drawable.zoomout); pptViewer.loadPPT(this, path); } }
STEP - 7 : Create a class, which handle the interation between app storage ( Phone or Assets)
FileUtils.java
import android.content.Context;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream; public class FileUtils { private FileUtils() { // Prevents instantiation } public static File fileFromAsset(Context context, String assetName) throws IOException { File outFile = new File(context.getCacheDir(), assetName + "-pdfview.pdf"); if (assetName.contains("/")) { outFile.getParentFile().mkdirs(); } copy(context.getAssets().open(assetName), outFile); return outFile; } public static void copy(InputStream inputStream, File output) throws IOException { OutputStream outputStream = null; try { outputStream = new FileOutputStream(output); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } } finally { try { if (inputStream != null) { inputStream.close(); } } finally { if (outputStream != null) { outputStream.close(); } } } } }
\\\
hii please help me i have done like you done it,
ReplyDeletebut i want to read ppt file from database using REST API how to do it please help me
can i get this packages to my react native project
ReplyDelete