Android 平台中的推送通知

发布于 2024-08-03 09:45:00 字数 180 浏览 2 评论 0原文

我正在寻找编写一个从服务器接收推送警报的应用程序。我找到了几种方法来做到这一点。

  1. SMS - 拦截传入的 SMS 并从服务器发起拉取
  2. 定期轮询服务器

每个都有其自身的限制。短信-不保证到达时间。轮询可能会耗尽电池电量。

请问您有更好的建议吗?非常感谢。

I am looking to write an app that receives pushed alerts from a server. I found a couple of methods to do this.

  1. SMS - Intercept the incoming SMS and initiate a pull from the server
  2. Poll the server periodically

Each has its own limitations. SMS- no guarantee on arrival time. Poll may drain the battery.

Do you have a better suggestion please? Thanks very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(20

摇划花蜜的午后 2024-08-10 09:45:01

我对 Android 推送通知的理解/经验是:

  1. C2DM GCM - 如果您的目标 Android 平台是 2.2+,那么就选择它。需要注意的是,设备用户必须始终使用 Google 帐户登录才能获取消息。

  2. MQTT - 基于发布/订阅的方法,需要设备的主动连接,如果不合理实施,可能会耗尽电池。

  3. Deacon - 由于社区有限,从长远来看可能不太好支持。

编辑:2013 年 11 月 25 日添加

GCM -谷歌说...

对于 3.0 之前的设备,这要求用户在其移动设备上设置 Google 帐户。运行 Android 4.0.4 或更高版本的设备不需要 Google 帐户。*

My understanding/experience with Android push notification are:

  1. C2DM GCM - If your target android platform is 2.2+, then go for it. Just one catch, device users have to be always logged with a Google Account to get the messages.

  2. MQTT - Pub/Sub based approach, needs an active connection from device, may drain battery if not implemented sensibly.

  3. Deacon - May not be good in a long run due to limited community support.

Edit: Added on November 25, 2013

GCM - Google says...

For pre-3.0 devices, this requires users to set up their Google account on their mobile devices. A Google account is not a requirement on devices running Android 4.0.4 or higher.*

拿命拼未来 2024-08-10 09:45:01

Android 云到设备消息传递框架

重要提示:自 2012 年 6 月 26 日起,C2DM 已被正式弃用。 这意味着 C2DM 已停止接受新用户和配额请求。 C2DM 不会添加新功能。但是,使用 C2DM 的应用程序将继续运行。我们鼓励现有 C2DM 开发人员迁移到新版本的 C2DM,即 Google Cloud Messaging for Android (GCM)。有关更多信息,请参阅 C2DM 到 GCM 迁移文档。开发者必须使用GCM进行新的开发。

请检查以下链接:

http://developer.android.com/guide/google /gcm/index.html

Android Cloud to Device Messaging Framework

Important: C2DM has been officially deprecated as of June 26, 2012. This means that C2DM has stopped accepting new users and quota requests. No new features will be added to C2DM. However, apps using C2DM will continue to work. Existing C2DM developers are encouraged to migrate to the new version of C2DM, called Google Cloud Messaging for Android (GCM). See the C2DM-to-GCM Migration document for more information. Developers must use GCM for new development.

Kindly check the following link:

http://developer.android.com/guide/google/gcm/index.html

半世晨晓 2024-08-10 09:45:01

这里我写了一些关于如何从头开始获取 RegID 和通知的步骤

  1. 在 Google Cloud 上创建/注册应用程序
  2. 使用开发设置 Cloud SDK
  3. 配置 GCM 项目
  4. 获取设备注册 ID
  5. 发送推送通知
  6. 接收推送通知

您可以在下面的 URL 链接中找到完整的教程

Android 推送入门通知:最新 Google Cloud
消息传递 (GCM) - 分步完整教程

在此处输入图像描述

获取的代码片段注册 ID(推送通知的设备令牌)。

为 GCM 配置项目


更新 AndroidManifest 文件

为了在我们的项目中启用 GCM,我们需要在清单文件中添加一些权限
转到 AndroidManifest.xml 并添加以下代码
添加权限

<uses-permission android:name="android.permission.INTERNET”/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name=“.permission.RECEIVE" />
<uses-permission android:name=“<your_package_name_here>.permission.C2D_MESSAGE" />
<permission android:name=“<your_package_name_here>.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

添加 GCM 广播接收器声明

在应用程序标签中添加 GCM 广播接收器声明

<application
        <receiver
            android:name=".GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" ]]>
            <intent-filter]]>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="" />
            </intent-filter]]>

        </receiver]]>
     
