Factory, $rootScope and onNotificationGCM handler function out of factory

I create a factory to manage push plugin and I create onNotificationGCM handler out of factory.

angular.module('mega.pushnotification', ['ionic', 'ngResource'])

.factory('PushProcessingService', function ($rootScope, $ionicPlatform, $cordovaDevice, $cordovaPush, $cordovaDialogs, $cordovaMedia, $cordovaStatusbar, $cordovaToast, $http) {
....
});

// ALL GCM notifications come through here. 
    function onNotificationGCM(e) {
....
};

But I need access to $rootScope or $scope from onNotificationGCM. How to made this?

What about a provider? Try something like this

.provider('myProvider1', function() {
var cfg = "";
    
    return {
        // function for use in config as myProvider1Provider
        setConfig: function (value) {
            cfg = value;
        },
        
        // use these in controller
        $get: function ($http, $q, $scope) {
            return {
                myFunction1: function() {
                    return true;
                },
                myFunction2: function() {
                    return true;
                }
            }
        }
})

It is a bit tricky to get hold of those from an out-of-scope function such as the onNotificationGCM.
One good solution is offered here: http://intown.biz/2014/04/11/android-notifications/
(look at code from line 60…)