Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5950] Hyperloop: Android PhoneStateListener apiName returns null

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNeeds more info
Resolution Date2018-12-03T21:30:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
Labelsandroid, hyperloop
ReporterMichael Gangolf
AssigneeShak Hossain
Created2018-10-01T16:05:45.000+0000
Updated2018-12-03T21:40:42.000+0000

Description

When trying to add PhoneStateListener to get the cell information most listeners work besides onCellInfoChanged. When I add this I'll end up with: _Cannot read property 'apiName' of null_ {noformat} [ERROR] TiExceptionHandler: (main) [51,51] /hyperloop/android.telephony.PhoneStateListener.js:1 [ERROR] TiExceptionHandler: (function (exports, require, module, __filename, __dirname, Titanium, Ti, global, kroll) {var Hyperloop=require('hyperloop'),parentPackage=require('./android.telephony'),PhoneStateListener=function(){var a;a=1==arguments.length&&arguments[0].isNativeProxy&&arguments[0].isInstanceProxy&&arguments[0].isInstanceOf('android.telephony.PhoneStateListener')?arguments[0]:PhoneStateListener.class.newInstance(arguments),this.$native=a,this._hasPointer=null!=a,this._private={}},SuperClass=require('./java.lang.Object');PhoneStateListener.prototype=Object.create(SuperClass.prototype),PhoneStateListener.prototype.constructor=PhoneStateListener,Object.defineProperty(PhoneStateListener.prototype,'super',{get:function(){return this._hasPointer?new PhoneStateListener(this.$native.super):null},enumerable:!0}),PhoneStateListener.className='android.telephony.PhoneStateListener',PhoneStateListener.prototype.className='android.telephony.PhoneStateListener',Object.defineProperty(PhoneStateListener,'class',{get:function(){return Hyperloop.getClass('android.telephony.PhoneStateListener')},enumerable:!0,configurable:!1}),PhoneStateListener.extend=function(a){var b=Hyperloop.extend('android.telephony.PhoneStateListener'),c=function(){function c(a){if(a.apiName&&a.isNativeProxy&&a.isInstanceProxy){var b=require('./'+a.apiName);return new b(a)}return a}function d(){for(var a=[],b=0;b
var win = Ti.UI.createWindow({backgroundColor:"#fff"});
var GsmCellLocation = require("android.telephony.gsm.GsmCellLocation");
var TelephonyManager = require("android.telephony.TelephonyManager");
var CellInfoLte = require("android.telephony.CellInfoLte");
var CellInfoGsm = require("android.telephony.CellInfoGsm");
var Activity = require('android.app.Activity');
var activity = new Activity(Ti.Android.currentActivity);
var Context = require("android.content.Context");

var tm = new TelephonyManager(activity)

var PhoneStateListener = require("android.telephony.PhoneStateListener");
var psl = PhoneStateListener.extend({
	onCellInfoChanged: function(ev) {
		console.log("onCellInfoChanged");
	},
	onCellLocationChanged: function(ev) {
		console.log("onCellLocationChanged " + ev);
	},
	onServiceStateChanged: function(ev) {
		console.log("onServiceStateChanged " + ev);
	},
	onSignalStrengthsChanged: function(ev) {
		console.log("onSignalStrengthsChanged " + ev);
	}
});
tm.listen(new psl(), PhoneStateListener.LISTEN_CALL_STATE |
	PhoneStateListener.LISTEN_CELL_INFO |
	PhoneStateListener.LISTEN_CELL_LOCATION |
	PhoneStateListener.LISTEN_DATA_ACTIVITY |
	PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
	PhoneStateListener.LISTEN_SERVICE_STATE |
	PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
	PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
	PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR);

win.open();
Add this to tiapp.xml and enable the permissions manually:
<android xmlns:android="http://schemas.android.com/apk/res/android">
		<manifest>
			<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
			<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
		</manifest>
	</android>
Hyperloop 3.1.3 Titanium SDK 7.4.0.GA Android 7