<application/>

添加 GCM 服务声明

<application
     <service android:name=".GcmIntentService" />
<application/>

获取注册 ID(用于推送通知的设备令牌)

现在转到您的启动/启动活动

添加常量和类变量

private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
public static final String EXTRA_MESSAGE = "message";
public static final String PROPERTY_REG_ID = "registration_id";
private static final String PROPERTY_APP_VERSION = "appVersion";
private final static String TAG = "LaunchActivity";
protected String SENDER_ID = "Your_sender_id";
private GoogleCloudMessaging gcm =null;
private String regid = null;
private Context context= null;

更新OnCreate和OnResume方法

@Override
protected void onCreate(Bundle savedInstanceState)
{
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_launch);
     context = getApplicationContext();
         if (checkPlayServices()) 
     {
            gcm = GoogleCloudMessaging.getInstance(this);
            regid = getRegistrationId(context);

            if (regid.isEmpty())
            {
                registerInBackground();
            }
            else
            {
            Log.d(TAG, "No valid Google Play Services APK found.");
            }
      }
 }

@Override protected void onResume()
{
       super.onResume();       checkPlayServices();
}


# Implement GCM Required methods (Add below methods in LaunchActivity)

private boolean checkPlayServices() {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            } else {
                Log.d(TAG, "This device is not supported - Google Play Services.");
                finish();
            }
            return false;
        }
        return true;
 }

