## This is the pdfActivity which receives the URL of pdf and displays it in pdf viewer##
public class PDFActivity extends AppCompatActivity implements OnLoadCompleteListener, OnPageChangeListener,OnPageErrorListener {
private static final String TAG ="THERE" ;
Integer pageNumber = 0;
ProgressBar pdfViewProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf);
final PDFView pdfView= findViewById(R.id.pdfView);
pdfViewProgressBar=findViewById(R.id.pdfViewProgressBar);
pdfViewProgressBar.setVisibility(View.VISIBLE);
//UNPACK OUR DATA FROM INTENT
Intent i=this.getIntent();
final String path=i.getExtras().getString("PATH");
System.out.print(path);
FileLoader.with(this)
.load(path,false) //2nd parameter is optioal, pass true to force load from network
.fromDirectory("My_PDFs", FileLoader.DIR_INTERNAL)
.asFile(new FileRequestListener<File>() {
@Override
public void onLoad(FileLoadRequest request, FileResponse<File> response) {
pdfViewProgressBar.setVisibility(View.GONE);
File pdfFile = response.getBody();
try {
pdfView.fromFile(pdfFile).defaultPage(1).enableSwipe(true).load();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(FileLoadRequest request, Throwable t) {
pdfViewProgressBar.setVisibility(View.GONE);
Toast.makeText(PDFActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public void loadComplete(int nbPages) {
pdfViewProgressBar.setVisibility(View.GONE);
Toast.makeText(PDFActivity.this, String.valueOf(nbPages), Toast.LENGTH_LONG).show();
}
@Override
public void onPageError(int page, Throwable t) {
pdfViewProgressBar.setVisibility(View.GONE);
Toast.makeText(PDFActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onPageChanged(int page, int pageCount) {
pageNumber = page;
setTitle(String.format("%s %s / %s", "File", page + 1, pageCount));
}
public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
for (PdfDocument.Bookmark b : tree) {
Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
if (b.hasChildren()) {
printBookmarksTree(b.getChildren(), sep + "-");
}
}
}
}
## MainActivity which retrieves values from mysql and pass those to pdfActivity ##
public class MainActivity extends AppCompatActivity {
public class PDFDoc {
int id;
String name,category,pdfURL,pdfIconURL;
public int getId() {return id;}
public void setId(int id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getAuthor() {return category;}
public void setCategory(String category) {this.category = category;}
public String getPdfURL() {return pdfURL;}
public void setPdfURL(String pdfURL) {this.pdfURL = pdfURL;}
public String getPdfIconURL() {return pdfIconURL;}
public void setPdfIconURL(String pdfIconURL) {this.pdfIconURL = pdfIconURL;}
}
/*
Our custom adapter class
*/
public class GridViewAdapter extends BaseAdapter {
Context c;
ArrayList<PDFDoc> pdfDocuments;
public GridViewAdapter(Context c, ArrayList<PDFDoc> pdfDocuments) {
this.c = c;
this.pdfDocuments = pdfDocuments;
}
@Override
public int getCount() {return pdfDocuments.size();}
@Override
public Object getItem(int pos) {return pdfDocuments.get(pos);}
@Override
public long getItemId(int pos) {return pos;}
@Override
public View getView(int pos, View view, ViewGroup viewGroup) {
if(view==null)
{
view= LayoutInflater.from(c).inflate(R.layout.row_model,viewGroup,false);
}
TextView txtName = view.findViewById(R.id.pdfNameTxt);
TextView txtAuthor = view.findViewById(R.id.authorTxt);
ImageView pdfIcon = view.findViewById(R.id.imageView);
final PDFDoc pdf= (PDFDoc) this.getItem(pos);
txtName.setText(pdf.getName());
txtAuthor.setText(pdf.getAuthor());
if(pdf.getPdfURL() != null && pdf.getPdfURL().length()>0)
{
Picasso.get().load(pdf.getPdfIconURL()).placeholder(R.drawable.placeholder).into(pdfIcon);
}else {
Toast.makeText(c, "Empty Image URL", Toast.LENGTH_LONG).show();
Picasso.get().load(R.drawable.pdf_icon).into(pdfIcon);
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(c, pdf.getName(), Toast.LENGTH_SHORT).show();
Intent i=new Intent(c,PDFActivity.class);
i.putExtra("PATH",pdf.getPdfURL());
c.startActivity(i);
}
});
return view;
}
}
/*
Our HTTP Client
*/
public class JSONDownloader {
private static final String PDF_SITE_URL="https://project-fyp.000webhostapp.com/ind.php";
private final Context c;
private GridViewAdapter adapter ;
public JSONDownloader(Context c) {
this.c = c;
}
/*
DOWNLOAD PDFS FROM MYSQL
*/
public void retrieve(final GridView gv, final ProgressBar myProgressBar)
{
final ArrayList<PDFDoc> pdfDocuments = new ArrayList<>();
myProgressBar.setIndeterminate(true);
myProgressBar.setVisibility(View.VISIBLE);
AndroidNetworking.get(PDF_SITE_URL)
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
JSONObject jo;
PDFDoc p;
try
{
for(int i=0;i<response.length();i++)
{
jo=response.getJSONObject(i);
int id=jo.getInt("id");
String name=jo.getString("name");
String category=jo.getString("category");
String description=jo.getString("description");
String pdfURL=jo.getString("pdf_url");
String pdfIconURL=jo.getString("pdf_icon_url");
p=new PDFDoc();
p.setId(id);
p.setName(name);
p.setCategory(category);
p.setCategory(description);
p.setPdfURL(PDF_SITE_URL+pdfURL);
p.setPdfIconURL(PDF_SITE_URL+pdfIconURL);
pdfDocuments.add(p);
}
adapter =new GridViewAdapter(c,pdfDocuments);
gv.setAdapter(adapter);
myProgressBar.setVisibility(View.GONE);
}catch (JSONException e)
{
myProgressBar.setVisibility(View.GONE);
Toast.makeText(c, "GOOD RESPONSE BUT JAVA CAN'T PARSE JSON IT RECEIEVED. "+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
//ERROR
@Override
public void onError(ANError error) {
error.printStackTrace();
myProgressBar.setVisibility(View.GONE);
Toast.makeText(c, "UNSUCCESSFUL : ERROR IS : "+error.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final GridView myGridView= findViewById(R.id.myGridView);
Button btnRetrieve= findViewById(R.id.downloadBtn);
final ProgressBar myProgressBar= findViewById(R.id.myProgressBar);
btnRetrieve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new JSONDownloader(MainActivity.this).retrieve(myGridView,myProgressBar);
}
});
}
}
Это ошибка, которую я получаю:
E / .hfad.pdfviewe: реализация для long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument не найдена (int, java). lang.String) (пробовал Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument и Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2) E / PDFView: загрузить ошибку pdf java .png. (пробовал Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument и Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2) на com.shockwave.pdfium.PdfiumCore.nativeOpenDocument (Native Method) на com.shockwave.pdfium.PdfiumCore.newDocument (PdfiumCore java:. 113) в com.github.barteks c .pdfviewer .source.FileSource.createDocument (FileSource. java: 38) на com.github.barteks c .pdfviewer.DecodingAsyncTask.doInBackground (DecodingAsyncTask. java: 53) на com.github.barteks * 1. 015 * .pdfviewer.DecodingAsyncTask.doInBackground (DecodingAsyncTask. java: 25) по android .os.AsyncTask $ 2.call (AsyncTask. java: 333) по java .util.concurrent.FutureTask.run ( FutureTask. java: 266) в java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1167) в java .util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor. 641) в java .lang.Thread.run (Тема. java: 764) ##