Cannot get push notification from Urban Airship

我与影子孤独终老i 提交于 2019-12-10 02:09:30

问题


I am integrating Urban Airship to my Android application. I got a sample code from there and I followed the same procedure in order to invoke it from my application. But, I don't get any push notification on my device.

Can anyone guide me how to integrate the Urban Airship in Android application? How to send the AppId and GCM Register ID to Urban Airship server and getting the notification?

public class MyApplication extends Application {

    public static SharedPreferences PREFS_TOKEN;
    public static final String PREFERENCE = "UrbanAirship";
    public static String tokenKey;

    @Override
    public void onCreate() {
        super.onCreate();

        AirshipConfigOptions options = AirshipConfigOptions
                .loadDefaultOptions(this);

        UAirship.takeOff(this, options);
        PushManager.enablePush();

        // Optionally, customize your config at runtime:
        //
        // options.inProduction = false;
        // options.developmentAppKey = "Your Development App Key";
        // options.developmentAppSecret "Your Development App Secret";
        // UAirship.takeOff(this, options);

        Logger.logLevel = Log.VERBOSE;

        // use CustomPushNotificationBuilder to specify a custom layout
        CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();

        nb.statusBarIconDrawableId = R.drawable.icon;// custom status bar icon

        nb.layout = R.layout.notification;
        nb.layoutIconDrawableId = R.drawable.icon;// custom layout icon
        nb.layoutIconId = R.id.icon;
        nb.layoutSubjectId = R.id.subject;
        nb.layoutMessageId = R.id.message;

        // customize the sound played when a push is received
        // nb.soundUri =
        // Uri.parse("android.resource://"+this.getPackageName()+"/"
        // +R.raw.cat);

        String apid = PushManager.shared().getAPID();

        Logger.info("My Application onCreate - App APID: " + apid);

        PREFS_TOKEN = this.getSharedPreferences(PREFERENCE,
                Context.MODE_PRIVATE);
        Editor edit = PREFS_TOKEN.edit();

        if (apid != null && apid != "") {
            edit.putString(PREFERENCE, apid);
            edit.commit();
        } else {
            edit.putString(PREFERENCE, apid);
            edit.commit();
        }

        tokenKey = PREFS_TOKEN.getString(PREFERENCE, "");
        System.out.println("---------- - App APID: " + tokenKey);

        PushManager.shared().setNotificationBuilder(nb);
        PushManager.shared().setIntentReceiver(IntentReceiver.class);
    }
}

IntentReceiver

public class IntentReceiver extends BroadcastReceiver {

    private static final String logTag = "PushSample";
    public static String APID_UPDATED_ACTION_SUFFIX = ".apid.updated";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(logTag, "Received intent: " + intent.toString());
        String action = intent.getAction();

        if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {
            int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);

            // Id
            String ap_id = intent.getStringExtra(PushManager.EXTRA_APID);

            System.out.println("IntentReceiver::- ID::-" + ap_id);

            Log.i(logTag,
                    "Received push notification. Alert: "
                            + intent.getStringExtra(PushManager.EXTRA_ALERT)
                            + " [NotificationID=" + id + "]");