Comments

  1. Rakhi Mitro 2018-11-29

    Hello, Thanks for reporting this. Can you please test this on 7.5.0.GA again and let us know how it goes. It would be helpful if you can share your complete console log and environment details here.
  2. Michael Gangolf 2018-12-03

    Sorry for the late reply. Yes, with 7.5.0.GA it is the same error message. This is the complete error message:
       [ERROR] TiExceptionHandler: (main) [74,74] /hyperloop/android.telephony.PhoneStateListener.js:1
       [ERROR] TiExceptionHandler: (function (exports, require, module, __filename, __dirname, Titanium, Ti, global, kroll) {var Hyperloop=require('hyperloop'),parentPackage=require('./android.telephony'),PhoneStateListener=function(){var a;a=1==arguments.length&&arguments[0].isNativeProxy&&arguments[0].isInstanceProxy&&arguments[0].isInstanceOf('android.telephony.PhoneStateListener')?arguments[0]:PhoneStateListener.class.newInstance(arguments),this.$native=a,this._hasPointer=null!=a,this._private={}},SuperClass=require('./java.lang.Object');PhoneStateListener.prototype=Object.create(SuperClass.prototype),PhoneStateListener.prototype.constructor=PhoneStateListener,Object.defineProperty(PhoneStateListener.prototype,'super',{get:function(){return this._hasPointer?new PhoneStateListener(this.$native.super):null},enumerable:!0}),PhoneStateListener.className='android.telephony.PhoneStateListener',PhoneStateListener.prototype.className='android.telephony.PhoneStateListener',Object.defineProperty(PhoneStateListener,'class',{get:function(){return Hyperloop.getClass('android.telephony.PhoneStateListener')},enumerable:!0,configurable:!1}),PhoneStateListener.extend=function(a){var b=Hyperloop.extend('android.telephony.PhoneStateListener'),c=function(){function c(a){if(a.apiName&&a.isNativeProxy&&a.isInstanceProxy){var b=require('./'+a.apiName);return new b(a)}return a}function d(){for(var a=[],b=0;b<arguments.length;b++)a[b]=c(arguments[b]);return a}var e=b.newInstance(arguments),f=this,g=a,h={};Object.keys(g).forEach(function(a){f[a]=function(){return g[a].apply(f,arguments)},h[a]=function(){return f[a].apply(f,d.apply(this,arguments))}}),e.setOverrides(h),this.$native=e,this._hasPointer=null!=e,this._private={}};return c.prototype=Object.create(PhoneStateListener.prototype),c.prototype.constructor=c,c},PhoneStateListener.cast=function(a){return a.$native&&a.$native.isInstanceProxy?new PhoneStateListener(Hyperloop.cast('android.telephony.PhoneStateListener',a.$native)):a},PhoneStateListener.LISTEN_NONE=0,PhoneStateListener.LISTEN_CELL_INFO=1024,PhoneStateListener.LISTEN_DATA_CONNECTION_STATE=64,PhoneStateListener.LISTEN_CELL_LOCATION=16,PhoneStateListener.LISTEN_CALL_STATE=32,PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE=524288,PhoneStateListener.LISTEN_SERVICE_STATE=1,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS=256,PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR=4,PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR=8,PhoneStateListener.LISTEN_DATA_ACTIVITY=128,PhoneStateListener.LISTEN_SIGNAL_STRENGTH=2,PhoneStateListener.prototype.onServiceStateChanged=function(){if(!this._hasPointer)return null;var a=this.$native.callNativeFunction({func:'onServiceStateChanged',instanceMethod:!0,args:Array.prototype.slice.call(arguments)});if(null==a)return null;if(a.apiName){if('android.telephony.PhoneStateListener'===a.apiName)return new PhoneStateListener(a);var b=require('./'+a.apiName);return new b(a)}return a},PhoneStateListener.prototype.onUserMobileDataStateChanged=function(){if(!this._hasPointer)return null;var a=this.$native.callNativeFunction({func:'onUserMobileDataStateChanged',instanceMethod:!0,args:Array.prototype.slice.call(arguments)});if(null==a)return null;if(a.apiName){if('android.telephony.PhoneStateListener'===a.apiName)return new PhoneStateListener(a);var b=require('./'+a.apiName);return new b(a)}return a},PhoneStateListener.prototype.onCallStateChanged=function(){if(!this._hasPointer)return null;var a=this.$native.callNativeFunction({func:'onCallStateChanged',instanceMethod:!0,args:Array.prototype.slice.call(arguments)});if(null==a)return null;if(a.apiName){if('android.telephony.PhoneStateListener'===a.apiName)return new PhoneStateListener(a);var b=require('./'+a.apiName);return new b(a)}return a},PhoneStateListener.prototype.onDataConnectionStateChanged=function(){if(!this._hasPointer)return null;var a=this.$native.callNativeFunction({func:'onDataConnectionStateChanged',instanceMethod:!0,args:Array.prototype.slice.call(arguments)});if
       [ERROR] V8Exception: Exception occurred at /hyperloop/android.telephony.PhoneStateListener.js:1: Uncaught TypeError: Cannot read property 'apiName' of null
       
       Operating System
         Name                        = Fedora
         Version                     = 29
         Architecture                = 64bit
         # CPUs                      = 12
         Memory                      = 15.3GB
       
       Node.js
         Node.js Version             = 10.12.0
         npm Version                 = 6.4.1
       
       Appcelerator CLI
         Installer                   = 4.2.13
         Core Package                = 7.0.8
       
       Titanium CLI
         CLI Version                 = 5.1.1
         node-appc Version           = 0.2.44
       
    Hyperloop 3.1.4 SDK 7.5.0.GA Android 7 (HTC A9)

JSON Source