Android Question Open external files with your app

Star-Dust

Expert
Licensed User
Longtime User
I used this method to click on an EPUB file to start my App

MANIFEST
B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:pathPattern=".*\\.epub" />
<data android:mimeType="application/epub+zip" />
</intent-filter>)

On Code
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim In As Intent = Activity.GetStartingIntent 
Dim FileNameParameter As String = In.GetData

If FileNameParameter<>Null Then
     Log(FileNameParameter)
End If
Obviously if there are other Apps that open the same format, a menu will pop up that lists all the apps if you have not set the OPEN ALWAYS WITH option

Clearly you have to change the values to open other formats, but you'll find enough on the internet. I hope this track will help you
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thank Star but anyway i have this message:

Screenshot_20170919-131609.png


"no app can do the action.."
Any solution ?
Thanks
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User

Hi Erel, thank for your tips, anyway i have this code in App:

Manifest:
B4X:
AddActivityText(Main,
<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="text/pst" />
</intent-filter>)

Code:
B4X:
#BridgeLogger: True

Sub Process_Globals
    Private OldIntent As Intent
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)

End Sub

Sub Activity_Resume
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim in As JavaObject = Activity.GetStartingIntent
        Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
        Try
            Log("Say: " & uri)
        Catch
            Log(LastException)
        End Try
    End If
End Sub

Private Sub IsRelevantIntent(in As Intent) As Boolean
    If in.IsInitialized And in <> OldIntent And in.Action = in.ACTION_SEND Then
        OldIntent = in
        Return True
    End If
    Return False
End Sub


Sub Activity_Pause (UserClosed As Boolean)

End Sub

Compiled in Release mode.
But anyway if i tap on file xxxx.pst ( that is simple terxt file but with extension pst ) i have this message:

Screenshot_20170919-134947.png


Where i wrong ?
Thanks
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Does there exists a MimeType "text/pst"? I only know "text/plain"
If there exists a mimetype for pst files then you need to use it. Try text/plain
same thing my dear Don

B4X:
AddActivityText(Main,
<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="text/plain" />
</intent-filter>)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Note that you should upload smaller images. The large images just make the thread less comprehensible.

Check this thread: https://www.b4x.com/android/forum/threads/eligible-open-with-for-own-file-extension-abc.65427

I tried on 3 different devices (Android 5.X / 6.X / 7.X) same result doesn't work

Manifest:
B4X:
AddActivityText(main,
         <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="https" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="content" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="file" android:host="*"
                    android:pathPattern=".*\\.pst" />
            </intent-filter>
)


Code:
B4X:
Sub Activity_Resume
    Dim in As Intent
    in = Activity.GetStartingIntent
    Log("Result: " & in )
End Sub

When i TAP on the file the message is "Unable to find application perform this action"

Screenshot_2017-09-20-06-56-23.jpg
 

Attachments

  • SourceB4A.zip
    8.7 KB · Views: 291
  • stampapos.zip
    192 bytes · Views: 255
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried it with android 7.
Wth the default FileExplorer it does not work, but with EsExplorer i could select a specific app and i choose b4a example...

Result: (Intent) Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/stampapos.pst typ=*/* flg=0x10000000 cmp=b4a.example/.main launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I tried on 3 different devices (Android 5.X / 6.X / 7.X) same result doesn't work

Manifest:
B4X:
AddActivityText(main,
         <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="https" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="content" android:host="*"
                    android:pathPattern=".*\\.pst" />
                <data android:scheme="file" android:host="*"
                    android:pathPattern=".*\\.pst" />
            </intent-filter>
)


Code:
B4X:
Sub Activity_Resume
    Dim in As Intent
    in = Activity.GetStartingIntent
    Log("Result: " & in )
End Sub

When i TAP on the file the message is "Unable to find application perform this action"

View attachment 59852
Is missing Mime Type
In my experience, with my EPUB reader, it does not work if Mime Type settings are missing or are wrong

<data android:mimeType="text/plain" /> ' I hope is right :p
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Is missing Mime Type
In my experience, with my EPUB reader, it does not work if Mime Type settings are missing or are wrong

<data android:mimeType="text/plain" /> ' I hope is right :p
Is missing Mime Type
In my experience, with my EPUB reader, it does not work if Mime Type settings are missing or are wrong

<data android:mimeType="text/plain" /> ' I hope is right :p
Dont change nothing.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I tried it with android 7.
Wth the default FileExplorer it does not work, but with EsExplorer i could select a specific app and i choose b4a example...
Thank dear Don the problem is that it should work with any File Explorer. So, there is something that does not work.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank dear Don the problem is that it should work with any File Explorer. So, there is something that does not work.
if tonight I come back soon I try to take a look, because in my App works
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I tried this code and it works:

Open a file manager and click on any pst file. The App will automatically open and receive as the parameter the name of the full minute file

I hope to be proved helpful
 

Attachments

  • extension.zip
    19.5 KB · Views: 283
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
in the Manifest:
B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.pst" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.pst" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.pst" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.pst" />
<data android:mimeType="*/*" />
</intent-filter>)

