Search code examples
javascriptappceleratortitanium-mobile

Titanium appcelerator: FileUriExposedException - How to use Content Provider?


I try to open a local pdf but it won't open because of this exception: android.os.FileUriExposedException: file:///storage/emulated/0/appid/1438-938X_2015_07/0.pdf exposed beyond app through Intent.getData()

I think I need to use a content provider, but how can I get the content:// path in appcelerator?


Solution

  • Today I was able to fix my issue.I didn't have to use a content provider. I was using this code to create an Intent:

                Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
                action: Ti.Android.ACTION_VIEW,
                type: 'application/pdf',
                data: pdfPath
            }));
    

    No I am using this code:

    var intent = Ti.Android.createIntent({
                action : Ti.Android.ACTION_VIEW,
                type : "application/pdf",
                data: pdfPath
            }); 
    
    
            var open = Ti.Android.createIntentChooser(intent, L('open_intent'));
            Ti.Android.currentActivity.startActivity(open);
    

    I hope this helps anyone with a similar problem!