QDesktopServices::openUrl( QUrl::fromLocalFile( “…pdf”) ) without Acrobat Reader - crash
-
Hy all!
I've tried a lot of things but nothing worked.
Situation: I'm downloading a PDF file (Location: /storage/sdcard0/MyFolder).
onDownloadFinished - I'm opening the .pdf.It's working on Windows - without any problems.
It's working on Android with Adobe Reader.
But without Adobe Reader - it's not working on Android. And I don't know why.@DownloadRequestedFile( requestParam, LOCAL_FILE_PATH, [](){
QDesktopServices::openUrl( QUrl::fromLocalFile( LOCAL_FILE_PATH ) );
});@
This is the CommandLine which should open the file
Here's the error Log
@
E/AndroidRuntime(24835): FATAL EXCEPTION: Thread-1269
E/AndroidRuntime(24835): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/sdcard0/MyFolder/MyPDF.pdf }
E/AndroidRuntime(24835): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
E/AndroidRuntime(24835): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
E/AndroidRuntime(24835): at android.app.Activity.startActivityForResult(Activity.java:3351)
E/AndroidRuntime(24835): at android.app.Activity.startActivityForResult(Activity.java:3312)
E/AndroidRuntime(24835): at android.app.Activity.startActivity(Activity.java:3522)
E/AndroidRuntime(24835): at android.app.Activity.startActivity(Activity.java:3490)
E/AndroidRuntime(24835): at org.qtproject.qt5.android.QtNative.openURL(QtNative.java:115)
E/AndroidRuntime(24835): at dalvik.system.NativeStart.run(Native Method)@Maybe someone is able to help me or give me a hint?
I don't wanna use Poppler or use a Java solution :-P
-
ActivityNotFoundException - means there is no programm associated with this url/file extension. It is just a normal Android SDK exception. The fact what program crashes is the Qt BUG.
-
Hello, I have a similar problem.
@AcerExtensa: did I understand correctly that the crash is a Qt bug?
Secondly, I'm using the same method of opening the .pdf file, but I'm wondering if there is a way to put my file(s) somewhere relative to the program.
For that matter, I don't even know where the program is on my Samsung Galaxy Tab 8.9. I'm trying to find it, but I have no idea where it's supposed to get placed upon deployment.
Also, I've seen some mention of using the assets folder, but I'm not sure how. Any help, please?Sorry if these seem like stupid questions, but I've been pulling my hair out over this.
-
[quote author="Lucijan" date="1379583727"]
@AcerExtensa: did I understand correctly that the crash is a Qt bug?
[/quote]Yes it is, ActivityNotFoundException exception should be definitely handled, but it is not.
[quote author="Lucijan" date="1379583727"]
Secondly, I'm using the same method of opening the .pdf file, but I'm wondering if there is a way to put my file(s) somewhere relative to the program.
For that matter, I don't even know where the program is on my Samsung Galaxy Tab 8.9. I'm trying to find it, but I have no idea where it's supposed to get placed upon deployment.
Also, I've seen some mention of using the assets folder, but I'm not sure how. Any help, please?Sorry if these seem like stupid questions, but I've been pulling my hair out over this.[/quote]
Maybe it is easy to explain with examples.... Open your QtCreator and create new QML Android project. Your .qml files are deployed to device and application opens it on start, look at cpp file to see how the app do it. In .pri(secondary project file I think or maybe in .pro) file you will see some lines with your qml files, here it tells "compiler" how and where this files should be putted on device/in .apk. Just copy paste this lines and change them to your needs/your files... You can also search this mobile subforum, i have saw some threads about putting files in .apk....
-
OK, after some playing around, I think I got it, but now it crashes with the following output:
@E/AndroidRuntime(27949): FATAL EXCEPTION: Thread-14
E/AndroidRuntime(27949): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=assets:/qml/DesignForAndroid/Papers/170.pdf }
E/AndroidRuntime(27949): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1535)
E/AndroidRuntime(27949): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
E/AndroidRuntime(27949): at android.app.Activity.startActivityForResult(Activity.java:3150)
E/AndroidRuntime(27949): at android.app.Activity.startActivity(Activity.java:3256)
E/AndroidRuntime(27949): at org.qtproject.qt5.android.QtNative.openURL(QtNative.java:115)
E/AndroidRuntime(27949): at dalvik.system.NativeStart.run(Native Method)@My intention was to use the assets system (check above) to open the PDF files with Adobe Reader. I'm using the QDesktopServices::openURL() to open the file and this works if I use an absolute path (/mnt/sdcard/DCIM/Papers/170.pdf) but not if I use the relative one (assets:/qml/DesignForAndroid/Papers/170.pdf). Here's the code I'm using:
@bool ExternalFileStarter::openFile(QString fileName)
{
return QDesktopServices::openUrl(QUrl::fromLocalFile(fileName));
}@I have noticed that when I try to search for files stored as assets on the Android device, they will not be found so I'm assuming that assets are something like qrc. That would explain why the asset files won't open (and the fact that fromLocalFile() adds a "file://").
So I'm back on square one, trying to figure out where does the application get stored on the Android device. I can't find it for the life of me, and using applicationFilePath() will return the file "app_process" which I assume is Android's and not my executable or rather, "app_process" runs the app. I've tried checking out the .pri file but I have no idea what's going on there and since the QML files also get stored as assets, they aren't much help. Thinking about it further, it could be that there is no way to get a relative path in the first place. What I mean is, I can't get the location of the package from Qt, and I think that where the package gets put differs from device to device.
Am I wrong or is there a way for me to get a relative path? If not, would it be possible to use qrc and then extract the files relative to the package? Any help would be most appreciated.