            logPushExtras(intent);
        } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
            Log.i(logTag,
                    "User clicked notification. Message: "
                            + intent.getStringExtra(PushManager.EXTRA_ALERT));

            logPushExtras(intent);

            Intent launch = new Intent(Intent.ACTION_MAIN);
            launch.setClass(UAirship.shared().getApplicationContext(),
                    SplashMainActivity.class);
            launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            UAirship.shared().getApplicationContext().startActivity(launch);
        } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {
            Log.i(logTag,
                    "Registration complete. APID:"
                            + intent.getStringExtra(PushManager.EXTRA_APID)
                            + ". Valid: "
                            + intent.getBooleanExtra(
                                    PushManager.EXTRA_REGISTRATION_VALID, false));

            // Notify any app-specific listeners
            Intent launch = new Intent(UAirship.getPackageName()
                    + APID_UPDATED_ACTION_SUFFIX);
            UAirship.shared().getApplicationContext().sendBroadcast(launch);
        } else if (action.equals(GCMMessageHandler.ACTION_GCM_DELETED_MESSAGES)) {
            Log.i(logTag,
                "The GCM service deleted "
                        + intent.getStringExtra(GCMMessageHandler.EXTRA_GCM_TOTAL_DELETED)
                        + " messages.");
        }
    }

    /**
     * Log the values sent in the payload's "extra" dictionary.
     * 
     * @param intent
     *            A PushManager.ACTION_NOTIFICATION_OPENED or
     *            ACTION_PUSH_RECEIVED intent.
     */
    private void logPushExtras(Intent intent) {
        Set<String> keys = intent.getExtras().keySet();
        for (String key : keys) {
            // ignore standard C2DM extra keys
            List<String> ignoredKeys = (List<String>) Arrays.asList(
                    "collapse_key",// c2dm collapse key
                    "from",// c2dm sender
                    PushManager.EXTRA_NOTIFICATION_ID,  // int id of generated
                                                        // notification
                                                        // (ACTION_PUSH_RECEIVED
                                                        // only)
                    PushManager.EXTRA_PUSH_ID,// internal UA push id
                    PushManager.EXTRA_ALERT);// ignore alert
            if (ignoredKeys.contains(key)) {
                continue;
            }
            Log.i(logTag,
                    "Push Notification Extra: [" + key + " : "
                            + intent.getStringExtra(key) + "]");
        }
    }
}

LogCat: Application send request and get the App Id

07-29 15:57:28.794: E/Trace(13468): error opening trace file: No such file or directory (2)
07-29 15:57:28.814: I/ActivityThread(13468): Pub com.dimdimsumapp.aniemoticonsfree.urbanairship.provider:com.urbanairship.UrbanAirshipProvider
07-29 15:57:28.934: D/dimdimsum - UALib(13468): Airship Take Off! Lib Version: 3.0.0 / App key = ydNnhfVFSa-mBbxvZsrSTg
07-29 15:57:28.934: D/dimdimsum - UALib(13468): In Production? false
07-29 15:57:29.024: D/dimdimsum - UALib(13468): Initializing Push.
**07-29 15:57:29.064: D/dimdimsum APID(13468): ceb76a95-e6d0-459e-a6ef-942ceddd750d**
07-29 15:57:29.064: D/dimdimsum - UALib(13468): Initializing Analytics.
07-29 15:57:29.104: I/dimdimsum - UALib(13468): My Application onCreate - App APID: ceb76a95-e6d0-459e-a6ef-942ceddd750d
07-29 15:57:29.104: I/System.out(13468): ---------- - App APID: ceb76a95-e6d0-459e-a6ef-942ceddd750d
07-29 15:57:29.234: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.SplashMainActivity","session_id":"6d266e92-6bd5-431b-bf52-fe270cb2b80d"},"type":"activity_started","event_id":"7885aac7-26bb-475a-8fa7-bad81dc8ab47","time":"1375093649"}
07-29 15:57:29.234: V/dimdimsum - UALib(13468): New session: 09ea147d-5a9f-4b5d-9bf6-1d7a4511a380
07-29 15:57:29.254: V/dimdimsum - UALib(13468): com.urbanairship.analytics.AppForegroundEvent -
    {"data":{"time_zone":19800,"session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380","notification_types":["sound","vibrate"],"daylight_savings":false,"push_enabled":true,"carrier":"","lib_version":"3.0.0","connection_type":"wifi","package_version":"1.0","os_version":"4.1.1"},"type":"app_foreground","event_id":"d63915e7-e0be-4779-9c60-90cb2e535ed7","time":"1375093649"}