private String getRegistrationId(Context context) 
{
   final SharedPreferences prefs = getGCMPreferences(context);
   String registrationId = prefs.getString(PROPERTY_REG_ID, "");
   if (registrationId.isEmpty()) {
       Log.d(TAG, "Registration ID not found.");
       return "";
   }
   int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
   int currentVersion = getAppVersion(context);
   if (registeredVersion != currentVersion) {
        Log.d(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

private SharedPreferences getGCMPreferences(Context context) 
{
    return getSharedPreferences(LaunchActivity.class.getSimpleName(),
                Context.MODE_PRIVATE);
}

private static int getAppVersion(Context context) 
{
     try 
     {
         PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
      } 
      catch (NameNotFoundException e) 
      {
            throw new RuntimeException("Could not get package name: " + e);
      }
}


private void registerInBackground() 
{     new AsyncTask() {
     Override
     protected Object doInBackground(Object... params) 
     {
          String msg = "";
          try 
          {
               if (gcm == null) 
               {
                        gcm = GoogleCloudMessaging.getInstance(context);
               }
               regid = gcm.register(SENDER_ID);               Log.d(TAG, "########################################");
               Log.d(TAG, "Current Device's Registration ID is: "+msg);     
          } 
          catch (IOException ex) 
          {
              msg = "Error :" + ex.getMessage();
          }
          return null;
     }     protected void onPostExecute(Object result) 
     { //to do here };
  }.execute(null, null, null);
}

注意:请存储REGISTRATION_KEY,这对于向GCM发送PN消息很重要
还要记住,这对于所有设备来说都是唯一的,通过使用它,只有 GCM 才会发送推送通知。

接收推送通知

添加 GCM 广播接收器类

由于我们已经在清单文件中声明了“GcmBroadcastReceiver.java”,所以让我们创建这个类
以这种方式更新接收器类代码

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) 
    {        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
        Toast.makeText(context, “wow!! received new push notification", Toast.LENGTH_LONG).show();
    }
}

添加GCM服务类

由于我们已经在清单文件中声明了“GcmBroadcastReceiver.java”,所以让我们创建这个类
以这种方式更新接收器类代码

public class GcmIntentService extends IntentService
{     public static final int NOTIFICATION_ID = 1;     private NotificationManager mNotificationManager;     private final static String TAG = "GcmIntentService";     public GcmIntentService() {
     super("GcmIntentService");     
     }     @Override
     protected void onHandleIntent(Intent intent) {
          Bundle extras = intent.getExtras();
          Log.d(TAG, "Notification Data Json :" + extras.getString("message"));

          GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
          String messageType = gcm.getMessageType(intent);          if (!extras.isEmpty()) {          if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
               .equals(messageType)) {
               sendNotification("Send error: " + extras.toString());
          } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
          .equals(messageType)) {
          sendNotification("Deleted messages on server: "
          + extras.toString());          // If it's a regular GCM message, do some work.
          } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
          .equals(messageType)) {
          // This loop represents the service doing some work.
          for (int i = 0; i < 5; i++) {
               Log.d(TAG," Working... " + (i + 1) + "/5 @ "
               + SystemClock.elapsedRealtime());               try {
                    Thread.sleep(5000);
               } catch (InterruptedException e) {
               }
             }
             Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
             sendNotification(extras.getString("message"));
           }
        }        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
     }     // Put the message into a notification and post it.
     // This is just one simple example of what you might choose to do with
     // a GCM message.
     private void sendNotification(String msg) {          mNotificationManager = (NotificationManager) this
          .getSystemService(Context.NOTIFICATION_SERVICE);
          PendingIntent contentIntent = PendingIntent.getActivity(this, 0,          new Intent(this, LaunchActivity.class), 0);

          NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(          this)
          .setSmallIcon(R.drawable.icon)
          .setContentTitle("Ocutag Snap")
          .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
          .setContentText(msg)
          .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

          mBuilder.setContentIntent(contentIntent);          mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
     }
}

Here I have written few steps for How to Get RegID and Notification starting from scratch

  1. Create/Register App on Google Cloud
  2. Setup Cloud SDK with Development
  3. Configure project for GCM
  4. Get Device Registration ID
  5. Send Push Notifications
  6. Receive Push Notifications

You can find complete tutorial in below URL link

Getting Started with Android Push Notification : Latest Google Cloud
Messaging (GCM) - step by step complete tutorial

enter image description here

Code snip to get Registration ID (Device Token for Push Notification).

Configure project for GCM


Update AndroidManifest file

For enable GCM in our project we need to add few permission in our manifest file
Go to AndroidManifest.xml and add below code
Add Permission

<uses-permission android:name="android.permission.INTERNET”/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name=“.permission.RECEIVE" />
<uses-permission android:name=“<your_package_name_here>.permission.C2D_MESSAGE" />
<permission android:name=“<your_package_name_here>.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

Add GCM Broadcast Receiver declaration

add GCM Broadcast Receiver declaration in your application tag

<application
        <receiver
            android:name=".GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" ]]>
            <intent-filter]]>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="" />
            </intent-filter]]>

        </receiver]]>
     
<application/>

Add GCM Servie declaration

<application
     <service android:name=".GcmIntentService" />
<application/>

Get Registration ID (Device Token for Push Notification)

Now Go to your Launch/Splash Activity

Add Constants and Class Variables

private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
public static final String EXTRA_MESSAGE = "message";
public static final String PROPERTY_REG_ID = "registration_id";
private static final String PROPERTY_APP_VERSION = "appVersion";
private final static String TAG = "LaunchActivity";
protected String SENDER_ID = "Your_sender_id";
private GoogleCloudMessaging gcm =null;
private String regid = null;
private Context context= null;

