本文介绍了Localytics - 推Notifcations不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Localytics试图整合推送通知如下这个指南。

I'm trying to integration Push Notifications through Localytics following this guide.

这里是我所做的事情的清单:

Here's a list of what I've done:

  1. 综合Localytics在我的应用程序的的onCreate

公共类应用扩展android.app.Application {

public class Application extends android.app.Application{

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

    // Integrate Localytics
    Localytics.setLoggingEnabled(true);
    Localytics.integrate(this);
    Localytics.setPushDisabled(false);
}

}

Localytics.registerPush 在我的主要活动的的onCreate()利用Gooogle开发者控制台项目编号。

Localytics.registerPush in my main activity's onCreate() using project number from Gooogle Developer Console.

公共类MainActivity扩展FragmentActivity {

public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Localytics.registerPush("1234567890");

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

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

    Localytics.handleTestMode(getIntent());
    Localytics.openSession();
    Localytics.tagScreen("Main");
    Localytics.upload();

    if (this instanceof FragmentActivity)
    {
        Localytics.setInAppMessageDisplayActivity(this);
    }

    Localytics.handleTestMode(getIntent());
}

public void onPause()
{
    Localytics.dismissCurrentInAppMessage();
    Localytics.clearInAppMessageDisplayActivity();

    Localytics.closeSession();
    Localytics.upload();

    super.onPause();
}

@Override
protected void onNewIntent(Intent intent)
{
    super.onNewIntent(intent);
    Log.e("MainActivity","onNewIntent");
    setIntent(intent);
}

private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    100).show();
        } else {
            Log.i("GAE", "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}

}

设置我的清单文件如下:

Set up my manifest file as follows:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />   // optional, but highly recommended
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.imena.localytics.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.imena.localytics.permission.C2D_MESSAGE" />

<application
    android:name=".Application"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".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>
    <activity android:name="com.localytics.android.PushTrackingActivity"/>
    <service
        android:name=".MyGcmListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <service
        android:name=".MyInstanceIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>
    <service android:name=".RegistrationIntentService"/>

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.imena.localytics" />
        </intent-filter>
    </receiver>

    <receiver android:name="com.localytics.android.ReferralReceiver" android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.localytics.android.PushReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.imena.localytics" />
        </intent-filter>
    </receiver>
    <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="LOCALYTICS_NOTIFICATION_ICON"
        android:value="@drawable/ic_launcher"/>
    <meta-data android:name="LOCALYTICS_APP_KEY" android:value="key"/>
</application>

我的注册与Localytics仪表盘谷歌API服务器键。

Registered my Google Api server key with Localytics Dashboard.

执行所有这些步骤后,我不能推通知工作。什么我错过了?我在哪里出了错?

After performing all of these steps, I can't get push notifications to work.What have I missed? Where have I gone wrong?

谢谢!

推荐答案

大约2个月,因为你的回答,不知是不是现在的工作,但在这里我们去反正:)

About 2 months since you answered, maybe it is working now but here we go anyway :)

我只是执行Localytics,发现您的文章,因为我有自己的麻烦在收到推送消息。

I just implemented Localytics and found your post as I had troubles myself on receiving push messages.

您的设置看起来不错,但也许你错过了同样的事情,我是,复制谷歌,services.json到我的项目。这是当您启用GCM(您从谷歌获取文件的步骤2 HTTP: //docs.localytics.com/#Analytics/android-push-gcm.html )。

Your settings looks good, but maybe you are missing the same thing I were, copying google-services.json into my project. It is a file you get from Google when you enable GCM (step 2 on http://docs.localytics.com/#Analytics/android-push-gcm.html).

其实我有正弦我使用谷歌Analytics(分析)之前,该文件存在,但忘了有GCM启用后,一个新的覆盖。

I actually had that file there before sine I'm using Google analytics, but forgot to overwrite it with a new one after enabling GCM.

祝你好运!

这篇关于Localytics - 推Notifcations不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 05:51