chabokpush / chabok-client-android

Chabok Push Client for Android
https://chabokpush.com
5 stars 1 forks source link

در اینجا تو هیچکدوم از کال بک ها نمیره #24

Closed sepehr13494 closed 5 years ago

sepehr13494 commented 5 years ago
private void sendData(MessageForHelper message) {

        PushMessage myPushMessage = new PushMessage();

        myPushMessage.setBody("پیام از طرف مدد کار");

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("title", message.getTitle());
            jsonObject.put("description", message.getDescription());
            jsonObject.put("date", message.getDate());
            jsonObject.put("helper", preferences.getString("helper_name",null));
            jsonObject.put("user_id", preferences.getString("user_id",null));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        myPushMessage.setData(jsonObject);

        myPushMessage.setId(UUID.randomUUID().toString());
        myPushMessage.setUseAsAlert(true);
        myPushMessage.setUser("user_"+preferences.getString("user_id",null));

        chabok = ((MyApplication)getApplication()).getPushClient();

        chabok.publish(myPushMessage, new com.adpdigital.push.Callback() {
            @Override
            public void onSuccess(Object o) {
                //Add some codes to show publish was successfully done
                Toast.makeText(SendMessageActivity.this, "پیام با موفقیت ارسال شد.", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "onSuccess: "+o.toString());
            }

            @Override
            public void onFailure(Throwable throwable) {

                //Add some codes for showing an error happened
                Toast.makeText(SendMessageActivity.this, "متاسفانه پیام ارسال نشد لطفا گزارش دهید.", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "onFailure: "+throwable.getMessage());
            }

        });

    }
behrad commented 5 years ago

سلام مجدد این سوال مربوط به کتابخانه اندروید هست من براتون انتقالش میدم به بخش اندروید و بخش کدی که گذاشتید رو ویرایش و مرتب می کنم

sepehr13494 commented 5 years ago

سلام مجدد این سوال مربوط به کتابخانه اندروید هست من براتون انتقالش میدم به بخش اندروید و بخش کدی که گذاشتید رو ویرایش و مرتب می کنم

بله خیلی ممنون

Husseinhj commented 5 years ago

لطفا از متصل بودن به چابک اطمینان حاصل کنین.

نکته: متد register عمل اتصال به سرور چابک را انجام می‌دهد، بنابراین باید فقط یک بار در طول اجرا اپلیکیشن (در کلاس application) فراخوانی شود.


برای دریافت نمونه initialize شده از کد زیر

chabok = AdpPushClient.get();

بجای

chabok = ((MyApplication)getApplication()).getPushClient();

استفاده کنید.