Search in sources :

Example 1 with DeliveryOptions

use of com.backendless.messaging.DeliveryOptions in project Android-SDK by Backendless.

the class PushActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.push);
    historyField = (TextView) findViewById(R.id.historyField);
    messageField = (EditText) findViewById(R.id.messageField);
    forceNotify = (CheckBox) findViewById(R.id.forceNotify);
    handler = new Handler(new Handler.Callback() {

        @Override
        public boolean handleMessage(Message message) {
            if (!(message.obj instanceof Error))
                historyField.setText(message.obj + "\n" + historyField.getText());
            else
                MainActivity.showAlert(PushActivity.this, ((Error) message.obj).getMessage());
            return true;
        }
    });
    findViewById(R.id.sendButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String message = messageField.getText().toString();
            if (message == null || message.equals(""))
                return;
            final ProgressDialog progressDialog = ProgressDialog.show(PushActivity.this, "", "Sending push message", true);
            DeliveryOptions deliveryOptions = new DeliveryOptions();
            deliveryOptions.setPushBroadcast(PushBroadcastMask.ALL);
            PublishOptions publishOptions = new PublishOptions();
            if (forceNotify.isChecked()) {
                publishOptions.putHeader(PublishOptions.ANDROID_TICKER_TEXT_TAG, getString(R.string.app_name));
                publishOptions.putHeader(PublishOptions.ANDROID_CONTENT_TITLE_TAG, getString(R.string.app_name));
                publishOptions.putHeader(PublishOptions.ANDROID_CONTENT_TEXT_TAG, message);
            }
            Backendless.Messaging.publish(Defaults.CHANNEL_NAME, message, publishOptions, deliveryOptions, new BackendlessCallback<MessageStatus>() {

                @Override
                public void handleResponse(MessageStatus response) {
                    progressDialog.cancel();
                    messageField.setText("");
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    progressDialog.cancel();
                    Toast.makeText(PushActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    });
    findViewById(R.id.unregisterButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Backendless.Messaging.unregisterDevice();
            setResult(RESULT_OK, new Intent());
            finish();
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Intent(android.content.Intent) PublishOptions(com.backendless.messaging.PublishOptions) ProgressDialog(android.app.ProgressDialog) TextView(android.widget.TextView) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) MessageStatus(com.backendless.messaging.MessageStatus) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) DeliveryOptions(com.backendless.messaging.DeliveryOptions)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 Message (android.os.Message)1 View (android.view.View)1 TextView (android.widget.TextView)1 BackendlessCallback (com.backendless.async.callback.BackendlessCallback)1 BackendlessFault (com.backendless.exceptions.BackendlessFault)1 DeliveryOptions (com.backendless.messaging.DeliveryOptions)1 MessageStatus (com.backendless.messaging.MessageStatus)1 PublishOptions (com.backendless.messaging.PublishOptions)1