在启动时启动的Windows Azure Mobile与Android服务的使用存在限制吗?

时间:2013-05-03 19:30:43

标签: java android azure azure-mobile-services

我写了一个与Windows Azure Mobile Services通信的Android应用程序,通常在设备和android Azure数据库之间发送数据,但是当我插入相同的代码时,在启动时自动启动的服务不会运行。 我在启动时启动的Android服务没有问题。 我对Windows Azure服务Android服务没有任何问题。

但是当两个(服务在启动Android + Windows Azure服务时启动)没有运行时。

我需要帮助!

ItemReceiver.java

package com.example.itemreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class ItemReceiver extends BroadcastReceiver {   

    @Override
    public void onReceive(Context context, Intent intent) {
      Intent myIntent = new Intent(context, ItemService.class);
      context.startService(myIntent);
    }
}

ItemService.Java

package com.example.itemreceiver;

import java.net.MalformedURLException;
import com.microsoft.windowsazure.mobileservices.*;
import android.util.Log;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class ItemService extends Service  {
    private static final String TAG = "++Service++";
    private MobileServiceClient mClient;

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onStart(Intent intent, int startId) {

        // TODO Auto-generated method stub
         try {
             mClient = new MobileServiceClient( 
                     "https://bn7.azure-mobile.net/",
                      "nFdklchhdEhCuUsmSZVsxgYLPeaOLo64",
                    this 
                    );
            Item item = new Item(); 

            // Phone Number
            item.IdPhone = "005511964271485";

            // IMEI
            item.IdImei =  "351597055788723";

            item.DateTimePhone = "2013-05-03 14:00:00"; 

            item.Active = false; 
            mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
            @Override 
            public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response)               { 
            if (exception == null) { 
                         // Insert succeeded
                        Log.d(TAG, " Insert Sucess");
                                            } else { 
                         // Insert failed
                        Log.d(TAG, " Insert failed");
                        Log.d(TAG, " toString = " + exception.toString());
                        Log.d(TAG, " getCause = " + exception.getCause());
                        Log.d(TAG, " getStackTrace = " + exception.getStackTrace());
                    } 
                 } 
                });
       } catch (MalformedURLException e) {
           Log.d(TAG, " MalformedURLException " + e.toString());
       }
       this.stopSelf();
    }

      @Override
        public void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
            Log.d(TAG, "FirstService destroyed");
        }
}

清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bn7.rotareceiver"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name=".RotaReceiver" android:enabled="true" android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <service android:name=".ServiceRota"  android:process=":Service_Rota"></service>
    </application>

</manifest>

错误 Exception.toString = com.microsoft.windowsazure.mobileservices.MobileServiceException:处理请求时出错。 Exception.getCause = java.net.UnknownHostException:bn7.azure-mobile.net Exception.getStackTrace = [Ljava.lang.StackTraceElement; @ 40519770

1 个答案:

答案 0 :(得分:1)

正如错误说明已经说明的那样,您在解决移动服务网址时遇到问题,而不是移动服务本身。

我的建议是您的Android设备在启动完成事件时没有建立的Internet连接。在实例化MobileServiceClient之前尝试检查Internet连接,here是相应的代码。如果出现此问题,请尝试延迟即时消息或等到服务中的连接。