Android Tutorial [TUTORIAL] Inter-app Communication with Intents

Discussion in 'Tutorials & Examples' started by thedesolatesoul, Jun 28, 2013.

  1. Federico956

    Federico956 Member Licensed User

    Hi @tdocs2 ,

    can you post your manifest editors?

    Thanks
     
  2. tdocs2

    tdocs2 Well-Known Member Licensed User

    Hello, Federico.

    The manifest for the IntentProvider is:
    Code:
    'This code will be applied to the manifest file during compilation.
    'You do not need to modify it in most cases.
    'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "11" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    AddActivityText(TestIntent, <
    intent-filter>
       <action android:name=
    "swi.IntentProvider.REQUEST" />
       <category android:name=
    "android.intent.category.DEFAULT" />
    </
    intent-filter>)
    'End of default text.
    For the IntentRequester
    Code:
    'This code will be applied to the manifest file during compilation.
    'You do not need to modify it in most cases.
    'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "4" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    'End of default text.
    Best regards.

    Sandy
     
    Federico956 likes this.
  3. Federico956

    Federico956 Member Licensed User

    Thank you so much!
    Federico
     
  4. tdocs2

    tdocs2 Well-Known Member Licensed User

    You are welcome, Federico.

    Since you are relatively new to the forum, whenever someone does something useful to you, give them a Like (click next to the post #).

    Best regards.

    Sandy
     
    Federico956 likes this.
  5. Federico956

    Federico956 Member Licensed User

    Sure @tdocs2, I've done it!
    Hi all,
    I have a problem. I'm using a TC55 with its barcode scanner and its scanning app (DataWedge). In DataWedge there are some settings that allow you to use intent (Action, Category and delivery type), so when you scan a code you can have the code "into your app" and you can manipulate it.
    I wrote a little code to try it and it works great, so I've tried to implement the code into my app and I noticed a strange behaviour: the first little app has only one activity and it works correctly, my app has lots of activity but I have to use the barcode scanner only in one of them.
    When I scan a barcode, instead of execute the code written in Activity_Resume, it is called the activity create of the main activity.
    I know it is something strange to explain, I hope you'll understand.

    Here's the code of the Activity_Resume:

    Code:
    Sub Activity_Resume
       
    Dim myintent As Intent
       myintent = 
    Activity.GetStartingIntent
       
    If myintent.GetExtra("com.motorolasolutions.emdk.datawedge.data_string") <> Null Then
         
    Dim dwstring As String = "com.motorolasolutions.emdk.datawedge.data_string"
         
    Dim read As String = myintent.GetExtra(dwstring)
         EditBC.Text = read
       
    End If
    End Sub
    Thanks
     
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    What device are you running on? It is possible the device runs low on memory and kills your app in the background, and then restarts it as the bar-code scanner exits.
     
    Federico956 likes this.
  7. Federico956

    Federico956 Member Licensed User

    Hi @thedesolatesoul,
    I'm using a Motorola TC55, it is not a terrible device! What should I do?

    Thanks for rapid reply
     
  8. thedesolatesoul

    thedesolatesoul Expert Licensed User

    In your manifest, you need to add the intent filter to the activity you want to receive the intent.
    Is it set correctly? You may have to post your manifest code if you cant spot it.
     
    Federico956 likes this.
  9. Federico956

    Federico956 Member Licensed User

    Here it is the manifest:

    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "4" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=
    "true"
      android:normalScreens=
    "true"
      android:smallScreens=
    "true"
      android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    AddActivityText(Main, <
    intent-filter>
      <action android:name=
    "com.IntentProvider.REQUEST" />
      <category android:name=
    "android.intent.category.DEFAULT" />
    </
    intent-filter>)
    It is the same in the small app I've tried and in my app.

    EDIT: AddActivityText(Main, <intent-filter>
    I have found the stupid but big error, I applied the intent-filter only to Main activity, right?
     
    Last edited: Nov 6, 2014
    thedesolatesoul likes this.
  10. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Yup, set it to the activity you want to open.
     
    Federico956 likes this.
  11. Federico956

    Federico956 Member Licensed User

    I've done it, now it works perfectly, thank you so much!
    I've another (maybe the last :p) question: is there a way, in a Start Activity intent, to "abort" the intent after receiving data?
     
  12. thedesolatesoul

    thedesolatesoul Expert Licensed User

    After you took the data you can call Activity.Finish to shut down the current activity. This will though create a small flicker of your activity showing and disappearing. If you want to do it in the background, you can also use a Service for this.
     
    Federico956 likes this.
  13. Federico956

    Federico956 Member Licensed User

    Thank you for this hint.
    Federico
     
  14. Cüneyt Gargin

    Cüneyt Gargin Member Licensed User

    Dea


    Dear Federico,
    Did you succeed in using TC55 Scan via Intents...
     
  15. imbault

    imbault Well-Known Member Licensed User

    Thank you @thedesolatesoul ,

    Very interesting, when you need APK communications, and I need a solution right now...

    Just a simple question, does an App can be as well Provider and Requester?

    Do we have others alternatives on Android (except file semaphores or SQLite solutions)?

    Many thanks.

    Patrick
     
  16. johndb

    johndb Active Member Licensed User

    I'm using the information presented in this tutorial as a basis for my inter-app communications and it works very well with SDK 19 and below. Communicating with services using implicit intents fail in apps targeted for apps using SDK above 19 due to increased android security. How do I change the information in the tutorial to use explicit intents for service communications?

    Thank you in advance.

    [SOLVED]

    To make the intent directed to a service "explicit" simply add the following:

    Intent.SetComponent("<package name>/.<service>")


    John
     
    Last edited: May 17, 2016
    LucaMs likes this.
  17. DonManfred

    DonManfred Expert Licensed User

    You shpuld start a new thread for this. Upload a sample app which shows the problem.
     
  18. johndb

    johndb Active Member Licensed User

    The post is related to this thread. It has been solved see my previous post.
     
    DonManfred likes this.
  19. mickeyk600

    mickeyk600 Member Licensed User

    Can some one help me how to write this in B4A:

    Intent intent = new Intent(Intent.ACTION_RUN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData("http://strava.com/nfc/record");
    startActivity(intent);
     
  20. Rusty

    Rusty Well-Known Member Licensed User

    Does anyone have a working simple example both provider and requestor?
    Thanks,
    Rusty
     
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