07-29 15:57:29.314: D/dimdimsum - UALib(13468): Push enabled: true
07-29 15:57:29.324: V/dimdimsum - UALib(13468): com.dimdimsumapp.aniemoticonsfree.urbanairship.analytics.APP_FOREGROUND
07-29 15:57:29.334: D/dimdimsum - UALib(13468): Starting GCM
07-29 15:57:29.334: I/System.out(13468): Extra Call::-3D Smiley
07-29 15:57:30.874: I/dimdimsum - UALib(13468): Using GCM Registration ID:
    APA91bEOcPZneTlt9ObegtkCj4QhO6FP-nym7LIE5YaTtTzUCayIFifG85kLG3Z3MXNgSMqyfBkt_B4NpaVdWR7TZmgZV6LkooqkR9uR48kZxgkxTriv3y9RVNQyDf3ahned53FF-2vnk7MxtOiaL_7bB1IW4Tbx-qnATWQpHFKrvcnVEsYoX9c
07-29 15:57:34.344: D/dalvikvm(13468): GC_CONCURRENT freed 16K, 9% free 9416K/10311K, paused 2ms+1ms, total 12ms
07-29 15:57:34.394: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.SplashLodingActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_started","event_id":"505c5d2a-f98d-436b-a32f-0c24cf3bd378","time":"1375093654"}
07-29 15:57:34.464: D/dalvikvm(13468): GC_FOR_ALLOC freed 919K, 14% free 9413K/10823K, paused 10ms, total 10ms
07-29 15:57:34.544: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStoppedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.SplashMainActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_stopped","event_id":"bfa4ee55-dbe3-40e6-b0f1-25655022a6a8","time":"1375093654"}
07-29 15:57:34.544: W/dimdimsum - UALib(13468): Activity com.dimdimsumapp.aniemoticonsfree.SplashMainActivity@411aa7a0 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.

07-29 15:57:38.374: I/dalvikvm(13468):   #17  pc 0005fab7  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+374)
07-29 15:57:44.984: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.view.MenuActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_started","event_id":"7026224f-b14a-401f-b9c8-0b0c510e5442","time":"1375093664"}
07-29 15:57:44.984: V/BulletinBoardTabActivity(13468): Entered in Activity
07-29 15:57:44.994: D/dalvikvm(13468): DexOpt: --- BEGIN 'ads360220448.jar' (bootstrap=0) ---
07-29 15:57:45.054: E/ActivityThread(13468): Failed to find provider info for com.google.plus.platform
07-29 15:57:45.064: I/Ads(13468): To get test ads on this device, call adRequest.addTestDevice("E55D186D8620B7B943AC22C1DEFD4948");
07-29 15:57:45.074: I/[RevMob](13468): Loading Fullscreen
07-29 15:57:45.084: I/[RevMob](13468): The ad is not completely loaded yet. As soon as it is loaded, it is going to be displayed automatically.

