使用第三方Android库加载PPT文件

时间:2018-01-25 14:43:22

标签: java android android-studio

ScreenShot of the app after lauching我已经在我的应用中导入了这个库https://github.com/itsrts/pptviewer-android,方法是在libs文件夹中添加.jar文件。我想将ppt文件加载到我的app中。不幸的是,应用程序一直显示加载发射后的旋转器。

MainActivity.java

package com.example.myapplication;

import android.app.Activity;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.itsrts.pptviewer.PPTViewer;


public class MainActivity extends Activity {

PPTViewer pptViewer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pptViewer = (PPTViewer) findViewById(R.id.pptviewer);
    String path = Environment.getExternalStorageDirectory().getPath()
            + "/Download/check.ppt";
    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);

}
}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.myapplication.MainActivity">

<com.itsrts.pptviewer.PPTViewer
    android:id="@+id/pptviewer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
 </android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

PPT查看器代码正在运行,但只有全屏问题。 它显示正在运行的原因是由于您提供的ppt路径不正确。如果提供的路径不正确,它将继续加载。 尝试检查提供的路径是否正确

File file = new File("Environment.getExternalStorageDirectory().getPath()
        + "/Download/check.ppt"");
if(file.exists()){
        Toast.makeText(getApplicationContext(),"File Present",Toast.LENGTH_LONG).show();
    }else{
        Toast.makeText(getApplicationContext(),"File Not Present",Toast.LENGTH_LONG).show();
    }

如果文件不存在或路径错误,则会显示吐司通知