簡體   English   中英

在啟動時將Windows Azure Mobile與Android服務結合使用會受到限制嗎?

[英]There is limitation in the use of Windows Azure Mobile with Android service that start at boot?

我編寫了一個與Windows Azure移動服務進行通信的Android應用程序,該應用程序通常在設備和android Azure數據庫之間發送數據,但是當我插入相同的代碼時,啟動時自動啟動的服務無法運行。 我在啟動時啟動的Android服務沒有問題。 Windows Azure Services Android服務沒有問題。

但是,當兩者(服務在啟動時啟動Android + Windows Azure Services)都無法運行時。

我需要幫助!

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

正如錯誤描述已經說明的那樣,您在解決移動服務URL而不是移動服務本身時遇到了問題。

我的建議是,您的Android設備在啟動完成事件中沒有建立的Internet連接。 實例化MobileServiceClient之前,請嘗試檢查Internet連接, 是相應的代碼。 如果這是問題,請嘗試延遲實例化或等待直到服務中的連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM