Ниже приведен фрагмент кода, который является демонстрационным приложением, перечисленным в документации графства для отправки push-уведомлений пользователю в Android, и у нас есть версия сообщества графства, проблема в том, что пользователи даже не регистрируются в графстве.
Демонстрация предоставлена countly
После добавления необходимых учетных данных в вышеприведенном демонстрационном приложении никто из тех, кто на самом деле не регистрирует мое устройство в countly, является ли счет точным для показа живых пользователей?или я что-то не так в коде ниже?
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);
}
}