07-29 15:57:45.094: W/System.err(13468):    at dalvik.system.NativeStart.main(Native Method)
07-29 15:57:45.754: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.view.MainActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_started","event_id":"11d4e931-39d5-4374-b4bf-319d9abf022a","time":"1375093665"}
07-29 15:57:45.754: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.MainTabActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_started","event_id":"a1f8a882-a2b4-4600-b62e-2108f296b599","time":"1375093665"}
07-29 15:57:45.834: I/Chartboost(13468): SHOULD REQUEST INSTERSTITIAL 'Default'?
07-29 15:57:46.024: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStoppedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.SplashLodingActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_stopped","event_id":"8dab5740-b165-42d5-a7fb-965127319581","time":"1375093666"}
07-29 15:57:46.024: W/dimdimsum - UALib(13468): Activity com.dimdimsumapp.aniemoticonsfree.SplashLodingActivity@41257a40 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
07-29 15:57:46.124: D/dalvikvm(13468): GC_CONCURRENT freed 792K, 10% free 10192K/11271K, paused 12ms+13ms, total 46ms
07-29 15:57:46.134: D/webviewglue(13468): nativeDestroy view: 0x400dbbc8
07-29 15:57:46.474: D/dalvikvm(13468): DexOpt: --- END 'ads360220448.jar' (success) ---
07-29 15:57:46.474: D/dalvikvm(13468): DEX prep '/data/data/com.dimdimsumapp.aniemoticonsfree/cache/ads360220448.jar': unzip in 0ms, rewrite 1486ms
07-29 15:57:49.714: D/[RevMob](13468): Server request successful (200)
07-29 15:57:49.714: D/[RevMob](13468): Server request successful (200)
07-29 15:57:49.734: I/Ads(13468): adRequestUrlHtml: <html><head><script
    src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":1,"session_id":"2193324013207180751","seq_num":"2","slotname":"a1514342105f35b","u_w":800,"msid":"com.dimdimsumapp.aniemoticonsfree","js":"afma-sdk-a-v6.4.1","bas_off":0,"net":"wi","app_name":"1.android.com.dimdimsumapp.aniemoticonsfree","hl":"en","smart_w":"full","gnt":0,"u_audio":1,"kw":[],"u_sd":1,"ms":"p0DRX3Xo5pLuR1fi0Ic10MS35Dw_drZEu_5_6RtMnJ822YUea_sQghGZZK0bPsKzzuAnPIWk8-yVqxb9BHIf_N-j3wpJBeSHhm826l5-piFZk6HwjYPzw6C41oIvK6Bow-j8W9VSM3ZqaMO7ybwSFgNQ_TLU8gO3E-5FOGlfGGXrNWF4JtTXnpsY5vWHbZyc1EehpK9IhJRBPHGqB1XvRy1lvg3wS3Ib-0Apre5d35WdzelWh5hs9_shmOeyTZDDX_-rpmVyAU_HYClt7ojGk5a_42e6Bk5LtbsUJ4EL2TTF7I7D18yarbwISoYIsSEDedrx_TIAT8XzCyc-ZcNqmw","mv":"80210010.com.android.vending","isu":"E55D186D8620B7B943AC22C1DEFD4948","format":"800x90_mb","oar":0,"smart_h":"auto","ad_pos":{"height":70,"visible":1,"y":55,"x":0,"width":800},"u_h":1232,"pt":0,"bas_on":0,"ptime":121});</script></head><body></body></html>
07-29 15:57:49.744: I/Ads(13468): adRequestUrlHtml: <html><head><script
    src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"2193324013207180751","seq_num":"1","slotname":"a1514342105f35b","u_w":800,"msid":"com.dimdimsumapp.aniemoticonsfree","js":"afma-sdk-a-v6.4.1","bas_off":0,"net":"wi","app_name":"1.android.com.dimdimsumapp.aniemoticonsfree","hl":"en","smart_w":"full","gnt":0,"u_audio":1,"kw":[],"u_sd":1,"ms":"XsSWrnHHD52AS1MoI-uXmIkhfG-hiLlwqgiB_WHMZUeTQmHYO_tZeAu0jgwxMfVMgcybiP5cHOyXxhGWCf-wJYtsCtLk1OJhJa7J-YGAOa1QlZFdC2H53dMvI-QopAY0PWqbYMIqLu7xNfEVIS7E-J618_jQ8i0Ydf3grtdafjeGhyRqxuakG7MadX0_CWU-l2INfQPW3ys0iK85uHegeY7ACM6Xmd5SPBt3KBrsP7fn7uPX2B7cNCuM09YPFgBAfFiA5GlEO-1aY7AI4RxgFkew_EJPDlKk42YxqTeI4xc-m7O7hHcE229JYlNopOkgPboiHXzA82k5j2uoCdZ5JQ","mv":"80210010.com.android.vending","isu":"E55D186D8620B7B943AC22C1DEFD4948","format":"800x90_mb","oar":0,"smart_h":"auto","ad_pos":{"height":0,"visible":0,"y":5,"x":0,"width":0},"u_h":1232,"pt":0,"bas_on":0,"ptime":0});</script></head><body></body></html>
07-29 15:57:49.814: V/WebRequest(13468): WebRequest::WebRequest, setPriority = 1
07-29 15:57:53.804: D/[RevMob](13468): Fullscreen static
07-29 15:57:53.804: W/SingleClientConnManager(13468): Invalid use of SingleClientConnManager: connection still allocated.
07-29 15:57:53.804: W/SingleClientConnManager(13468): Make sure to release the connection before allocating another one.
07-29 15:57:53.874: I/Ads(13468): Received ad url: <url:
    "http://googleads.g.doubleclick.net:80/mads/gma?preqs=1&session_id=2193324013207180751&seq_num=2&u_w=800&msid=com.dimdimsumapp.aniemoticonsfree&js=afma-sdk-a-v6.4.1&bas_off=0&net=wi&app_name=1.android.com.dimdimsumapp.aniemoticonsfree&hl=en&smart_w=full&gnt=0&u_audio=1&kw&u_sd=1&ms=p0DRX3Xo5pLuR1fi0Ic10MS35Dw_drZEu_5_6RtMnJ822YUea_sQghGZZK0bPsKzzuAnPIWk8-yVqxb9BHIf_N-j3wpJBeSHhm826l5-piFZk6HwjYPzw6C41oIvK6Bow-j8W9VSM3ZqaMO7ybwSFgNQ_TLU8gO3E-5FOGlfGGXrNWF4JtTXnpsY5vWHbZyc1EehpK9IhJRBPHGqB1XvRy1lvg3wS3Ib-0Apre5d35WdzelWh5hs9_shmOeyTZDDX_-rpmVyAU_HYClt7ojGk5a_42e6Bk5LtbsUJ4EL2TTF7I7D18yarbwISoYIsSEDedrx_TIAT8XzCyc-ZcNqmw&mv=80210010.com.android.vending&format=800x90_mb&oar=0&smart_h=auto&u_h=1232&bas_on=0&ptime=121&u_so=p&imbf=%40installed_markets%40&cap=t&output=html&region=mobile_app&u_tz=330&client_sdk=1&ex=1&slotname=a1514342105f35b&kw_type=broad&askip=1&gsb=wi&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&eisu=hSCEQLwXlQ5zQs_QZvNYzuXzxV6V4206otKKrdAOuzZZ9PFeGAZbXn5F_iuYOfFvxOpKQDuYJAlW-YKlEH2LK90RIGT2if9ira5RJEckQgGBacn8GXzr1XLCWPXeV5ZR&et=10&jsv=53"
    type: "admob" afmaNotifyDt: "null" activationOverlayUrl: "null"
    useWebViewLoadUrl: "false">
