Reputation: 1005
Is there a way to open a PDF file with the click of a button. The code I am using below downloads a PDF file from the web, it would be much easier if the PDF file was already on the app when it was download from the play store so the user doesn't have to download anything else. I've already looked at this question and answer but i cannot make sense of it https://stackoverflow.com/review/suggested-edits/6350919 . If its possible could you post an example as i am new to programming and find it difficult to make sense of what people are saying sometimes. Thank you very much!
Here's my Code:
public class GreekHl extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_greek_hl);
Button ge1 = (Button) findViewById(R.id.ge1);
ge1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0) {
String url1 = "http://www.examinations.ie/archive/exampapers/2014/JC007ALP000EV.pdf";
Intent ge1 = new Intent(Intent.ACTION_VIEW);
ge1.setData(Uri.parse(url1));
startActivity(ge1);
}
});
Button gm1 = (Button) findViewById(R.id.gm1);
gm1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0) {
String url1 = "http://examinations.ie/archive/markingschem/2014/JC007ALP000EV.pdf";
Intent ge1 = new Intent(Intent.ACTION_VIEW);
ge1.setData(Uri.parse(url1));
startActivity(ge1);
}
});
ps Im quite new to the whole coding thing so i may be a bit slow!
Upvotes: 0
Views: 121
Reputation: 943
I think you'll also want to go:
ge1.setType("application/pdf");
So that when you start the activity, it'll redirect to PDF viewers.
Upvotes: 1