gluon Mobile LocalNotificationsServices.class不工作 [英] gluon Mobile LocalNotificationsServices.class Not working

查看:149
本文介绍了gluon Mobile LocalNotificationsServices.class不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我是使用javafx进行Android开发的新手。我试图使用 javafx (javafxports和gluon Mobile)在Android上创建推送通知。
我的问题是推送通知没有像我预期的那样显示。
我从

Hi guys Am new to Android development using javafx.
Am trying to create push notification on android using javafx (javafxports and gluon Mobile ) .
My problem is that push-notification is not displaying as I did Expected.
I got this idea from

http://gluonhq.com/products/mobile/charm-down/
http://docs.gluonhq.com/charm/javadoc/4.2.0/com/gluonhq/charm/down/plugins/LocalNotificationsService.html#getNotifications--


这里是gradle.build文件,如下所示。

here's the gradle.build file Below.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.2.0'

}
}

apply plugin: 'org.javafxports.jfxmobile'

  repositories 
  {
  jcenter()
  maven 
  {
  url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
  }
  }

  mainClassName = 'com.sample.Main'

  dependencies 
  {
  compile 'com.gluonhq:charm:4.2.0'
  compileNoRetrolambda 'com.jfoenix:jfoenix:1.0.0'
  //compile files('lib/jfoenix-0.0.0-SNAPSHOT-retrolambda.jar')
  }

  jfxmobile
  {
  downConfig 
  {
  version = '3.2.4'
    // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
  plugins 'display', 'lifecycle', 'local-notifications', 'runtime-args', 'statusbar', 'storage'
  }
  android {
  manifest = 'src/android/AndroidManifest.xml'
  }
  ios
  {
  infoPList = file('src/ios/Default-Info.plist')
  forceLinkClasses = [
            'com.gluonhq.**.*',
            'javax.annotations.**.*',
            'javax.inject.**.*',
            'javax.json.**.*',
            'org.glassfish.json.**.*'
    ]
   }
   }


这是我尝试创建推送Nofification <的主要程序/ strong>
使用下面的LocalNotificationServices.class。


Here's the main program in which I have tried to create push Nofification using LocalNotificationServices.class below.

package com.sample;

import com.gluonhq.charm.down.Services;
import java.time.ZonedDateTime;
import com.gluonhq.charm.down.plugins.DisplayService;
import com.gluonhq.charm.down.plugins.LocalNotificationsService;
import com.gluonhq.charm.down.plugins.Notification;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.stage.Screen;
import javafx.stage.Stage;

//import android.database.sqlite.*;
/**
* Created by Guru on 1/30/2017.
*/
public class Main extends Application  {
@FXML Button schedule;
public static void main(String args[])
{

    launch();
}


public static String screen1ID = "Home";
public static String screen1File = "Home.fxml";
public static String screen2ID = "screen2";
public static String screen2File = "Next1.fxml";

static Group grp;
static Next nxt;
Rectangle2D visual;
ScreensController control;
Next backup;
public void init()
{
}
@Override
public void start(Stage primaryStage) throws Exception {
    try{


        Rectangle2D visual=Screen.getPrimary().getVisualBounds();
        ScreensController mainContainer = new ScreensController();

        mainContainer.loadScreen(Main.screen1ID, Main.screen1File);
     backup=  (Next) mainContainer.loadScreen(Main.screen2ID, Main.screen2File);

        Group root = new Group();
        root.getChildren().addAll(mainContainer);
        Scene scene=null;
         control=mainContainer;

         if("android".equals(System.getProperty("javafx.platform")))
         {
         scene = new Scene(root,visual.getWidth(),visual.getHeight());

             try {

     String notificationId = "abcd1234";
     Services.get(LocalNotificationsService.class).ifPresent(service -> {
     service.getNotifications().add(
     new Notification(notificationId, "Sample Notification Text",
     ZonedDateTime.now().plusSeconds(20), () -> {
     Alert alert = 
     new Alert(AlertType.INFORMATION, "You have been notified!");
                  Platform.runLater(() -> alert.showAndWait());
          }));
        });
     }
             catch(Exception e)
             {
                 e.printStackTrace();
             }
         }
         else
             scene =new Scene(root);
         primaryStage.setScene(scene);
        primaryStage.show();
         }
        catch (Exception i)
        {
    i.printStackTrace();
     }
      }


 }


应用程序正常但显示推送通知

我不知道我的代码错误

我在这里附上 AndroidManifest.xml 文件以下..


The App Works Fine but the push Notification is shown .
I dont know what's Wrong with my Code.
And I here I have Attached the AndroidManifest.xml file Below..

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sample" android:versionCode="1" android:versionName="1.0">
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21"/>
<application android:label="Sample" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/ic_launcher">
 <activity android:name="javafxports.android.FXActivity" android:label="Sample" android:configChanges="orientation|screenSize">
 <meta-data android:name="main.class" android:value="com.sample.Main"/>
 <meta-data android:name="debug.port" android:value="0"/>
 <intent-filter>
 <action android:name="android.intent.action.MAIN"/>
 <category android:name="android.intent.category.LAUNCHER"/>
 </intent-filter>
 </activity>
 </application>
 </manifest>


一切看起来都不错,但推送通知不起作用。

我不知道我错过了什么!


Everything looks fine to Me,but push Notification's not working .
I don't know what I have Missed!

推荐答案

除了代码中对服务的调用外,还有Charm Down插件对于本地通知需要一些额外的配置,因为您可以在文档

Besides the call to the service in your code, the Charm Down plugin for local notifications requires some additional configuration, as you can read in the documentation you have linked.

在您的AndroidManifest文件中,您遗漏了一些内容:

In your AndroidManifest file you are missing a few things:


  • 使用SingleTop启动模式

  • 添加NotificationActivity

  • 添加AlarmReceiver

像这样:

<manifest ...>
...
<application ...>
  <activity android:name="javafxports.android.FXActivity"
            android:label="Sample"
            android:launchMode="singleTop"
            android:configChanges="orientation|screenSize">
    <meta-data android:name="main.class" android:value="com.sample.Main"/>
    ...
  </activity>
  ...
  <activity android:name="com.gluonhq.impl.charm.down.plugins.android.NotificationActivity"
            android:parentActivityName="javafxports.android.FXActivity">
        <meta-data android:name="android.support.PARENT_ACTIVITY" 
                   android:value="javafxports.android.FXActivity"/>
  </activity>
  <receiver android:name="com.gluonhq.impl.charm.down.plugins.android.AlarmReceiver" />
</application>

如您所见,插件隐藏了Android实现,因此您不需要使用Android API。 iOS也是如此。到目前为止,您需要做的就是更新清单。

As you can see, the plugin hides from you the Android implementation, so you don't need to use Android APIs. The same goes for iOS. So far, all you need to do is take care of updating your manifest.

这篇关于gluon Mobile LocalNotificationsServices.class不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