1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

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

Discussion in 'Tutorials & Examples' started by kanaida, Jun 22, 2011.

Similar threads

B4A Code Snippet [B4X] Bytes To File
B4A Library Printing and Pdf creation
B4A Code Snippet Upload files with WebView
B4A Library OkHttp - Replaces the Http library
B4A Question Share txt files
  1. kanaida

    kanaida Active Member Licensed User

    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

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

     
  2. hackhack

    hackhack Active Member Licensed 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)


    Code:
    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
     
  3. Tom Christman

    Tom Christman Active Member Licensed 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: Nov 9, 2011
  4. Woale

    Woale New Member Licensed User

    To open Voice Settings (not always visible)

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

    warwound Expert Licensed User

    Have you seen the openintents website?

    Another link HERE.

    Lots of potential i think.

    Martin.
     
    Multiverse app likes this.
  6. junaidahmed

    junaidahmed Well-Known Member Licensed 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)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Did you install a PDF reader?
     
  8. junaidahmed

    junaidahmed Well-Known Member Licensed User

    Thanks for your quick replay
     
  9. warwound

    warwound Expert Licensed User

  10. siddsg

    siddsg Member Licensed User

    Intent for calling the Messaging App?

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

    DonManfred Expert Licensed User

    first i found this

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

    Code:
    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... :)
     
    Leo10 likes this.
  12. holdemadvantage

    holdemadvantage Active Member Licensed User

    Sorry ...i would like to set LAT and LONG to the navigator (default one, com.google.android.apps.maps) , what is the intent i have to use?
     
  13. NJDude

    NJDude Expert Licensed User

    Code:
    Dim i As Intent

    i.Initialize(i.ACTION_VIEW, 
    "geo:40.7142,-74.0064")

    StartActivity(i)
     
  14. siddsg

    siddsg Member Licensed 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
     
  15. holdemadvantage

    holdemadvantage Active Member Licensed User

    Thanks NJ:)
     
  16. MrKim

    MrKim Active Member Licensed 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.

    Code:
    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: Oct 6, 2013
  17. MrKim

    MrKim Active Member Licensed 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.
    Code:
    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.
    Code:
    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!
    Code:
    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]
    Code:
    i.Initialize2("file://" & File.DirDefaultExternal & "/713-042124-001.pdf"0)
    StartActivity(I)
     
    Last edited: Oct 8, 2013
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice