use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class MakeChoiceActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case Default.SELECT_PHOTO:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
File imageFile = new File(getRealPathFromURI(selectedImage));
final String filePath = imageFile.getPath();
progressDialog = ProgressDialog.show(MakeChoiceActivity.this, "", "Loading", true);
Backendless.Files.upload(imageFile, Default.DEFAULT_PATH_ROOT, new AsyncCallback<BackendlessFile>() {
@Override
public void handleResponse(BackendlessFile response) {
String photoBrowseUrl = response.getFileURL();
Intent intent = new Intent();
intent.putExtra(Default.PHOTO_BROWSE_URL, photoBrowseUrl);
intent.putExtra(Default.FILE_PATH, filePath);
setResult(Default.ADD_NEW_PHOTO_RESULT, intent);
progressDialog.cancel();
finish();
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(MakeChoiceActivity.this, fault.toString(), Toast.LENGTH_SHORT).show();
}
});
}
break;
case Default.MAKE_NEW_PHOTO:
String photoCameraUrl = imageReturnedIntent.getStringExtra(Default.PHOTO_CAMERA_URL);
String filePath = imageReturnedIntent.getStringExtra(Default.FILE_PATH);
Intent intent = new Intent();
intent.putExtra(Default.PHOTO_CAMERA_URL, photoCameraUrl);
intent.putExtra(Default.FILE_PATH, filePath);
setResult(Default.ADD_NEW_PHOTO_RESULT, intent);
finish();
break;
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class FenceDemo method startFenceMonitoring.
private void startFenceMonitoring() {
boolean useCustomCallback = ((Switch) findViewById(R.id.customCallbackToggle)).isChecked();
final String fenceName = fenceNameField.getText().toString();
IGeofenceCallback customCallback = new CustomCallBack();
if (fenceName == null || fenceName.isEmpty()) {
if (useCustomCallback) {
Backendless.Geo.startGeofenceMonitoring(customCallback, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(FenceDemo.this, "Fences monitoring started", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG).show();
}
});
} else {
Backendless.Geo.startGeofenceMonitoring(geoPoint, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(FenceDemo.this, "Fences monitoring started", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG).show();
}
});
}
} else {
if (useCustomCallback) {
Backendless.Geo.startGeofenceMonitoring(fenceName, customCallback, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(FenceDemo.this, "Fence " + fenceName + " monitoring started", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG).show();
}
});
} else {
Backendless.Geo.startGeofenceMonitoring(fenceName, geoPoint, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(FenceDemo.this, "Fence " + fenceName + " monitoring started", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class UploadingActivity method uploadBitmap.
private void uploadBitmap(Bitmap photo) {
LinearLayout imageContainer = (LinearLayout) findViewById(R.id.imageContainer);
Drawable drawable = new BitmapDrawable(photo);
drawable.setAlpha(50);
imageContainer.setBackgroundDrawable(drawable);
String name = UUID.randomUUID().toString() + ".png";
Backendless.Files.Android.upload(photo, Bitmap.CompressFormat.PNG, 100, name, Defaults.DEFAULT_PATH_ROOT, new AsyncCallback<BackendlessFile>() {
@Override
public void handleResponse(final BackendlessFile backendlessFile) {
handleSuccess(backendlessFile);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(UploadingActivity.this, backendlessFault.toString(), Toast.LENGTH_SHORT).show();
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class ChatActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
final String name = getIntent().getStringExtra(Defaults.NAME_TAG);
final EditText historyField = (EditText) findViewById(R.id.historyField);
final EditText messageField = (EditText) findViewById(R.id.messageField);
Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);
Backendless.Messaging.subscribe(Defaults.CHANNEL_NAME, new AsyncCallback<List<Message>>() {
@Override
public void handleResponse(List<Message> response) {
for (Message message : response) historyField.setText(message.getPublisherId() + ": " + message.getData() + "\n" + historyField.getText());
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
}, new AsyncCallback<Subscription>() {
@Override
public void handleResponse(Subscription response) {
subscription = response;
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
messageField.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_UP) {
String message = messageField.getText().toString();
if (message == null || message.equals(""))
return true;
final ProgressDialog progressDialog = ProgressDialog.show(ChatActivity.this, "", "Sending", true);
Backendless.Messaging.publish(Defaults.CHANNEL_NAME, message, new PublishOptions(name), new AsyncCallback<MessageStatus>() {
@Override
public void handleResponse(MessageStatus response) {
progressDialog.cancel();
messageField.setText("");
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
return true;
}
return false;
}
});
}
use of com.backendless.exceptions.BackendlessFault 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);
}
Aggregations