Android Tutorial List of known android "Intents" to do stuff

I saw and example here and there for intents, but I noticed it takes a bit of guesswork to figure out what strings to pass sometimes so i'm starting a list of known intents. If you know any different ones please add them. pdf was obvious, however excel was not.

Filename syntax: file://SomeFolder/Filename.xxx

Sub OpenPDF(FileName As String)
Dim i As Intent 'Requires a reference to the Phone library
i.Initialize(i.ACTION_VIEW, FileName)
i.SetType("application/pdf")
i.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(i)
End Sub

Sub OpenExcel(FileName As String)
Dim i As Intent 'Requires a reference to the Phone library
i.Initialize(i.ACTION_VIEW, FileName)
i.SetType("application/vnd.ms-excel")
i.WrapAsIntentChooser("Choose Excel Viewer")
StartActivity(i)
End Sub

These are untested, but I've seen them around:

image/*
video/*
audio/*
application/pdf
application/postscript
application/zip
application/x-tar
application/msword
application/vnd.ms-excel
application/vnd.ms-powerpoint
application/vnd.oasis.opendocument.text
application/vnd.oasis.opendocument.presentation
application/vnd.oasis.opendocument.graphics
application/vnd.oasis.opendocument.image
application/vnd.oasis.opendocument.spreadsheet
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.visio
application/x-debian-package
application/vnd.android.package-archive
text/csv
text/plain
text/rtf
 

hackhack

Active Member
Licensed User
Longtime User
Here is another one, this will send a local flash file to the adobe flash player (if it isn't installed it just crashes)


B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW,"file:///sdcard/video/filename.swf")
intent1.SetType("application/x-shockwave-flash")
StartActivity(Intent1)

Keywords: play flash animation adobe flash player swf
 

Tom Christman

Active Member
Licensed User
Longtime User
I Have called the Android Calendar using the following code:

Sub Activity_Create(FirstTime As Boolean)
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN,"com.android.calendar")
Intent1.SetComponent("com.android.calendar/.LaunchActivity")
StartActivity(Intent1)
End Sub

Tom
 
Last edited:

Woale

New Member
Licensed User
Longtime User
To open Voice Settings (not always visible)

B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("com.android.settings/.TextToSpeechSettings")
StartActivity(Intent1)
 

junaidahmed

Well-Known Member
Licensed User
Longtime User
I understood the above code,but when i open pdf file it shows an error message as "No application can perform this action".my code is given below


Dim i As Intent
i.Initialize(i.ACTION_VIEW,"/mnt/sdcard/Data/DailyProd.pdf")
i.SetType("application/pdf")
i.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(i)
 

siddsg

Member
Licensed User
Longtime User
Intent for calling the Messaging App?

Hello,
Would you know the intent for the default messaging app?
Thanks,
Siddharth
 

DonManfred

Expert
Licensed User
Longtime User
Would you know the intent for the default messaging app?

first i found this

Then i tried to port this to b4a (i´m relative new to b4a)

B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetType("vnd.android-dir/mms-sms")
Intent1.PutExtra("sms_body", "Content of the SMS goes here...")    
StartActivity(Intent1)

and it works for me... :)
 

siddsg

Member
Licensed User
Longtime User
Open the message composer.

Thanks so much!
That worked.
Here's a small change, to open the SMS composer:

Intent1.Initialize(Intent1.ACTION_VIEW, "")
Intent1.SetType("vnd.android-dir/mms-sms")
Intent1.PutExtra("address", "123")
StartActivity(Intent1)

So,
Intent1.Initialize(Intent1.ACTION_MAIN, "") 'opens the messages list

Intent1.Initialize(Intent1.ACTION_VIEW, "") 'opens the message composer
 

MrKim

Well-Known Member
Licensed User
Longtime User
After much playing around I got the following intents to work. While the ones you show work, they don't show the exact syntax for the filename, which is tricky, and NOT intuitive - the path prefix winds up being file:/// (yes THREE '/'!). Also for you newbies (of which I am one) don't forget you CANNOT load a file from the internal directories because the external applications don't have access to it (that cost me 20 minutes).

The below are based on having installed QuickOffice which is evidently written BY Google which is available FREE from the Android store. They were tested by me and work on my Nexus 7.

B4X:
Sub OpenPdf_Click
Dim i As Intent 'Requires a reference to the Phone library
Msgbox("file:/" &  File.DirDefaultExternal & "/713-042124-001.pdf","")
Msgbox(File.Exists(File.DirDefaultExternal,"713-042124-001.pdf"),"713-042124-001.pdf")
i.Initialize(i.ACTION_VIEW, "file://" &  File.DirDefaultExternal & "/713-042124-001.pdf")
i.SetType("application/pdf")
i.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(i)
 
End Sub
Sub OpenExcel_Click
    Dim i As Intent 'Requires a reference to the Phone library
i.Initialize(i.ACTION_VIEW, "file://" &  File.DirDefaultExternal & "/0267337-001_BOM-NPI-Import.xls")
'i.SetType("application/xls")
i.SetType("application/vnd.ms-excel")
'i.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(i)
End Sub
Sub OpenWord_Click
    Dim i As Intent 'Requires a reference to the Phone library
i.Initialize(i.ACTION_VIEW,  "file://" & File.DirDefaultExternal & "/Test.doc")
i.SetType("application/vnd.ms-word")
'i.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(i)
End Sub
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Here is some more useful info on intents:
If there is more than one application that can open a file and a default has not been set (At least I found this true for pdf files with Adobe and QuickOffice both available:

This code will open the Chooser IF THE DEVAULT HAS NOT BEEN SET and allow you to SET THE DEFAULT.
B4X:
i.Initialize(i.ACTION_VIEW, "file://" & File.DirDefaultExternal & "/713-042124-001.pdf")
i.SetType("application/pdf")
StartActivity(I)
This code will ALWAYS open the Chooser IF THERE IS MORE THAN ONE PROGRAM but WITHOUT the Option of setting the default.
B4X:
    i.Initialize(i.ACTION_VIEW, "file://" &  File.DirDefaultExternal & "/713-042124-001.pdf")
    i.SetType("application/pdf")
    i.WrapAsIntentChooser("Choose PDF Viewer")
    StartActivity(i)
This code will open the FILE DIRECTLY WITH ADOBE READER - NO CHOOSER!
B4X:
    i.Initialize(i.ACTION_VIEW, "file://" &  File.DirDefaultExternal & "/713-042124-001.pdf")
    StartActivity(i)

'This code will ALWAYS OPEN WITH ADOBE READER even if you add
i.WrapAsIntentChooser("Choose PDF Viewer")[/CODE]
B4X:
i.Initialize2("file://" & File.DirDefaultExternal & "/713-042124-001.pdf", 0)
StartActivity(I)
 
Last edited:
Top