想获得新的手机后一个通知,如果我的话preSS博客任何新的职位? [英] Want to get a notification on mobile of new post if any new post on my wordpress blog?

查看:80
本文介绍了想获得新的手机后一个通知,如果我的话preSS博客任何新的职位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用的WebView创建 Android应用


  

我想告诉我的用户(谁安装我的Andr​​oid应用程序)的新博客文章的通知。


  
  

在上通知URL用户点击应当网页视图中打开。


我试着喜欢这个教程。

  mNotificationManager =
        (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//设置为通知的ID,因此它可以被更新
INT notifyID = 1;
mNotifyBuilder =新NotificationCompat.Builder(本)
    .setContentTitle(新邮件)
    .setContentText(你收到的新邮件。)
    .setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
//循环处理数据,然后开始通知用户
...
    mNotifyBuilder.setContentText(currentText)
        .setNumber(++ numMessages);
    //因为ID保持不变,现有的通知
    //更新。
    mNotificationManager.notify(
            notifyID,
            mNotifyBuilder.build());


  

但我是新手,这是不是在所有的工作。


也试过在这code保护无效的onCreate(捆绑savedInstanceState){

 意图notificationIntent =新意图(背景下,yourwebviewactivity.class);
的PendingIntent contentIntent = PendingIntent.getActivity(上下文,0,notificationIntent,0); NotificationManager notificationManager =(NotificationManager)上下文
            .getSystemService(Context.NOTIFICATION_SERVICE); 通知的NotI =新NotificationCompat.Builder(上下文)
                    .setSmallIcon(icon_small)
                    .setTicker(股票信息)
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis的())
                    .setContentTitle(题)
                    .setContentText(信息)
                    .setContentIntent(co​​ntentIntent)
                    //最多三个动作按钮可以添加
                    .setAutoCancel(真).build();
notificationManager.notify(notifyID,NotI位);


解决方案

您需要设置通知意向活动这样的:

 意图notificationIntent =新意图(背景下,yourwebviewactivity.class);
的PendingIntent contentIntent = PendingIntent.getActivity(上下文,0,notificationIntent,0); NotificationManager notificationManager =(NotificationManager)上下文
            .getSystemService(Context.NOTIFICATION_SERVICE); 通知的NotI =新NotificationCompat.Builder(上下文)
                    .setSmallIcon(icon_small)
                    .setTicker(股票信息)
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis的())
                    .setContentTitle(题)
                    .setContentText(信息)
                    .setContentIntent(co​​ntentIntent)
                    //最多三个动作按钮可以添加
                    .setAutoCancel(真).build();
notificationManager.notify(notifyID,NotI位);

不要忘记注册您的WebView 活动的manifest.xml

有关更多信息,请访问: http://developer.android。 COM /引导/主题/ UI /通知者/ notifications.html

I have created a android app using webview.

I want to show my users (who has installed my android app ) a notification of new blog posts.

When user click on that notification Url should be opened in webview.

I tried like this tutorial.

mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
int notifyID = 1;
mNotifyBuilder = new NotificationCompat.Builder(this)
    .setContentTitle("New Message")
    .setContentText("You've received new messages.")
    .setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
// Start of a loop that processes data and then notifies the user
...
    mNotifyBuilder.setContentText(currentText)
        .setNumber(++numMessages);
    // Because the ID remains unchanged, the existing notification is
    // updated.
    mNotificationManager.notify(
            notifyID,
            mNotifyBuilder.build());

But i'm newbie, this is not at all working

Also tried this code in protected void onCreate(Bundle savedInstanceState) {

Intent notificationIntent = new Intent(context, yourwebviewactivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

 NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

 Notification noti = new NotificationCompat.Builder(context)
                    .setSmallIcon(icon_small)
                    .setTicker("ticker message")
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis())
                    .setContentTitle("title")
                    .setContentText("message")
                    .setContentIntent(contentIntent)
                    //At most three action buttons can be added
                    .setAutoCancel(true).build();
notificationManager.notify(notifyID, noti);

解决方案

You need to set Notification Intent Activity like:

Intent notificationIntent = new Intent(context, yourwebviewactivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

 NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

 Notification noti = new NotificationCompat.Builder(context)
                    .setSmallIcon(icon_small)
                    .setTicker("ticker message")
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis())
                    .setContentTitle("title")
                    .setContentText("message")
                    .setContentIntent(contentIntent)
                    //At most three action buttons can be added
                    .setAutoCancel(true).build();
notificationManager.notify(notifyID, noti);

Do not forget to Register your webview Activity in manifest.xml

For more information go to: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

这篇关于想获得新的手机后一个通知,如果我的话preSS博客任何新的职位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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