デバイスに保存せず、サードパーティのアプリケーションを使用せずにサーバーからPDFファイルを開く方法ファイル。
31123 次
3 に答える
17
このメソッドは、古いバージョンの Android で機能しました。
新しいアクティビティで:
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=URL_of_PDF/fileName.pdf");
setContentView(webview);
internet
マニフェスト ファイルで許可を与えます。
次の方法を使用して、サードパーティ アプリケーションが既にインストールされている PDF ファイルを開きます。
アプリケーションで PDF を開くには:
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
于 2012-05-07T11:18:20.397 に答える
4
PdfViewer.jarを使用して、以下のようなコードを作成します -ここからコピー
First.java
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for(int i = 0;i<imagelist.length;i++)
{
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, pdflist));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String path = imagelist[(int)id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path)
{
try
{
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Second.java
public class Second extends PdfViewerActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
これが大いに役立つことを願っています。これを試して。マニフェストに Second.java を追加することを忘れないでください。ドローアブルを使用して second.java に必要なものをいくつか追加します。そして、GitHubの例を参照してください
于 2012-06-05T03:00:41.540 に答える
0
このためには、pdf リーダー ライブラリを使用する必要があります。このリンクが役立ちます。
https://stackoverflow.com/questions/4665957/pdf-parsing-library-for-android
于 2012-05-07T11:10:54.030 に答える