07-29 15:57:53.884: I/Ads(13468): Ad url modified to http://googleads.g.doubleclick.net:80/mads/gma?preqs=1&session_id=2193324013207180751&seq_num=2&u_w=800&msid=com.dimdimsumapp.aniemoticonsfree&js=afma-sdk-a-v6.4.1&bas_off=0&net=wi&app_name=1.android.com.dimdimsumapp.aniemoticonsfree&hl=en&smart_w=full&gnt=0&u_audio=1&kw&u_sd=1&ms=p0DRX3Xo5pLuR1fi0Ic10MS35Dw_drZEu_5_6RtMnJ822YUea_sQghGZZK0bPsKzzuAnPIWk8-yVqxb9BHIf_N-j3wpJBeSHhm826l5-piFZk6HwjYPzw6C41oIvK6Bow-j8W9VSM3ZqaMO7ybwSFgNQ_TLU8gO3E-5FOGlfGGXrNWF4JtTXnpsY5vWHbZyc1EehpK9IhJRBPHGqB1XvRy1lvg3wS3Ib-0Apre5d35WdzelWh5hs9_shmOeyTZDDX_-rpmVyAU_HYClt7ojGk5a_42e6Bk5LtbsUJ4EL2TTF7I7D18yarbwISoYIsSEDedrx_TIAT8XzCyc-ZcNqmw&mv=80210010.com.android.vending&format=800x90_mb&oar=0&smart_h=auto&u_h=1232&bas_on=0&ptime=121&u_so=p&imbf=8009&cap=t&output=html&region=mobile_app&u_tz=330&client_sdk=1&ex=1&slotname=a1514342105f35b&kw_type=broad&askip=1&gsb=wi&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&eisu=hSCEQLwXlQ5zQs_QZvNYzuXzxV6V4206otKKrdAOuzZZ9PFeGAZbXn5F_iuYOfFvxOpKQDuYJAlW-YKlEH2LK90RIGT2if9ira5RJEckQgGBacn8GXzr1XLCWPXeV5ZR&et=10&jsv=53
07-29 15:57:53.884: I/Ads(13468): Request scenario: Online server request.
07-29 15:57:53.964: I/Ads(13468): Received ad url: <url:
    "http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=2193324013207180751&seq_num=1&u_w=800&msid=com.dimdimsumapp.aniemoticonsfree&js=afma-sdk-a-v6.4.1&bas_off=0&net=wi&app_name=1.android.com.dimdimsumapp.aniemoticonsfree&hl=en&smart_w=full&gnt=0&u_audio=1&kw&u_sd=1&ms=XsSWrnHHD52AS1MoI-uXmIkhfG-hiLlwqgiB_WHMZUeTQmHYO_tZeAu0jgwxMfVMgcybiP5cHOyXxhGWCf-wJYtsCtLk1OJhJa7J-YGAOa1QlZFdC2H53dMvI-QopAY0PWqbYMIqLu7xNfEVIS7E-J618_jQ8i0Ydf3grtdafjeGhyRqxuakG7MadX0_CWU-l2INfQPW3ys0iK85uHegeY7ACM6Xmd5SPBt3KBrsP7fn7uPX2B7cNCuM09YPFgBAfFiA5GlEO-1aY7AI4RxgFkew_EJPDlKk42YxqTeI4xc-m7O7hHcE229JYlNopOkgPboiHXzA82k5j2uoCdZ5JQ&mv=80210010.com.android.vending&format=800x90_mb&oar=0&smart_h=auto&u_h=1232&bas_on=0&ptime=0&u_so=p&imbf=%40installed_markets%40&cap=t&output=html&region=mobile_app&u_tz=330&client_sdk=1&ex=1&slotname=a1514342105f35b&kw_type=broad&gsb=wi&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&eisu=mJ5gWZo5jcV51kF671otqywVPd9HzqJSLviR5bZ1ubyxvtFnkFW0XeSqgwQnl0L7hK3qzuEy3CknOkZ4iJxeI_txVvpNT5Pg6gY9_pum4vCyLu24OnWWj2P7naZKofgh&et=35&jsv=53"
    type: "admob" afmaNotifyDt: "null" activationOverlayUrl: "null"
    useWebViewLoadUrl: "false"
