I am making a app where a user should be able to click on a pdf file that is stored on firebase and the file should open without saving it to the device and user should be able to read it now currently when I click on the pdf it gets downloaded to device through web browser i want to give this downloading option after the user has viewed the pdf
this is my code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
menuButton=findViewById(R.id.menuButton);
listView=findViewById(R.id.listview);
uploads=new ArrayList<>();
//create method
viewAllFiles();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
pdfClass pdfupload=uploads.get(i);
Intent intent= new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
intent.setData(Uri.parse(pdfupload.getUrl()));
startActivity(intent);
}
});
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NavigationActivity.class));
finish();
}
});
}
private void viewAllFiles() {
databaseReference= FirebaseDatabase.getInstance().getReference("Uploads");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for(DataSnapshot postsnapshot: snapshot.getChildren()){
pdfClass pdfClass=postsnapshot.getValue(com.example.dmcianappversion4.pdfClass.class);
uploads.add(pdfClass);
}
String[] Uploads= new String[uploads.size()];
for(int i=0;i<Uploads.length;i++){
Uploads[i]=uploads.get(i).getName();
}
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1,Uploads){
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view=super.getView(position,convertView,parent);
TextView text =(TextView) view.findViewById(android.R.id.text1);
text.setTextColor(Color.BLACK);
text.setTextSize(22);
return view;
}
};
listView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
this is the code where i need help after onclick it should display the pdf so what code should i put in the on click listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
pdfClass pdfupload=uploads.get(i);
Intent intent= new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
intent.setData(Uri.parse(pdfupload.getUrl()));
startActivity(intent);
}
});
so can someone please help im new to android so i dont know very much about android studio
i tried some of the answers that are there in stackoverflow but i couldnt get them to work