【发布时间】:2016-06-12 17:41:33
【问题描述】:
我正在做一个涉及 Web 界面的小项目,该界面可以将信息发送到我的 android 应用程序,该应用程序将显示推送通知等信息。
但事情是这样的,我对如何做到这一点有点困惑。至于我必须采取什么步骤。
所以我有一个 HTML 格式的 Web 界面,其中有一个用于通知标题、内容和提交按钮的文本字段。我希望当用户单击提交按钮时,网页会将标题和内容字段中的文本发送到我的 android 应用程序,然后应用程序会将它们显示为推送通知。
到目前为止,在应用程序上,当您单击设备上的按钮时,它只会在操作栏上显示通知。这非常适合测试,但您最好通过 Web 界面编写通知。
我的应用测试推送通知代码:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
// TODO: Make this accessible to exterior projects, such as web interface.
Notification notification = new Notification.Builder(MainActivity.this)
.setTicker("Notification")
.setContentTitle("Important Message")
.setContentText("This is an example of a push notification using a Navigation Manager")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)
.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nManager.notify(0, notification);
}
});
如果有人能帮我一把,将不胜感激。
【问题讨论】:
-
网页界面可以在桌面或移动设备上使用
-
如果它可以在移动浏览器上运行,那么你可以在 上搜索,这样你就不必实现 GCM
标签: java android web-services web push-notification