Update OnCreate and OnResume methods

@Override
protected void onCreate(Bundle savedInstanceState)
{
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_launch);
     context = getApplicationContext();
         if (checkPlayServices()) 
     {
            gcm = GoogleCloudMessaging.getInstance(this);
            regid = getRegistrationId(context);

            if (regid.isEmpty())
            {
                registerInBackground();
            }
            else
            {
            Log.d(TAG, "No valid Google Play Services APK found.");
            }
      }
 }

@Override protected void onResume()
{
       super.onResume();       checkPlayServices();
}


# Implement GCM Required methods (Add below methods in LaunchActivity)

private boolean checkPlayServices() {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            } else {
                Log.d(TAG, "This device is not supported - Google Play Services.");
                finish();
            }
            return false;
        }
        return true;
 }

private String getRegistrationId(Context context) 
{
   final SharedPreferences prefs = getGCMPreferences(context);
   String registrationId = prefs.getString(PROPERTY_REG_ID, "");
   if (registrationId.isEmpty()) {
       Log.d(TAG, "Registration ID not found.");
       return "";
   }
   int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
   int currentVersion = getAppVersion(context);
   if (registeredVersion != currentVersion) {
        Log.d(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

private SharedPreferences getGCMPreferences(Context context) 
{
    return getSharedPreferences(LaunchActivity.class.getSimpleName(),
                Context.MODE_PRIVATE);
}

private static int getAppVersion(Context context) 
{
     try 
     {
         PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
      } 
      catch (NameNotFoundException e) 
      {
            throw new RuntimeException("Could not get package name: " + e);
      }
}


private void registerInBackground() 
{     new AsyncTask() {
     Override
     protected Object doInBackground(Object... params) 
     {
          String msg = "";
          try 
          {
               if (gcm == null) 
               {
                        gcm = GoogleCloudMessaging.getInstance(context);
               }
               regid = gcm.register(SENDER_ID);               Log.d(TAG, "########################################");
               Log.d(TAG, "Current Device's Registration ID is: "+msg);     
          } 
          catch (IOException ex) 
          {
              msg = "Error :" + ex.getMessage();
          }
          return null;
     }     protected void onPostExecute(Object result) 
     { //to do here };
  }.execute(null, null, null);
}

Note : please store REGISTRATION_KEY, it is important for sending PN Message to GCM
also keep in mine this will be unique for all device, by using this only GCM will send Push Notification.

Receive Push Notifications

Add GCM Broadcast Receiver Class

As we have already declared “GcmBroadcastReceiver.java” in our Manifest file, So lets create this class
update receiver class code this way

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) 
    {        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
        Toast.makeText(context, “wow!! received new push notification", Toast.LENGTH_LONG).show();
    }
}

Add GCM Service Class

As we have already declared “GcmBroadcastReceiver.java” in our Manifest file, So lets create this class
update receiver class code this way

public class GcmIntentService extends IntentService
{     public static final int NOTIFICATION_ID = 1;     private NotificationManager mNotificationManager;     private final static String TAG = "GcmIntentService";     public GcmIntentService() {
     super("GcmIntentService");     
     }     @Override
     protected void onHandleIntent(Intent intent) {
          Bundle extras = intent.getExtras();
          Log.d(TAG, "Notification Data Json :" + extras.getString("message"));

          GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
          String messageType = gcm.getMessageType(intent);          if (!extras.isEmpty()) {          if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
               .equals(messageType)) {
               sendNotification("Send error: " + extras.toString());
          } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
          .equals(messageType)) {
          sendNotification("Deleted messages on server: "
          + extras.toString());          // If it's a regular GCM message, do some work.
          } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
          .equals(messageType)) {
          // This loop represents the service doing some work.
          for (int i = 0; i < 5; i++) {
               Log.d(TAG," Working... " + (i + 1) + "/5 @ "
               + SystemClock.elapsedRealtime());               try {
                    Thread.sleep(5000);
               } catch (InterruptedException e) {
               }
             }
             Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
             sendNotification(extras.getString("message"));
           }
        }        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
     }     // Put the message into a notification and post it.
     // This is just one simple example of what you might choose to do with
     // a GCM message.
     private void sendNotification(String msg) {          mNotificationManager = (NotificationManager) this
          .getSystemService(Context.NOTIFICATION_SERVICE);
          PendingIntent contentIntent = PendingIntent.getActivity(this, 0,          new Intent(this, LaunchActivity.class), 0);

          NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(          this)
          .setSmallIcon(R.drawable.icon)
          .setContentTitle("Ocutag Snap")
          .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
          .setContentText(msg)
          .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

          mBuilder.setContentIntent(contentIntent);          mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
     }
}
一抹微笑 2024-08-10 09:45:01

