Create and open file(pdf/image/text/doc) at selected/ Download folder using intent from Android App?
24 هزار بار بازدید -
2 سال پیش
-
This video shows the steps
This video shows the steps to create and open a file of any type (pdf, jpeg, txt or doc) at a user selected or download folder using intent from your Android App.
It uses basic actions of ACTION_CREATE_DOCUMENT and ACTION_VIEW to create the document and view/ open the document in your intent.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]
Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...
However, the main Java code is copied below also for reference:
package com.programmerworld.createandopenafileofanytype;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE},
PackageManager.PERMISSION_GRANTED);
}
public void buttonCreateFile(View view){
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT, MediaStore.Downloads.EXTERNAL_CONTENT_URI);
// intent.setType("application/pdf");
intent.setType("*/*");
this.startActivity(intent);
}
public void buttonOpenFile(View view){
Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Downloads.EXTERNAL_CONTENT_URI);
// intent.setType("application/pdf");
intent.setType("*/*");
this.startActivity(intent);
}
}
-
It uses basic actions of ACTION_CREATE_DOCUMENT and ACTION_VIEW to create the document and view/ open the document in your intent.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]
Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...
However, the main Java code is copied below also for reference:
package com.programmerworld.createandopenafileofanytype;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE},
PackageManager.PERMISSION_GRANTED);
}
public void buttonCreateFile(View view){
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT, MediaStore.Downloads.EXTERNAL_CONTENT_URI);
// intent.setType("application/pdf");
intent.setType("*/*");
this.startActivity(intent);
}
public void buttonOpenFile(View view){
Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Downloads.EXTERNAL_CONTENT_URI);
// intent.setType("application/pdf");
intent.setType("*/*");
this.startActivity(intent);
}
}
-
2 سال پیش
در تاریخ 1401/04/12 منتشر شده
است.
24,014
بـار بازدید شده