Requirement of project: communication between windows azure Website and android device using azure mobile services
1)Website is build in VB.NET using Microsoft Windows Azure (server side)
2)Android Application is on Android Device (client side)
The client (Android user) should be able to send data from android device (client side) to Website (Server side) and vice-versa To make this possible ie Communcation Between client and sever I am using Mobile Services provided by Microsoft Windows Azure (server side) which use GCM (Google Cloud Messaging)
I have Followed all steps according to the documentation
http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-android/
Also followed all steps as been provided in the above link documentation of Microsoft windows azure
but when I try to send message from Android device towards the website the following error occurs
Error: com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request
Note: GCM (Google Cloud Messaging) gives us an gcm.jar file which is used in the android app to send data towards Server ie website
ONCREATE CODE
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
mRegistationId = GCMRegistrar.getRegistrationId(this);
if (mRegistationId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
}
mProgressBar = (ProgressBar) findViewById(R.id.loadingProgressBar);
// Initialize the progress bar
mProgressBar.setVisibility(ProgressBar.GONE);
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"url of website",
"POBHgxwAktyxUdeRRpcFyqEcsppwiS99",
this).withFilter(new ProgressFilter());
// Get the Mobile Service Table instance to use
mToDoTable = mClient.getTable(ToDoItem.class);
mTextNewToDo = (EditText) findViewById(R.id.textNewToDo);
// Create an adapter to bind the items with the view
mAdapter = new ToDoItemAdapter(this, R.layout.row_list_to_do);
ListView listViewToDo = (ListView) findViewById(R.id.listViewToDo);
listViewToDo.setAdapter(mAdapter);
// Load the items from the Mobile Service
refreshItemsFromTable();
}
catch (MalformedURLException e) {
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
}
On BUTTON click event addItem() is called
public void addItem(View view) {
if (mClient == null) {
return;
}
try
{
// Create a new item
ToDoItem item = new ToDoItem();
item.setText(mTextNewToDo.getText().toString());
item.setComplete(false);
// Insert the new item
mToDoTable.insert(item, new TableOperationCallback<ToDoItem>() {
public void onCompleted(ToDoItem entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
if (!entity.isComplete()) {
mAdapter.add(entity);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
item.setRegistrationId(mRegistationId.equals("") ?
GCMIntentService.getRegistrationId() : mRegistationId);
mTextNewToDo.setText("");
}
catch(Exception ex)
{
}
}
public void checkItem(ToDoItem item) {
if (mClient == null) {
return;
}
// Set the item as completed and update it in the table
item.setComplete(true);
mToDoTable.update(item, new TableOperationCallback<ToDoItem>() {
public void onCompleted(ToDoItem entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
if (entity.isComplete()) {
mAdapter.remove(entity);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
}
private void refreshItemsFromTable() {
// Get the items that weren't marked as completed and add them in the
// adapter
mToDoTable.where().field("complete").eq(val(false)).execute(new TableQueryCallback<ToDoItem>() {
public void onCompleted(List<ToDoItem> result, int count, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
mAdapter.clear();
for (ToDoItem item : result) {
mAdapter.add(item);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
}
private void createAndShowDialog(Exception exception, String title) {
createAndShowDialog(exception.toString(), title);
}
private void createAndShowDialog(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message);
builder.setTitle(title);
builder.create().show();
}
private class ProgressFilter implements ServiceFilter {
@Override
public void handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback,
final ServiceFilterResponseCallback responseCallback) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mProgressBar != null) mProgressBar.setVisibility(ProgressBar.VISIBLE);
}
});
nextServiceFilterCallback.onNext(request, new ServiceFilterResponseCallback() {
@Override
public void onResponse(ServiceFilterResponse response, Exception exception) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mProgressBar != null) mProgressBar.setVisibility(ProgressBar.GONE);
}
});
if (responseCallback != null) responseCallback.onResponse(response, exception);
}
});
}
}
弄清楚该教程使用的是“而不是”,在我的情况下是问题所在。问题出在蔚蓝的插入脚本中。希望对您有所帮助:-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.