2012-04-24 18 views
0

アンドロイドアプリケーションを作成しました。 私は拡張可能なリストを作成しました。子をクリックすると、PDFを開きます。 PDFが開いていないと、no_application_foundのコンテンツであるメッセージが表示されます(「PDFを開くことができません」)。 オープンPDFのコードは次のとおりです。アンドロイドアプリケーションでPDFを開くことができません

public boolean onChildClick (
     ExpandableListView parent, 
     View v, 
     int groupPosition, 
     int childPosition, 
     long id) { 
    Log.d(LOG_TAG, "onChildClick: " + childPosition); 

    File file = new File("http://www.ratt.ro/grafice/e2-a.pdf"); 
    Uri path = Uri.fromFile(file); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    intent.setDataAndType(path, getString(R.string.application_type)); 
    try 
    { 
     startActivity(intent); 
    } 
    catch (ActivityNotFoundException e) 
    { 
     Toast.makeText(ElistCBox.this, 
      getString(R.string.no_application_found), 
      Toast.LENGTH_SHORT).show(); 
    } 

    return false; 
} 

答えて

3

これは、あなたがウェブ・ビューでPDFを開く方法です:ユーザーがない場合はこちらを

webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.ratt.ro/grafice/e2-a.pdf"); 
+0

を私は、あなたのソリューションを試してみてくださいおかげでそんなに – Andreea

+0

、それが動作するかどうか、ちょうど私の答えを「受け入れる」にチェックマークをクリックします:) – Pallavi

+0

もちろん、私はそれをします。 – Andreea

0

は、リーダーでPDFファイルを開くための私のコードですそれはGoogleにリンクを開き、任意のPDFリーダーを持っているものをダウンロードするためにプレー:

void openpdf (String filename) 

{ 
    String loc = "/sdcard/"; 
    File file = new File(loc+filename); 
    Uri path = Uri.fromFile(file); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(path, "application/pdf"); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    try { 
     startActivity(intent); 
    } catch (Exception e) { 

     e.printStackTrace(); 
     Toast.makeText(getApplicationContext(), "No pdf reader installed", Toast.LENGTH_SHORT).show(); 
     Intent market = new Intent(Intent.ACTION_VIEW); 
     market.setData(Uri.parse("market://details?id=com.adobe.reader")); 
     startActivity(market); 
    } 

} 
+0

あなたの解決策を今試してみます。ありがとうございます – Andreea

+0

filename = "http://www.ratt.ro/grafice/e2-a.pdf"を入力できますか? – Andreea

+0

@SabauAndreeaあなたはそれを使用する前にまずそれをダウンロードしなければなりません – zapl