Bug 307605 - Not able to run local files via QDesktopServices::openUrl
Summary: Not able to run local files via QDesktopServices::openUrl
Status: RESOLVED UNMAINTAINED
Alias: None
Product: Necessitas
Classification: Applications
Component: Android Qt4 (show other bugs)
Version: alpha4
Platform: Android Android 2.x
: HI normal
Target Milestone: Beta 2
Assignee: BogDan Vatra
URL: http://sourceforge.net/p/necessitas/t...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-30 09:57 UTC by Roman Pasechnik
Modified: 2018-09-04 16:15 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Pasechnik 2012-09-30 09:57:06 UTC
When trying to run a local file on Android, the MIME type needs to be set as well for the Intent. 
Thus the QDesktopServices::openUrl((QUrl("file:///sdcard/temp/SCM.apk"))) gives the following error:
I/ActivityManager( 2704): Starting: Intent { act=android.intent.action.VIEW dat=file:///sdcard/temp/SCM.apk } from pid 8656
E/AndroidRuntime( 8656): FATAL EXCEPTION: Thread-10
E/AndroidRuntime( 8656): java.lang.NoClassDefFoundError: org.kde.necessitas.industrius.QtNative$4
E/AndroidRuntime( 8656): at org.kde.necessitas.industrius.QtNative.setFullScreen(QtNative.java:400)
E/AndroidRuntime( 8656): at dalvik.system.NativeStart.run(Native Method)
E/AndroidRuntime( 8656): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///sdcard/temp/SCM.apk}
E/AndroidRuntime( 8656): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
E/AndroidRuntime( 8656): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
E/AndroidRuntime( 8656): at android.app.Activity.startActivityForResult(Activity.java:2833)
E/AndroidRuntime( 8656): at android.app.Activity.startActivity(Activity.java:2959)
E/AndroidRuntime( 8656): at org.kde.necessitas.industrius.QtNative.openURL(QtNative.java:76)
E/AndroidRuntime( 8656): ... 1 more
I think this may be fixed by changing the openURL function in src/android/jar/src/org/kde/necessitas/industrius/QtNative.java from
public static void openURL(String url)
{
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity().startActivity(intent);
}
to the following:
public static void openURL(String url)
{
if (url.toLowerCase().startsWith("file:"))
{ 

Intent intent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mime = MimeTypeMap.getSingleton();
File file = new File(url);
String ext=file.getName().substring(file.getName().lastIndexOf(".")+1).toLowerCase();
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(file),type);
activity().startActivity(intent);
}
else
{
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity().startActivity(intent);
}
}
Must also add the following import:
import android.webkit.MimeTypeMap;
Otherwise one will have to find a mechanism to provide the MIME filetype some other way.

Reproducible: Always

Steps to Reproduce:
1. Create Hello World Necessitas application.
2. In main.cpp add code QDesktopServices::openUrl((QUrl("file:///sdcard/temp/image.jpg")))
3. Make sure there is temp/image.jpg file on sd card.
4. Run the program.
Actual Results:  
No intent with image pops up.

Expected Results:  
Gallery application intent with image pops up.

This is a bug reported by TomasL on the sourceforge page of Necessitas
http://sourceforge.net/p/necessitas/tickets/159/
Comment 1 Andrew Crouthamel 2018-09-04 16:15:38 UTC
Hello! Sorry to be the bearer of bad news, but this project has been unmaintained for many years and I will be closing this bug.