I have PDF files in my assets folder now i am able to view that PDF files in list view .But the problem is now on click of any pdf i want to open pdf in my pdf viewer. Here is my code
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AssetManager asset = getAssets();
try {
final String[] arrdata = asset.list("PDFfolder");
List<String> pdflist = new ArrayList<String>();
int size = arrdata.length;
for(int i = 0;i<size;i++)
{
if(arrdata[i].contains(".pdf"))
{
pdflist.add(arrdata[i]);
}
}
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,pdflist);
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0 ) {
File pdffile = new File("file:///android_assets/AAI.pdf");
//File ff = new File(getAssets().open("AAI.pdf"));
Uri path = Uri.fromFile(pdffile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);
}
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Now please help me out how to open it using intent from my assets folder. i am getting error of having no activity found to handle intent as i already have pdfviewer in my phone.