首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >count.ly推送通知

count.ly推送通知
EN

Stack Overflow用户
提问于 2019-01-01 15:53:11
回答 1查看 343关注 0票数 0

下面是代码片段,这是演示应用程序中列出的计数文档发送推送通知给用户在安卓&我们有社区版的计数,问题是用户甚至没有注册在计数。

Demo provided by countly

在上面的演示应用程序中添加了必要的凭据后,这些凭据实际上都没有在计数中注册我的设备,是否可以计数准确地显示实时用户?或者我在下面的代码中遗漏了什么错误?

代码语言:javascript
代码运行次数:0
运行
复制
public class MainActivity extends Activity {

    private BroadcastReceiver messageReceiver;

    /**
     * You should use try.count.ly instead of YOUR_SERVER for the line below if you are using Countly trial service
     */
    final String COUNTLY_SERVER_URL = "http://xxxx";
    final String COUNTLY_APP_KEY = "xxxx";
     final String COUNTLY_MESSAGING_PROJECT_ID = "xxxx";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Context appC = getApplicationContext();
        Countly.onCreate(this);
        Countly.sharedInstance().setLoggingEnabled(true);
        Countly.sharedInstance().setPushIntentAddMetadata(true);
        Countly.sharedInstance().enableCrashReporting();
        Countly.sharedInstance().setViewTracking(true);
        Countly.sharedInstance().setAutoTrackingUseShortName(true);
        Countly.sharedInstance().setRequiresConsent(false);
        Countly.sharedInstance().setConsent(new String[]{Countly.CountlyFeatureNames.sessions}, true);
        Countly.sharedInstance().init(appC, COUNTLY_SERVER_URL, COUNTLY_APP_KEY)
                .initMessaging(this, MainActivity.class, COUNTLY_MESSAGING_PROJECT_ID, Countly.CountlyMessagingMode.PRODUCTION);

        Countly.sharedInstance().recordEvent("test", 1);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Countly.sharedInstance().recordEvent("test2", 1, 2);
            }
        }, 5000);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Countly.sharedInstance().recordEvent("test3");
            }
        }, 10000);
    }

    @Override
    public void onStart() {
        super.onStart();
        Countly.sharedInstance().onStart(this);
    }

    @Override
    public void onStop() {
        Countly.sharedInstance().onStop();
        super.onStop();
    }

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

        // Register for broadcast action if you need to be notified when Countly message received
        messageReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Message message = intent.getParcelableExtra(CountlyMessaging.BROADCAST_RECEIVER_ACTION_MESSAGE);
                Log.i("CountlyActivity", "Got a message with data: " + message.getData());

                //Badge related things
                Bundle data = message.getData();
                String badgeString = data.getString("badge");
                try {
                    if (badgeString != null) {
                        int badgeCount = Integer.parseInt(badgeString);

                        boolean succeeded = ShortcutBadger.applyCount(getApplicationContext(), badgeCount);
                        if (!succeeded) {
                            Toast.makeText(getApplicationContext(), "Unable to put badge", Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (NumberFormatException exception) {
                    Toast.makeText(getApplicationContext(), "Unable to parse given badge number", Toast.LENGTH_SHORT).show();
                }
            }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction(CountlyMessaging.getBroadcastAction(getApplicationContext()));
        registerReceiver(messageReceiver, filter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(messageReceiver);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-01-07 23:42:56

由于您在Countly仪表板上看不到您的用户,因此这是以下原因之一:

  • 错误的COUNTLY_APP_KEY;
  • Wrong COUNTLY_SERVER_URL;
  • Some连接问题-您的设备无法访问该服务器。

您已经通过Countly.sharedInstance().setLoggingEnabled(true)启用了日志记录,因此您的Logcat应该会有一些错误,这些错误会告诉您其中哪一个是关于您的案例的。

此外,您还可以使用sdk-messaging依赖项而不是sdk-messaging-fcm。第一个使用GCM,它被弃用而支持FCM,也就是Firebase。我们有a detailed guide for that

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53993885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档