Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24420] Hyperloop : Android: Unable to access getApplicationContext method in android.content.Context class

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionNot Our Bug
Resolution Date2017-03-08T22:21:33.000+0000
Affected Version/sRelease 6.0.0, Release 6.0.1
Fix Version/sn/a
ComponentsAndroid, Hyperloop
Labelsn/a
ReporterNeeraj Mishra
AssigneeJan Vennemann
Created2017-02-21T17:58:09.000+0000
Updated2017-05-31T22:30:56.000+0000

Description

Problem Description:

Unable to access method getApplicationContext in android.content.Context class using Hyperloop while trying to use thord party library Localytics for Android. (attached the third party library as well)

Steps to reproduce:

1. Create a classic app and enable Hyperloop. 2. Run the attached (app.js) code. 3. You will see the below error message:
[ERROR] :  TiExceptionHandler: (main) [42,42] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,42] - In /app.js:5,56
[ERROR] :  TiExceptionHandler: (main) [0,42] - Message: Uncaught SyntaxError: Invalid or unexpected token
[ERROR] :  TiExceptionHandler: (main) [0,42] - Source: var appContext = (new context).getApplicationContext();​​​
[DEBUG] :  OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[DEBUG] :  D/        : HostConnection::get() New Host Connection established 0xe98bfe40, tid 1965
[ERROR] :  V8Exception: Exception occurred at /app.js:5: Uncaught SyntaxError: Invalid or unexpected token

Expected Result:

To be able to get the ApplicationContext in order to use it for localytics method parameter.

Attachments

FileDateSize
app.js2017-02-21T17:58:43.000+0000218
localytics.jar2017-02-21T17:58:50.000+0000530347

Comments

  1. Jan Vennemann 2017-02-28

    [~nmishra], the code they are using is wrong. android.content.context is an abstract class which cannot be instantiated. Also it is not possible to hook into the application's onCreate method from Hyperloop, which is the designated place to run Localytics.autoIntegrate() according to the documentation of the Localytics SDK. They can try this, but it won't log the first activity launched.
       var Activity = require('android.app.Activity');
       var currentActivity = new Activity(Ti.Android.currentActivity);
       var Localytics = require('com.localytics.android.Localytics');
       Localytics.autoIntegrate(currentActivity.getApplicationContext());
       Localytics.setLoggingEnabled(true);
       // Example how to use listeners
       var AnalyticsListenerAdapter = require('com.localytics.android.AnalyticsListenerAdapter');
       var listener = new AnalyticsListenerAdapter({
           localyticsSessionWillOpen: function(isFirst, isUpgrade, isResume) {
           // ... do something ...
           Ti.API.debug('Localytics session will open');
         }
       });
       Localytics.setAnalyticsListener(listener);
       
    For a full integration they could write a module, place the Localytics SDK there and include a method annotated with @Kroll.onAppCreate where the Localytics SDK can be properly initialized. After that they can then continue to use Hyperloop to make all other calls to the Localytics SDK.
  2. Jan Vennemann 2017-02-28

    It's a key provided by Localytics to identify the app. Please see their docs: https://docs.localytics.com/dev/android.html#modify-androidmanifest-android and our docs how to add that: http://docs.appcelerator.com/platform/latest/#!/guide/Maintaining_a_Custom_AndroidManifest.xml
  3. Neeraj Mishra 2017-02-28

    [~jvennemann]: Thanks much. It will help.
  4. Neeraj Mishra 2017-03-08

    [~jvennemann]: This worked at customer end too and we can close this jira too. Thanks for your help.
  5. Lee Morris 2017-05-31

    Closing ticket with reference to the above comments.

JSON Source