Using new annotations

77 views
Skip to first unread message

Tiziano Conti

unread,
Dec 13, 2017, 8:16:38 AM12/13/17
to App Inventor Open Source Development
I see the BroadcastReceiver can be dinamically linked with android manifest via the annotations, but I do not find the documentation about to do it. So if I use @UsesBroadcastReceivers (myReceiver.class) or something like, it can find the symbol, which is defined later  ....

Jose Dominguez

unread,
Dec 13, 2017, 9:59:17 AM12/13/17
to app-inventor-open-source-dev
The Texting component uses that annotation; maybe looking at the code
will help: https://github.com/mit-cml/appinventor-sources/blob/master/appinventor/components/src/com/google/appinventor/components/runtime/Texting.java#L132

cheers,
José
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to app-inventor-open-so...@googlegroups.com.
> To post to this group, send email to
> app-inventor-o...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/app-inventor-open-source-dev.
> For more options, visit https://groups.google.com/d/optout.

Tiziano Conti

unread,
Dec 13, 2017, 10:14:49 AM12/13/17
to App Inventor Open Source Development
Thank you very much for your hint!
Message has been deleted

Tiziano Conti

unread,
Dec 14, 2017, 3:33:01 AM12/14/17
to App Inventor Open Source Development
I saw the page, I tried to annotate my receiver and it compiled without error but unfortunately it does not  work, so I have some doubts about two things:
 -when I annotate my receiver I set as name the full qualified name "com.mypackageName.myreceiverName". However this is not the name of final app, which I do not know, but only the name of my extension.
Should it work anyway when incorporated in an app? And is this annotation enough to have got the receiver registered in manifest?

- I found in row 966 of Texting.java file this code "activity.registerReceiver(sendReceiver, new IntentFilter(SENT));" Is this registration code compulsory? Without it the manifest will be written anyway? And such a receiver will survive to the app shut down and also a reboot (with needed code added) or it is similar to a context registered receiver?

Il giorno mercoledì 13 dicembre 2017 15:59:17 UTC+1, Jos ha scritto:
The Texting component uses that annotation; maybe looking at the code
will help: https://github.com/mit-cml/appinventor-sources/blob/master/appinventor/components/src/com/google/appinventor/components/runtime/Texting.java#L132

cheers,
José



On 13 December 2017 at 13:16, Tiziano Conti <tizianoc...@gmail.com> wrote:
> I see the BroadcastReceiver can be dinamically linked with android manifest
> via the annotations, but I do not find the documentation about to do it. So
> if I use @UsesBroadcastReceivers (myReceiver.class) or something like, it
> can find the symbol, which is defined later  ....
>
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Evan Patton

unread,
Dec 14, 2017, 9:55:38 AM12/14/17
to App Inventor Open Source Development
Hi Tiziano,

The code you cite is only for sending texts, not receiving them, which is what the BroadcastReceiver is used for in Texting. So no, it is not compulsory to register a new receiver in the code. It should be sufficient to just provide the annotation, which will include the info required to update the manifest during compilation, and then when appropriate broadcast is received Android will start an instance of the receiver class.

Note that you won't be able to test this in the companion since the manifest is not modifiable at runtime. You will need to build the apps for testing.

Regards,
Evan

Tiziano Conti

unread,
Dec 14, 2017, 11:38:31 AM12/14/17
to App Inventor Open Source Development
Thank You very much. I already made my apps but, in reading the manifest , I find no clue of the the receiver (and, by the way , of a permission annotation too), so the compiler has not included it . I would focus your attention to the first of my previous question:
 -when I annotate my receiver I set its name to be a full qualified name "com.myExtensionPackageName.myreceiverName". However this is not the name of final app, which I do not know, but only the name of my extension.
Should it work anyway when incorporated in an app? 
Is this one the problem and is there a workaround?
 (The same code used in an app made in adroid studio works perfectly, the modifications to adapt it to an extension  have been kept at minimum...)
Thanks again

Tiziano Conti

unread,
Dec 15, 2017, 3:22:04 AM12/15/17
to App Inventor Open Source Development
I cloned again appinventor sources, I lost an update probably,  and now the annotations are incorporated in app manifest but the registered name is that of my extension and not the app name. 
I would focus your attention to the first of my previous question:
 -when I annotate my receiver I set its name to be a full qualified name "com.myExtensionPackageName.myreceiverName". However this is not the name of final app, which I do not know, but only the name of my extension.
Should it work anyway when incorporated in an app? 
Is this one the problem and is there a workaround?
 (The same code used in an app made in adroid studio works perfectly, the modifications to adapt it to an extension  have been kept at minimum...)
Thanks again

Evan Patton

unread,
Dec 15, 2017, 3:43:15 PM12/15/17
to App Inventor Open Source Development
The fully qualified class name does not need to be updated to match the app package. For example, this is how the texting component handles its broadcast receiver and it stays in the com.google.appinventor.components.runtime package.

Evan

Ken Nichols

unread,
Jun 3, 2018, 12:28:26 AM6/3/18
to App Inventor Open Source Development
Tiziano1960,

Did you get your Broadcast Receiver working?

I am currently working on an extension that will require a Broadcast Receiver and could use some pointers.

Tiziano1960

unread,
Jun 3, 2018, 3:03:38 AM6/3/18
to App Inventor Open Source Development
Yes it's working
Reply all
Reply to author
Forward
0 new messages