-1

您好,我需要提供我的应用程序原始文件夹中的 pdf 文件的路径,即(R.raw.input.pdf)

请查看我的主要 java 文件,并请帮助我提供原始文件夹的路径

public class MainBrowserActivity extends Activity {
    private Button btnPDF;
    public Scanner scan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnPDF = (Button) findViewById(R.id.btnOpenPDF);

        btnPDF.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {   
                Resources res = getResources();
                scan = new Scanner(res.openRawResource(R.raw.input));

                String uri = "android.resource://" + getPackageName() + "/"+R.raw.input;

                System.out.println("FIle Path is" + uri);


                    final Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.parse(uri), "pdf/*");
                    intent.setClass(MainBrowserActivity.this,PdfViewerActivity.class);
                    startActivity(intent); 




                     }
            });

      }
   }
4

1 回答 1

6

尝试

String uri = "android.resource://" + getPackageName() + "/"+R.raw.filename;
于 2013-06-10T10:58:44.957 回答