有一项新的开源项目正在开发一个 Java 库,用于基于 Meteor Web 服务器在 Android 上推送通知。您可以在 Deacon 项目博客 中查看,您可以在其中找到 Meteor 和项目 GitHub 存储库的链接。我们需要开发人员,所以请传播出去!

There is a new open-source effort to develop a Java library for push notifications on Android based on the Meteor web server. You can check it out at the Deacon Project Blog, where you'll find links to Meteor and the project's GitHub repository. We need developers, so please spread the word!

君勿笑 2024-08-10 09:45:01

您可以使用 Xtify (http://developer.xtify.com) - 他们有一个可以使用的推送通知网络服务与他们的 SDK。它是免费的,到目前为止,它对我来说非常有效。

You can use Xtify (http://developer.xtify.com) - they have a push notifications webservice that works with their SDK. it's free and so far, it's worked really well for me.

空心↖ 2024-08-10 09:45:01

或者....

3) 保持与服务器的连接,每隔几分钟发送一次 keep-alive,服务器可以立即推送消息。这就是 Gmail、Google Talk 等的工作原理。

or....

3) Keep a connection to the server, send keep-alives every few minutes, and the server can push messages instantly. This is how Gmail, Google Talk, etc. works.

远山浅 2024-08-10 09:45:01

我建议使用 GCM - Android 版 Google 云消息传递
它是免费的,对于简单的用途来说,它应该非常容易。

但是,它需要维护一个第三端服务器来代表您发送通知。
如果你想避免,有一些非常好的Android推送通知服务的工业解决方案:

  • Urban Airship - 免费高达1M每月通知数,之后按 1000 条通知收费
  • PushApps - 每月 100 万条通知免费,并且无限次通知每月 19.99 美元
  • PushWoosh - 100 万台设备免费,高级套餐 39 欧元起

免责声明 - 我在 PushApps 工作,并且在我的应用程序中使用他们的产品已有一年多了。

I recommend using GCM - Google Cloud Messaging for Android
It's free, and for simple uses it's should be very easy.

However it requires to maintain a 3rd side server to send the notifications on your behalf.
If you want to avoid that there are some very good industrial solutions for Android push notifications service:

  • Urban Airship - free up to 1M notifications per month, afterwards you are charged per 1000 notifications
  • PushApps - free for 1M notifications per month, and unlimited notifications for 19.99 per month
  • PushWoosh - free for 1M devices, premium plans are from 39 EURO

Diclaimer - I work in PushApps and also use their product in my applications for over a year now.

梦里兽 2024-08-10 09:45:01

截至 2016 年 5 月 18 日,Firebase 是 Google 为移动开发者提供的统一平台,包括推送通知。

As of 18/05/2016 Firebase is Google's unified platform for mobile developers including push notifications.

原谅我要高飞 2024-08-10 09:45:01

恐怕您已经找到了这两种可能的方法。 Google 至少在最初打算实现一个 GChat API,您可以使用它来实现推/拉。遗憾的是,该库被 Android 1.0 删除了。