'<data android:pathPattern=".*\\.pst" />

In the code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim In As Intent = Activity.GetStartingIntent  
    Dim Parametri As String = In.GetData
  
    If Parametri<>Null Then
        ' Apertura parametri
        Log("Start App with parameter: " & Parametri)
        Activity.LoadLayout("print")
        LabelInfo.Text="Print file: " & Parametri
    Else
        Log("Open Main App")
        Activity.LoadLayout("main")
    End If
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I tried this code and it works:

Open a file manager and click on any pst file. The App will automatically open and receive as the parameter the name of the full minute file

I hope to be proved helpful
Thank you Start for your commitment. Unfortunately, continues to not work.


I've noticed in any case doing some research by writing the following instructions in the manifest file (essentially dividing the same with multiple hypotheses):

B4X:
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/octet-stream"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/pst"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)
AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/octet-stream"
    android:scheme="file"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/pst"
    android:scheme="file"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/octet-stream"
    android:scheme="content"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/pst"
    android:scheme="content"
    android:host="*"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/octet-stream"
    android:host="*"
    android:scheme="http"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/pst"
    android:host="*"
    android:scheme="http"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)


AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/octet-stream"
    android:host="*"
    android:scheme="https"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

AddActivityText(Main,
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data
    android:mimeType="application/pst"
    android:host="*"
    android:scheme="https"
    android:pathPattern=".*\\.pst"
  />
</intent-filter>
)

Code B4A ( Return ):
B4X:
Sub Activity_Resume
    Dim in As Intent
    in = Activity.GetStartingIntent
    Log("Result: " & in )
End Sub

it works with 99% of navigators. 1% = In my example it does not work on the standard navigator ( app default device )
Example if i use Filecommander to open file, work and i have this result:
Result: (Intent) Intent { act=android.intent.action.VIEW dat=content://com.mobisystems.fileman.RemoteFiles/ZmlsZTovLy9zdG9yYWdlL2VtdWxhdGVkLzAvRG93bmxvYWQvMTUwNTkxNzY5NC5wc3Q/0 typ=application/octet-stream flg=0x3 cmp=test.file.com/.main launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }

here for example i see it using
typ=application/octet-stream

but in the standard navigator doesn't work, even though it has included all ( i hope ) combinations.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I've tested my code on Android 4.2.2, 6 .0.1, 7.0.0 these are the results:

With version 6 and 7 after you open the OPEN WITH select panel open ... and the game is done. Selecting the right MIME should not let all other Apps appear but just yours.
The best result I got with Android 4 that directly opens my App without asking OPEN WITH.

I do not understand why you do not work. Which device did you try the code? And what version of android has it?

Android 4.2.2.gif Android 6.0.1.gif Android 7.gif
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I've tested my code on Android 4.2.2, 6 .0.1, 7.0.0 these are the results:

With version 6 and 7 after you open the OPEN WITH select panel open ... and the game is done. Selecting the right MIME should not let all other Apps appear but just yours.
The best result I got with Android 4 that directly opens my App without asking OPEN WITH.

I do not understand why you do not work. Which device did you try the code? And what version of android has it?

View attachment 59889 View attachment 59890 View attachment 59891
Mhh.. this is a "mystery"
I tried with:
Samsung S7 with Droid 7.0
Samsung S6 with Droid 6.X
Samsung J3 with Droid 6.X
 
Upvote 0
Top