07-29 15:57:53.984: D/dalvikvm(13468): GC_CONCURRENT freed 3647K, 34% free 7864K/11783K, paused 4ms+4ms, total 53ms
07-29 15:57:53.994: I/Ads(13468): Ad url modified to http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=2193324013207180751&seq_num=1&u_w=800&msid=com.dimdimsumapp.aniemoticonsfree&js=afma-sdk-a-v6.4.1&bas_off=0&net=wi&app_name=1.android.com.dimdimsumapp.aniemoticonsfree&hl=en&smart_w=full&gnt=0&u_audio=1&kw&u_sd=1&ms=XsSWrnHHD52AS1MoI-uXmIkhfG-hiLlwqgiB_WHMZUeTQmHYO_tZeAu0jgwxMfVMgcybiP5cHOyXxhGWCf-wJYtsCtLk1OJhJa7J-YGAOa1QlZFdC2H53dMvI-QopAY0PWqbYMIqLu7xNfEVIS7E-J618_jQ8i0Ydf3grtdafjeGhyRqxuakG7MadX0_CWU-l2INfQPW3ys0iK85uHegeY7ACM6Xmd5SPBt3KBrsP7fn7uPX2B7cNCuM09YPFgBAfFiA5GlEO-1aY7AI4RxgFkew_EJPDlKk42YxqTeI4xc-m7O7hHcE229JYlNopOkgPboiHXzA82k5j2uoCdZ5JQ&mv=80210010.com.android.vending&format=800x90_mb&oar=0&smart_h=auto&u_h=1232&bas_on=0&ptime=0&u_so=p&imbf=8009&cap=t&output=html&region=mobile_app&u_tz=330&client_sdk=1&ex=1&slotname=a1514342105f35b&kw_type=broad&gsb=wi&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&eisu=mJ5gWZo5jcV51kF671otqywVPd9HzqJSLviR5bZ1ubyxvtFnkFW0XeSqgwQnl0L7hK3qzuEy3CknOkZ4iJxeI_txVvpNT5Pg6gY9_pum4vCyLu24OnWWj2P7naZKofgh&et=35&jsv=53
07-29 15:57:53.994: I/Ads(13468): Request scenario: Online server request.
07-29 15:57:54.134: D/dalvikvm(13468): GC_CONCURRENT freed 612K, 34% free 7863K/11783K, paused 6ms+3ms, total 54ms
07-29 15:57:54.134: D/dalvikvm(13468): WAIT_FOR_CONCURRENT_GC blocked 7ms
07-29 15:57:54.774: D/dalvikvm(13468): GC_FOR_ALLOC freed 37K, 34% free 7885K/11783K, paused 45ms, total 45ms
07-29 15:57:54.784: I/dalvikvm-heap(13468): Grow heap (frag case) to 11.956MB for 4194320-byte allocation
07-29 15:57:54.814: D/dalvikvm(13468): GC_CONCURRENT freed <1K, 25% free 11981K/15943K, paused 11ms+1ms, total 25ms
07-29 15:57:54.874: I/[RevMob](13468): Fullscreen loaded
07-29 15:57:54.894: D/webviewglue(13468): nativeDestroy view: 0x64fc17f0
07-29 15:57:54.904: I/Ads(13468): onReceiveAd()
07-29 15:57:54.924: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStartedEvent -
    {"data":{"class_name":"com.revmob.ads.fullscreen.FullscreenActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_started","event_id":"0028a546-73b3-4d72-bf16-42b1fd03330f","time":"1375093674"}
07-29 15:57:55.524: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStoppedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.MainTabActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_stopped","event_id":"a545b947-b649-4c7d-8d9c-3bab9fa5844a","time":"1375093675"}
07-29 15:57:55.524: W/dimdimsum - UALib(13468): Activity com.dimdimsumapp.aniemoticonsfree.MainTabActivity@4114d510 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
07-29 15:57:55.524: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStoppedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.view.MenuActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_stopped","event_id":"a15bbf00-cbcf-4ce5-9dc2-4132d38d459d","time":"1375093675"}
07-29 15:57:55.524: W/dimdimsum - UALib(13468): Activity com.dimdimsumapp.aniemoticonsfree.view.MenuActivity@4124c630 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
07-29 15:57:55.534: V/dimdimsum - UALib(13468): com.urbanairship.analytics.ActivityStoppedEvent -
    {"data":{"class_name":"com.dimdimsumapp.aniemoticonsfree.view.MainActivity","session_id":"09ea147d-5a9f-4b5d-9bf6-1d7a4511a380"},"type":"activity_stopped","event_id":"014f5625-1c02-4fa4-af7a-131d2bdd7301","time":"1375093675"}
07-29 15:57:55.534: W/dimdimsum - UALib(13468): Activity com.dimdimsumapp.aniemoticonsfree.view.MainActivity@41504f18 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
    content://com.dimdimsumapp.aniemoticonsfree.urbanairship.provider/preferences/com.urbanairship.analytics.LAST_SEND/insert
07-29 15:58:23.984: V/dimdimsum - UALib(13468): Notified of change of key com.urbanairship.analytics.LAST_SEND
07-29 15:58:23.994: I/dimdimsum - UALib(13468): Sending 1 events.
07-29 15:58:23.994: V/dimdimsum - UALib(13468): Set Timeout: 60000
07-29 15:58:23.994: V/dimdimsum - UALib(13468): Set Socket Buffer Size: 16384
07-29 15:58:24.004: V/dimdimsum - UALib(13468): GZIP'd: 228 into 200 (expected 57)
07-29 15:58:24.004: I/dimdimsum - UALib(13468): Sending Analytics to: https://combine.urbanairship.com/warp9/
07-29 15:58:24.994: I/dimdimsum - UALib(13468): Warp 9 response: 200
07-29 15:58:26.084: I/Chartboost(13468): INTERSTITIAL 'Default' REQUEST FAILED
07-29 15:59:23.994: V/dimdimsum - UALib(13468): Notifying of change to
    content://com.dimdimsumapp.aniemoticonsfree.urbanairship.provider/preferences/com.urbanairship.analytics.LAST_SEND/insert
07-29 15:59:24.004: V/dimdimsum - UALib(13468): Notified of change of key com.urbanairship.analytics.LAST_SEND
07-29 15:59:24.004: I/dimdimsum - UALib(13468): Sending 11 events.
07-29 15:59:24.004: V/dimdimsum - UALib(13468): Set Timeout: 60000
07-29 15:59:24.004: V/dimdimsum - UALib(13468): Set Socket Buffer Size: 16384
07-29 15:59:24.004: V/dimdimsum - UALib(13468): GZIP'd: 2623 into 688 (expected 655)
07-29 15:59:24.014: I/dimdimsum - UALib(13468): Sending Analytics to: https://combine.urbanairship.com/warp9/
07-29 15:59:29.554: I/dimdimsum - UALib(13468): Warp 9 response: 200

回答1:


These are the steps you have to follow:

Android Side:

  • Create a sample app.
  • Include the jar of urban airship to your libs folder. I think latest jar is 3.0.
  • Create a file inside assets folder called: airshipconfig.properties.

These are what you have to put inside airshipconfig.properties:

// app ID of the project in google API's console, called 'Project Number' (in overview page)
gcmSender = 123456789
transport = gcm
developmentAppKey = mqqwqP1gLRkuf-bQBhlwOow
developmentAppSecret = 4kqqwqJfRGmSRBd40bA_Wg
inProduction = false

Android Manifest has to be as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jbm.push"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <!-- REQUIRED PERMISSIONS (for Urban Airship GCM) -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- This app has permission to register with GCM and receive message -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="com.jbm.push.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.jbm.push.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:name="com.jbm.push.MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.jbm.push.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- REQUIRED for Urban Airship GCM -->
        <receiver android:name="com.urbanairship.CoreReceiver" />
        <receiver
            android:name="com.urbanairship.push.GCMPushReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <!-- MODIFICATION REQUIRED - Use your package name as the category -->
                <category android:name="com.jbm.push" />
            </intent-filter>
            <!-- REQUIRED for detecting when the application is upgraded so it can request a new GCM ID -->
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REPLACED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <service
            android:name="com.urbanairship.push.PushService"
            android:label="Push Notification Service" />
        <!-- REQUIRED only with UA Android lib version 2.1.4 and earlier. Do not include PushWorkerService with UA Android lib version 3.0.0+ since it has been deprecated -->
        <service
            android:name="com.urbanairship.push.PushWorkerService"
            android:label="Push Notification Worker Service" />
        <service
            android:name="com.urbanairship.analytics.EventService"
            android:label="Event Service" />

        <!-- This is required for persisting preferences related to push and location -->
        <!-- MODIFICATION REQUIRED - Use your package name + ".urbanairship.provider" in the android:authorities -->
        <provider
            android:name="com.urbanairship.UrbanAirshipProvider"
            android:authorities="com.jbm.push.urbanairship.provider"
            android:exported="false"
            android:multiprocess="true" />
        <!-- END OF REQUIRED ITEMS -->


        <!-- OPTIONAL (for segments support) -->
        <service
            android:name="com.urbanairship.location.LocationService"
            android:label="Segments Service" />

        <!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
        <!-- Replace the receiver below with your package and class name -->
        <receiver android:name="com.jbm.push.IntentReceiver" />
    </application>

</manifest>

MyApplication.java:

public class MyApplication extends Application {

       @Override
       public void onCreate(){
           AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
           UAirship.takeOff(this, options);
           PushManager.enablePush();

       }
    }

This is all that you require from the Android side. In order to send the push it is a must that you configure your app properly on urban airship site. Provide the android application's package name and the Google API Console project's server key: follow these steps: http://docs.urbanairship.com/dashboard/getting_started.html#configuring-services

Then simply send the message from the dashboard that airship has provided. I followed this tutorial:

http://docs.urbanairship.com/build/android.html



来源:https://stackoverflow.com/questions/17921968/cannot-get-push-notification-from-urban-airship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!