Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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服务同步爱奥尼亚应用程序_Android_Ionic Framework_Badge - Fatal编程技术网

外部Android服务同步爱奥尼亚应用程序

外部Android服务同步爱奥尼亚应用程序,android,ionic-framework,badge,Android,Ionic Framework,Badge,我正在尝试获得一个离子应用程序,以获得启动应用程序图标上的通知徽章。 据我所知,如果ionic应用程序关闭(不是在后台),这是不可能的。因此,有人知道是否有可能创建一个android服务,我总是在后台运行,并同步我的ionic应用程序,更新图标徽章 提前谢谢你既然@Shiben问了,这就是我解决问题的方法 安装cordova插件firebase 转到并创建firebase项目(请参阅配置指南) -在app.component.ts中执行以下操作: export class MyApp { r

我正在尝试获得一个离子应用程序,以获得启动应用程序图标上的通知徽章。 据我所知,如果ionic应用程序关闭(不是在后台),这是不可能的。因此,有人知道是否有可能创建一个android服务,我总是在后台运行,并同步我的ionic应用程序,更新图标徽章


提前谢谢你

既然@Shiben问了,这就是我解决问题的方法

  • 安装cordova插件firebase

  • 转到并创建firebase项目(请参阅配置指南)

-在app.component.ts中执行以下操作:

export class MyApp {
rootPage:any = HomePage;
firebase : any;

constructor(public platform: Platform, 
                   public statusBar: StatusBar, 
                   public splashScreen: SplashScreen, 
                   private _firebase: Firebase,
                   public alertCtrl: AlertController) {

  platform.ready().then(() => {
  (your things)
  this.firebase = _firebase;
  this.initFirebase();
  this.firebase.setBadgeNumber(0);
 });
}
这是我的initFirebase():

-在yor index.html中插入如下内容(从firebase获得)


//初始化Firebase
变量配置={
apiKey:“你的钥匙”,
authDomain:“您的域”,
数据库url:“您的url”,
projectId:“你的项目”,
storageBucket:“你的storageBucket”,
messagingSenderId:“您的messageid”
};
firebase.initializeApp(配置);
我很久以前就这样做了,可能会有所改变。这可能是不推荐的,也可能不是最佳实践,但是,我希望它能让您朝着正确的方向前进

initFirebase(){

this.firebase.grantPermission();

this.firebase.onTokenRefresh()
  .subscribe((token: string) => localStorage.setItem("pushToken", token)) 

this.firebase.onNotificationOpen()
.subscribe((notification) => {
  let alert = this.alertCtrl.create({
    title: 'New Notification',
    subTitle: "Your notification",
    buttons:['OK']
  });
  alert.present();
});
}
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "your key",
    authDomain: "your domain",
    databaseURL: "your url",
    projectId: "your projid",
    storageBucket: "your storagebucket",
    messagingSenderId: "your messageid"
  };
firebase.initializeApp(config);
</script>