1

Phonegap と jQuery Mobile を使用して Android 用のアプリケーションを構築しています。プッシュ通知を実装したいのですが、次のような方法が見つかりました: Urban-Air & Phonegap プラグイン

しかし、彼らは Cordova 1.9 をサポートしていないようです... 私が使用できる他の新しいバージョンはありますか?

4

2 に答える 2

2

Pushwoosh ( http://pushwoosh.com ) からプッシュ SDK を試すことができます。これらは無料で、(UrbanAirship とは異なり) Cordova 1.9 および GCM を既にサポートしています。

于 2012-08-16T15:47:21.987 に答える
1

有料サービスで提供されているプラ​​グインが iOS 専用の場合、Urban Airship は... Android はCGMを使用して PUSH 通知を配信するようになりました。

CGM は非常に新しく、以前はC2DMだったので、手元に CGM のマニュアルはありませんが、このコードは開発を始めるのに役立つかもしれません:

メイン アプリケーション JAR ファイル:

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // register for PUSH notifications - you will need a registered Google e-mail for it
    C2DMessaging.register(this /*the application context*/, DeviceRegistrar.SENDER_ID);
    super.loadUrl("file:///android_asset/www/index.html");
}

DeviceRegistrar.java

package YOURPACKAGE;

import android.content.Context;
import android.util.Log;

public class DeviceRegistrar {
    public static final String SENDER_ID = "YOUR-GOOGLE-REGISTERED-EMAIL";
    private static final String TAG = "YOUR_APP_NAME";
    // just so you can work with the registration token from C2DM
    public static String token;

    public static void registerWithServer(Context context, String registrationId)
    {
        token = registrationId;
        // insert code to supplement this device registration with your 3rd party server
        Log.d(TAG, "successfully registered, ID = " + registrationId);
    }

    public static void unregisterWithServer(Context context, String registrationId)
    {
        // insert code to supplement unregistration with your 3rd party server
        Log.d(TAG, "succesfully unregistered with 3rd party app server");
    }
}

C2DMReceiver.java ( c2dm.jar ファイルが必要で、ライブラリに追加します)

package YOURPACKAGE;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.util.Log;

import com.google.android.c2dm.C2DMBaseReceiver;
import com.google.android.c2dm.C2DMessaging;

public class C2DMReceiver extends C2DMBaseReceiver 
{
    public static final String TAG = "YOUR_APP_NAME";
    public static String lastMessage = "";
    public static List<Integer> lastNotifications = new ArrayList<Integer>();
    public static Boolean isForegrounded = true;

    public C2DMReceiver()
    {
        //send the email address you set up earlier
        super(DeviceRegistrar.SENDER_ID);
    }

    @Override
    public void onRegistered(Context context, String registrationId) throws IOException 
    {
        Log.d(TAG, "successfully registered with C2DM server; registrationId: " + registrationId);
        DeviceRegistrar.registerWithServer(context, registrationId);
    }

    @Override
    public void onError(Context context, String errorId) 
    {
        //notify the user
        Log.e(TAG, "error with C2DM receiver: " + errorId);
        if ("ACCOUNT_MISSING".equals(errorId)) {
            //no Google account on the phone; ask the user to open the account manager and add a google account and then try again
            //TODO  
            } else if ("AUTHENTICATION_FAILED".equals(errorId)) {
                //bad password (ask the user to enter password and try.  Q: what password - their google password or the sender_id password? ...)
                //i _think_ this goes hand in hand with google account; have them re-try their google account on the phone to ensure it's working
                //and then try again
                //TODO  
            } else if ("TOO_MANY_REGISTRATIONS".equals(errorId)) {
                //user has too many apps registered; ask user to uninstall other apps and try again
                //TODO  
            } else if ("INVALID_SENDER".equals(errorId)) {
                //this shouldn't happen in a properly configured system
                //TODO: send a message to app publisher?, inform user that service is down  
            } else if ("PHONE_REGISTRATION_ERROR".equals(errorId)) {
                //the phone doesn't support C2DM; inform the user
                //TODO  
            } //else: SERVICE_NOT_AVAILABLE is handled by the super class and does exponential backoff retries
        }
    }

    @Override
    protected void onMessage(Context context, Intent intent) 
    {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            //parse the message and do something with it.
            //For example, if the server sent the payload as "data.message=xxx", here you would have an extra called "message"
            String message = extras.getString("message");
            Log.i(TAG, "received message: " + message);
        }
    }
}
于 2012-08-14T13:21:29.210 に答える