I'm afraid you've found both possible methods. Google was, at least initially, going to implement a GChat api you could use for a push/pull implementation. Sadly, that library was cut by Android 1.0.

浅浅淡淡 2024-08-10 09:45:01

我不知道这是否还有用。我通过 http://www.pushlets.com/ 的 java 库实现了类似的目标,尽管

在服务不会阻止 android 关闭它并杀死侦听器线程。

I dont know if this is still useful. I achieved something like this with a java library at http://www.pushlets.com/

Althoug doing it in a service won't prevent android from shutting it down an killing the listener thread.

春夜浅 2024-08-10 09:45:01

Google C2DM 现在已弃用,为此,您必须使用新服务 GCM(Google Cloud Messaging)。有关文档,请参阅 http://developer.android.com/guide/google/gcm /gs.html

Google C2DM is depreciated now, for that, you have o use the new service GCM (Google Cloud Messaging). For documantation, see http://developer.android.com/guide/google/gcm/gs.html

最近可好 2024-08-10 09:45:01

C2DM:您的应用程序用户必须拥有 Gmail 帐户。

MQTT:当您的连接达到1024时,它将停止工作,因为它使用了linux的“选择模型”。

Android 有一个免费的推送服务和 api,你可以尝试一下:http://push-notification.org

C2DM: your app-users must have the gmail account.

MQTT: when your connection reached to 1024, it will stop work because of it used "select model " of linux.

There is a free push service and api for android, you can try it: http://push-notification.org

铜锣湾横着走 2024-08-10 09:45:01

免费且简单的方法:

如果您的目标用户群不大(小于1000)并且您想要开始免费服务,那么Airbop是最好、最方便的。

Airbop 网站
它通过其 API 使用 Google Cloud Messaging 服务,并提供良好的性能。我已经将它用于我的两个项目,并且很容易实现。

像 Urbanship 这样的服务非常出色,但提供了整个部署堆栈,而不仅仅是推送通知。

如果您的目标只是推送服务,Airbop 就可以正常工作。

我没有使用过 Pushwoosh,但也是一个不错的选择。它允许免费推送到 1,000,000 台设备

Free and easy method:

If your target user base is not large(less than a 1000) and you want a free service to start with, then Airbop is the best and most convenient.

Airbop Website
It uses Google Cloud Messaging service through its API and is provides a good performance. i have used it for two of my projects and it was easy implementing it.

Services like and Urbanship are excellent but provide an entire deployment stack and not just the push notifications thing.

If only push service is your target, Airbop will work fine.

I haven't used Pushwoosh, but is also a great choice. It allows push to 1,000,000 devices for free

坦然微笑 2024-08-10 09:45:01

我建议同时使用 SMS 和 HTTP。如果用户未登录,请向其手机发送短信以通知他们有一条消息正在等待。

这就是爱立信实验室服务的工作原理:https://labs.ericsson.com/apis /mobile-java-push/

如果您自己实现这一点,棘手的部分是在用户看不到它的情况下删除传入的短信。或者,如果他们在你的案例中看到这一点也没关系。

看起来这样有效:
使用 BroadCastReceiver - Android 删除短信

是的,编写这样的代码可能很危险,您可以可能会毁掉某人的生活,因为您的应用程序删除了不应删除的短信。

I would suggest using both SMS and HTTP. If the user is not signed in send their phone an SMS to notify them there's a message waiting.

That's how this Ericsson Labs service works: https://labs.ericsson.com/apis/mobile-java-push/

If you implement this yourself the tricky part is deleting the incoming SMS without the user seeing it. Or maybe it's ok if they see it in your case.

Looks like this works:
Deleting SMS Using BroadCastReceiver - Android

Yes, writing code like this can be dangerous and you can potentially ruin someone's life because your application deleted an SMS it shouldn't have.

时光是把杀猪刀 2024-08-10 09:45:01

您可以使用 Google Cloud Messaging 或 GCM,它免费且易于使用。您还可以使用第三方推送服务器,例如 PushWoosh,这为您提供了更大的灵活性

