Ich habe ein pdf mit meiner eigenen Anwendung geöffnet. Jetzt, wenn Benutzer auf einen Knopf klickt, zeige ich openwith Optionen von Anwendung/pdf an. Jetzt wählt der Benutzer seine Wahl (zum Beispiel Adobe Reader) und die geöffnete PDF-Datei muss in der Benutzerauswahl angezeigt werden (in diesem Fall adobereader). Ich habe Bytearray und Eingabestream mit mir für das geöffnete PDF.open pdf mit openwith option android
Antwort
Versuchen Sie, diese
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
EDIT 1
OutputStream out = new FileOutputStream("out.pdf");
out.write(bArray);
out.close();
Nach pdf erstellen,
File file = new File("filepath");
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
EDIT 2
File myFile = new File("out.pdf");
OutputStream out = new FileOutputStream(myFile);
out.write(bytArray);
out.close();
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(myFile),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
kann dies hilft Ihnen
EDIT 3
Der folgende Code wurde von mir getestet und es funktioniert wie u
die pdf-Datei erstellen möchten:
File resolveMeSDCard = new File("/sdcard/download/media/output.pdf");
public void createPDF()
{
byte[] byt = new byte[]{1,2,3,4,5};
File mediaDir = new File("/sdcard/download/media");
if (!mediaDir.exists()){
mediaDir.mkdir();
}
FileOutputStream fos;
try {
//File resolveMeSDCard = new File("/sdcard/download/media/output.pdf");
resolveMeSDCard.createNewFile();
fos = new FileOutputStream(resolveMeSDCard);
fos.write(byt);
fos.close();
System.out.println("Your file has been written");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Your file has not been written");
}
}
Öffnen Sie die PDF-Datei:
public void openPDF()
{
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(resolveMeSDCard),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
}
manifest.xml
fügen Sie die folgende Erlaubnis
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Note :
1.Change der Code, um als Sie wollen.
2. Rufen Sie createPDF() und dann OpenPDF() auf.
Dies ist Arbeitscode.
Danke für die Antwort Sathish .. aber meine Datei ist nicht physisch verfügbar ,, Ich habe die Datei in Bytearray und Inputstream sowie ... –
Dann erstellen Sie zuerst PDF von Ihrem ByteArray. siehe meine EDIT 1 –
Was ist Dateipfad in Datei ... wo ich keine Datei habe stattdessen habe ich nur out.pdf ... –
wenn auf Openwith in App .. im mit Content-Provider angeklickt als meine Datei physikalisch nicht vorhanden ist ...
try {
createCachedFile(this, attachmentFileName, bytes);
startActivity(pdfOpenWith(this, attachmentFileName, bytes));
}catch (IOException e) {
e.printStackTrace();
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "Not available on this device.", Toast.LENGTH_SHORT).show();
}
public void createCachedFile(Context context, String fileName, byte[] content) throws IOException {
File cacheFile = new File(context.getCacheDir() + File.separator + fileName);
cacheFile.createNewFile();
BufferedOutputStream bostream = new BufferedOutputStream(new FileOutputStream(cacheFile));
bostream.write(content);
bostream.flush();
bostream.close();
}
public static Intent pdfOpenWith(Activity context, String fileName, byte[] bytecontent)
{
Intent pdfintent = new Intent(Intent.ACTION_VIEW);
//pdfintent.setType("application/pdf");
Uri contenturi = Uri.parse("content://" + AttachFileProvider.AUTHORITY + "/" + fileName);
Toast.makeText(context, fileName, Toast.LENGTH_LONG).show();
pdfintent.setDataAndType(contenturi, "application/pdf");
pdfintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pdfintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return pdfintent;
- 1. emacs dired und openwith
- 2. Open XML als PDF speichern
- 3. Open-Source-Web-PDF-Viewer?
- 4. Open Source Javascript PDF Viewer
- 5. PowerPoint zu PDF: Mindestgröße Option
- 6. Android-Option Menü mit Symbol
- 7. Open-Source-PDF-Bibliothek in c
- 8. Android Facebook Open Graph?
- 9. anzeigen PDF in Android
- 10. Android Open-Mail-Client
- 11. PDF-Download deaktivieren und speichern Option
- 12. Wie PDF auf Android machen PdfRenderer mit
- 13. Android Option Menü
- 14. Datei lesen mit "open()" vs "mit open()"
- 15. PDF render in Android
- 16. Android Open Fragment über ViewPager
- 17. Open Gallery App in Android
- 18. Android PDF Viewer
- 19. Open GL Line Draw android
- 20. Android öffnen pdf-Datei
- 21. Open-Telegramm-Kanal in Android
- 22. Open URL in Android App
- 23. wie PDF in Android öffnen pdfview mit
- 24. PDF-Viewer-Bibliothek mit Seitenrotation in android
- 25. So konvertieren Android View to PDF
- 26. .NET Open PDF in Winform ohne externe Abhängigkeiten
- 27. Welche Option hatte ich für Open Source Charting Bibliothek?
- 28. Window.Open mit PDF-Stream statt PDF Standort
- 29. Android Tablet Zoom-Option fehlt
- 30. Open-Source-PDF-Bibliothek für C/C++ - Anwendung?
Und was ist Ihre Frage? – AxelH
hallo, es wird standardmäßig angezeigt. aber was hast du bisher probiert? –
openwith Fenster wird standardmäßig angezeigt, aber wenn ich auf eine Schaltfläche in meiner App klicken, ich zeige openwith intent und jetzt Benutzer wählt Adobe Reader, jetzt möchte ich die gleichen PDF-Dokument PDF-Bytes in Adobereader zeigen. Eigentlich bin ich newbee zu Android und nicht in der Lage zu starten oder zu identifizieren, welches Ereignis hier ausgelöst .... –