Android open pdf file via Intent

I have some pdf files in some folder in sdcard. I created an app that shows all pdf as ListView. When i click on any pdf file it gives error in OfficeSuite application (UNSUPPORTED OR CORRUPT FILE FORMAT. Is something wrong with the code. Here is the code.

//Code for Items displayed as ListVIew

    ListView lv;
    ArrayList<String> FilesInFolder = GetFiles(Environment.getExternalStorageDirectory()
            + "/SOMEFOLDER");
    lv = (ListView) findViewById(;

    lv.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, FilesInFolder));

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // Clicking on items

    public ArrayList<String> GetFiles(String DirectoryPath) {
    ArrayList<String> MyReports = new ArrayList<String>();
    File f = new File(DirectoryPath);

    File[] files = f.listFiles();
    if (files.length == 0)
        return null;
    else {
        for (int i=0; i<files.length; i++)

    return MyReports;

//Code for opening files VIA Intent

    public void open_File(){
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/SOMEFOLDER");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/pdf");
    Intent intent1 = Intent.createChooser(intent, "Open With");
    try {
    } catch (ActivityNotFoundException e) {
        // Instruct the user to install a PDF reader here, or something


Corrupt or unsupported file format

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.