Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14666] Android: push notification icon does not show the default icon if the chosen one is missing

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.2.0, Release 3.2.1
Fix Version/sn/a
ComponentsAndroid
LabelssupportTeam
ReporterDavide Cassenti
AssigneeUnknown
Created2013-07-26T09:14:36.000+0000
Updated2018-02-28T20:03:42.000+0000

Description

Problem description

When sending a push notification to the device, if the payload contains the icon and the file is not available, or the icon is not specified, the documentation states the default app icon would be used. However, instead of the app icon's, an "information" image is shown instead.

Steps to reproduce

Just send a notification to the Android device, with the icon in the Payload. If the icon is not specified, or it does not exist, the wrong icon is shown.

Additional information

The documentation says the app icon is used: http://docs.appcelerator.com/cloud/latest/#!/guide/android-section-7 "If no icon is provided or the provided one is unreachable, the app's icon will be used by default."

Code to reproduce the issue

I used the following code to get the notifications and test this. To send a notification, I use the dashboard.
(function() {
	var platform = null;
	var type = null;
	var deviceToken = null;
	var username = null;
 
	var label = null;
 
	// Cloud modules
	var CloudPush = null; // required for Android
	var Cloud = require('ti.cloud');
 
	function init() {
		platform = Ti.Platform.osname;
		type = platform;
 
		switch(platform) {
			case "iphone":
			case "ipad":
				type = "ios";
				buildUI();
				break;
 
			case "android":
				CloudPush = require("ti.cloudpush");
				CloudPush.debug = true;
 
				buildUI();
				break;
 
			default:
				showError("Platform not supported!");
		}
	}
 
	function buildUI() {
		var win = Ti.UI.createWindow({
		    backgroundColor : 'black',
		    layout: 'vertical'
		});
 
		var title = Ti.UI.createLabel({
			text: "Appcelerator Cloud Services",
			font: {
				fontSize: "20dp"
			},
			color: "white",
			top: "10dp",
			height: Ti.UI.SIZE
		})
 
		win.add(title);
 
		var btn = Ti.UI.createButton({
			title: "Subscribe",
			height: Ti.UI.SIZE,
			top: '10dp'
		});
 
		btn.addEventListener('click', function(e) {
			label.text = "";
 
			// login the default user
			checkUser();
		});
 
		win.add(btn);
 
		label = Ti.UI.createLabel({
			text: "",
			width: Ti.UI.FILL,
			height: Ti.UI.FILL,
			color: "#dddddd",
			top: '10dp'
		});
 
		win.add(label);
 
		win.open();
	}
 
	function checkUser(retrying) {
		Cloud.Users.logout(function (e) {
	    	username = Ti.App.Properties.getString('username');
			if(username) {
				loginUser(retrying);
			} else {
				username = "";
				for(var i=0; i<10; i++) {
					username += ("" + Math.floor(10 * Math.random()));
				}
 
				addLog("Registering user " + username + "...");
				Cloud.Users.create({
					username: username,
			        password: 'logmein',
			        password_confirmation: 'logmein'
			    }, function (e) {
			        if (e.success) {
			            addLog("User registered.");
			            Ti.App.Properties.setString('username', username);
			            loginUser(retrying);
			        } else {
			            showError(e);
			        }
			    });
			} 
	    });
	}
 
	function loginUser(retrying) {
		addLog("Logging in as " + username + "...");
		Cloud.Users.login({
            login : username,
            password : 'logmein'
        }, function(e) {
            if (e.success) {
            	addLog("Logged in as " + username + ".");
                getDeviceToken();
            } else {
            	if(retrying) {
            		showError(e);
            	} else {
	                // try recreating the user
	                Ti.App.Properties.setString('username', null);
	                checkUser(true);
	            }
            }
        });
	}
 
	function getDeviceToken() {
		switch(type) {
		case "android":
			CloudPush.retrieveDeviceToken({
			    success : registrationSuccess,
			    error : showError
			});
			break;
 
		case "ios":
			Titanium.Network.registerForPushNotifications({
				types: [
					Titanium.Network.NOTIFICATION_TYPE_ALERT
				],
 
				success: registrationSuccess,
				error: showError,
				callback: handleNotification
			});
			break;
		}
	}
 
	function defaultUnsubscribe() {
		Cloud.PushNotifications.unsubscribe({
			device_token: deviceToken
		}, function(e) {
			defaultSubscribe();
		});
	}
 
	function defaultSubscribe() {
		Cloud.PushNotifications.subscribe({
			channel: 'alert',
			type: type,
			device_token: deviceToken
		},
			function (e) {
				if (e.success) {
					addLog("Subscribed to the alert channel");
				} else {
					addLog("Already subscribed to the alert channel");
				}
 
				addLog("Ready to receive notifications");
			});
 
		switch(type) {
		case "android":
		    CloudPush.addEventListener('callback', function(e) {
			    handleNotification(e);
			});
		}
	}
 
	function registrationSuccess(e) {
		deviceToken = e.deviceToken;
		addLog("Got device token: " + deviceToken);
 
		if(platform == "android") {
			CloudPush.enabled = true;
		}
 
		defaultUnsubscribe();
	}
 
	function showError(e) {
		alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
	}
 
	function handleNotification(e) {
		addLog("Notification received");
		if(e && e.payload && e.payload.alert) {
			alert(e.payload.alert);
		} else {
			alert(JSON.stringify(e));
		}
	}
 
	function addLog(text) {
		label.text = label.text + "\n" + text;
	}
 
	init();
})();

Attachments

FileDateSize
device-2014-02-18-134423.png2014-02-18T07:46:56.000+000035747

Comments

  1. Martin N 2014-03-12

    This also affects 3.2.2. Doesn't show the default icon/appicon, when "icon" is not specified.
  2. Manuel Lehner 2015-07-07

    Please open source ti.cloudpush - would like to help here

JSON Source