You can use Google Cloud Messaging or GCM, it's free and easy to use. Also you can use third party push servers like PushWoosh which gives you more flexibility

淡淡的优雅 2024-08-10 09:45:01

有很多第三方服务器,例如 Urban Airship、Xtify、Mainline, ... 不仅可以在 Android 上发送,还可以在 iOs、Windows Phone 上发送 ...

There's a lot a third party servers like Urban Airship, Xtify, Mainline, ... whiches allow send not only on Android, but also on iOs, Windows Phone ...

习ぎ惯性依靠 2024-08-10 09:45:01

Firebase Cloud Messaging (FCM) 是新版本GCM。 FCM 是一种跨平台消息传递解决方案,可让您安全且免费地发送消息。继承 GCM 的中央基础设施,在 Android、iOS、Web (javascript)、Unity 和 C++ 上可靠地传递消息。

截至 2018 年 4 月 10 日,Google 已拒绝 GCM。 GCM 服务器和客户端 API 已弃用,并将于 2019 年 4 月 11 日删除。Google 建议将 GCM 应用程序迁移到 Firebase Cloud Messaging (FCM),它继承了可靠且可扩展的 GCM 基础设施。

资源

Firebase Cloud Messaging (FCM) is the new version of GCM. FCM is a cross-platform messaging solution that allows you to send messages securely and for free. Inherits GCM's central infrastructure to deliver messages reliably on Android, iOS, Web (javascript), Unity and C ++.

As of April 10, 2018, Google has disapproved of GCM. The GCM server and client APIs are deprecated and will be removed on April 11, 2019. Google recommends migrating GCM applications to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure.

Resource

一身骄傲 2024-08-10 09:45:01

您可以使用 Pusher

它是一项托管服务,可以非常轻松地将实时数据和功能添加到网络和移动应用程序。
Pusher 提供了可集成到所有主要运行时和框架中的库。

服务器上的PHP、Ruby、Python、Java、.NET、Go 和 Node
客户端上的 JavaScript、Objective-C (iOS) 和 Java (Android)

You can use Pusher

It's a hosted service that makes it super-easy to add real-time data and functionality to web and mobile applications.
Pusher offers libraries to integrate into all the main runtimes and frameworks.

PHP, Ruby, Python, Java, .NET, Go and Node on the server
JavaScript, Objective-C (iOS) and Java (Android) on the client.

一影成城 2024-08-10 09:45:00

Google 的官方答案是Android 云到设备消息传递框架(已弃用) Google 云消息(已弃用) Firebase Cloud Messaging

它适用于 Android >= 2.2(在具有 Play 商店的手机上) 。

Google's official answer is the Android Cloud to Device Messaging Framework (deprecated) Google Cloud Messaging(deprecated) Firebase Cloud Messaging

It will work on Android >= 2.2 (on phones that have the Play Store).

流绪微梦 2024-08-10 09:45:00

(从我对类似问题给出的答案中交叉发布 - Android 是否支持近乎实时的推送通知? )

我最近开始使用 MQTT http:// mqtt.org for Android 作为做这类事情的一种方式(即不是短信而是数据驱动的推送通知,几乎立即消息传递,而不是轮询等)

我有一篇博客文章,其中包含背景信息如果有帮助

http://dalelane.co.uk/blog/?p=938

(注:MQTT 是一项 IBM 技术,我应该指出我为 IBM 工作。)

(cross-posting from an answer I gave to a similar question - Does Android support near real time push notification? )

I recently started playing with MQTT http://mqtt.org for Android as a way of doing this sort of thing (i.e. push notification that is not SMS but data driven, almost immediate message delivery, not polling, etc.)

I have a blog post with background information on this in case it's helpful

http://dalelane.co.uk/blog/?p=938

(Note: MQTT is an IBM technology, and I should point out that I work for IBM.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文