Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android IBM Mobilefirst 7.1 PushNotifications:无法从后台检索到前台的通知文本_Android_Push Notification_Ibm Mobilefirst - Fatal编程技术网

Android IBM Mobilefirst 7.1 PushNotifications:无法从后台检索到前台的通知文本

Android IBM Mobilefirst 7.1 PushNotifications:无法从后台检索到前台的通知文本,android,push-notification,ibm-mobilefirst,Android,Push Notification,Ibm Mobilefirst,我们在MobileFirst应用程序中集成了基于标签的通知和广播通知。我们可以在应用程序打开并且用户能够看到通知文本时发送通知。但是,当用户杀死应用程序,通知到达通知面板时:用户可以单击通知并打开应用程序,但不会显示通知文本 请查找以下代码: /* TagBased and Broadcast Notification Code Start */ var chkHolder; function suborunsub(chkbxFlag){ console.log('The value of ch

我们在MobileFirst应用程序中集成了基于标签的通知和广播通知。我们可以在应用程序打开并且用户能够看到通知文本时发送通知。但是,当用户杀死应用程序,通知到达通知面板时:用户可以单击通知并打开应用程序,但不会显示通知文本

请查找以下代码:

/* TagBased and Broadcast Notification Code Start */
var chkHolder;
function suborunsub(chkbxFlag){
console.log('The value of checkbox flag is:'+chkbxFlag);
var checkBox;
if(chkbxFlag=='TG1') {
    chkHolder = "TAG1";
    checkBox = document.getElementById("SUBTG1").checked;
    console.log('The checkbox value is:'+checkBox);
    if(checkBox) {
        subscribeToNotifTag('TAG1');
    } else {
        unsubscribeFromNotifTag('TAG1');
    }
} else if(chkbxFlag=='TG2') {
    chkHolder = "TAG 2";
    checkBox = document.getElementById("SUBTG2").checked;
    console.log('The checkbox value is:'+checkBox);
    if(checkBox) {

        subscribeToNotifTag('TAG2');
    } else {
        unsubscribeFromNotifTag('TAG2');
    }
} 
//---------------------------- Check if push support is available-----------
function isPushSupported() {
var isSupported = false;
if (WL.Client.Push){
    isSupported = WL.Client.Push.isPushSupported();
}   
WL.SimpleDialog.show("Alert", JSON.stringify(isSupported), [ {
    text : 'Close',
    handler : function() {}
  }
]);
}
// --------------------------------- Subscribe to tag --------------------

function subscribeToNotifTag(nTag) {
  WL.Client.Push.subscribeTag(nTag, {
        onSuccess: subscribeTagSuccess,
        onFailure: subscribeTagFailure
    });
}

function subscribeTagSuccess() {
    WL.SimpleDialog.show("Alert", "Subscribed to : "+chkHolder, [ {
    text : 'Close',
    handler : function() {}
  }
  ]);
}

function subscribeTagFailure() {
WL.SimpleDialog.show("Alert", "Failed to subscribe : "+chkHolder, [ {
    text : 'Close',
    handler : function() {}
  }
  ]);
}

// ------------------------------- Unsubscribe from tag --------------------

function unsubscribeFromNotifTag(nTag) {
WL.Client.Push.unsubscribeTag(nTag, {
        onSuccess: unsubscribeTagSuccess,
        onFailure: unsubscribeTagFailure
    });
}
function unsubscribeTagSuccess() {
WL.SimpleDialog.show("Alert", "Unsubscribed to : "+chkHolder, [ {
    text : 'Close',
    handler : function() {}
  }
  ]);
}

function unsubscribeTagFailure() {
WL.SimpleDialog.show("Alert", "Failed to unsubscribe : "+chkHolder, [ {
    text : 'Close',
    handler : function() {}
  }
  ]);
}

//------------------------------- Handle received notification -----------
WL.Client.Push.onMessage = function (props) {
if(WL.StaticAppProps.ENVIRONMENT=='iphone') {
WL.SimpleDialog.show("Alert", ""  + JSON.stringify(props.alert.body), [ {
    text : 'Close',
    handler : function() {}
}]);
}else if(WL.StaticAppProps.ENVIRONMENT=='android') {
    WL.SimpleDialog.show("Alert", ""  + JSON.stringify(props.alert), [ {
        text : 'Close',
        handler : function() {}
    }]);
    }
};
/* TagBased and Broadcast Notification Code End */
AndroidManifest.xml

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myAPP" android:versionCode="6" android:versionName="8.2">  
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21"/>  
<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/>  
<uses-permission android:name="android.permission.INTERNET"/>  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
<!-- Push permissions -->  
<permission android:name="com.myAPP.permission.C2D_MESSAGE" android:protectionLevel="signature"/>  
<uses-permission android:name="com.myAPP.permission.C2D_MESSAGE"/>  
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>  
<uses-permission android:name="android.permission.WAKE_LOCK"/>  
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>  
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>  
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>  
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
<uses-permission android:name="android.permission.READ_CALENDAR"/>  
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>  
<application android:label="@string/app_name"  android:icon="@drawable/icon"> 
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBHvtzEPwG4DYTG9Zsvijz9mRIC53ehleU"/>  
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>  
    <activity android:name=".myAPP" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"> 
        <intent-filter> 
            <action android:name="android.intent.action.MAIN"/>  
            <category android:name="android.intent.category.LAUNCHER"/> 
        </intent-filter>  
        <intent-filter> 
            <action android:name="com.myAPP.myAPP.NOTIFICATION"/>  
            <category android:name="android.intent.category.DEFAULT"/> 
        </intent-filter> 
    </activity>  
    <activity android:name=".MGMapFragment" android:theme="@style/Theme.MGMapTheme"/>  
    <activity android:name=".MGMultiMapFragment" android:theme="@style/Theme.MGMapTheme"/>  
    <activity android:name=".MGPickerMapFragment" android:theme="@style/Theme.MGPckrTheme"/>  
    <!-- Preference Activity  -->  
    <activity android:name="com.worklight.common.WLSettingActivity" android:label="Worklight Settings"/>  
    <!-- UI Activity for displaying native dialogs  -->  
    <activity android:name="com.worklight.wlclient.ui.UIActivity"/>  
    <!-- Push service  -->  
    <!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver 
        It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->  
    <service android:name=".GCMIntentService"/>  
    <service android:name=".ForegroundService"/>  
    <!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->  
    <receiver android:name="com.worklight.androidgap.push.WLBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
        <!-- Receive the actual message -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>  
            <category android:name="com.myAPP"/> 
        </intent-filter>  
        <!-- Receive the registration id -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>  
            <category android:name="com.myAPP"/> 
        </intent-filter> 
    </receiver> 
   </application> 
 </manifest>

我尝试过使用示例应用程序附带的默认代码,效果很好。但是使用这个“WL.StaticAppProps.ENVIRONMENT”的原因是我们只想向用户显示通知文本。有没有最好的方法只向用户显示通知文本

“只是通知文本”是什么意思?这与默认通知有何不同?示例应用程序显示了如何访问通知对象并显示有效负载和道具。分别地

function pushNotificationReceived(props, payload) {

    WL.SimpleDialog.show("Push Notifications", "Provider notification data: " + JSON.stringify(props), [ {
        text : 'Close',
        handler : function() {
            WL.SimpleDialog.show("Push Notifications", "Application notification data: " + JSON.stringify(payload), [ {
                text : 'Close',
                handler : function() {}
              }]);      
        }
    }]);
}

无论应用是关闭还是打开,都会到达main.js文件中的相同代码路径;因此,问题是设置问题。可能在AndroidManifest.xml中-您可以添加它吗?你有什么改变吗?串?名称?应用程序已关闭,并且我们尚未更改清单文件中的任何字符串或名称。请说明您的确切版本号。您是否检查了示例应用程序?它也不工作吗?版本号:7.1.0.0-MFPF-IF201512191535。我已经在示例应用程序上试用过,效果很好。就连我也比较了两个android manifest.xml文件,除了一些额外的活动之外没有区别。删除代码中的“WL.StaticAppProps.ENVIRONMENT”条件检查,然后重试。当我们使用“+JSON.stringify(props)”时,它会将通知作为“提供者通知数据:{“警报”:测试,“徽章”:1,“声音”:null,“优先级”“:0}”。因此,在本文中,我们只想向用户显示“警报”:test。因此,我们将其自定义为“+JSON.stringify(props.alert)”。