0

TI の OMAP4460 プロセッサで Android 4.2 を使用しています。私の目標は、ブート直後に、マルチキャスト ソケットで SSDP クエリをリッスンするサービスを開始することです。これはできますが、作成MulticastSocketしようとすると例外が発生します。例外は、基になるdatagramSocket. 以下にいくつかのコード スニペットを示します。

<receiver          android:name="com.example.reciever.StartServicesAtBootReceiver" android:enabled="true" android:exported="false" android:label="StartServicesAtBootRemoteReceiver" >
    <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />

       <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</receiver>

onRecieve()はこのように見えます:

public void onReceive(Context context, Intent intent) {

    Intent ServiceIntent = new Intent(context,
            myService.class);
    ComponentName serviceStarted = context
            .startService(ServiceIntent);
    if (serviceStarted != null)

}

そして最後に、サービス スニペット:

public int onStartCommand(Intent intent, int flags, int startId) {
    try {
        if (null == ssdpServer) {
            ssdpServer = new UDPListenThread();
            ssdpServer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

public class UDPListenThread extends Thread {

    protected MulticastSocket socket = null;

    public UDPListenThread() throws IOException {
        this("UDPListenThread");
    }

    public UDPListenThread(String name) throws IOException {
        super(name);
    }

    @Override
    public void run() {

            Socket mySocket = new Socket();
            socket = new MulticastSocket(SSDP_PORT);
            // socket.setLoopbackMode(false);
            socket.joinGroup(InetAddress.getByName(SSDP_ADDRESS));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

注: はSocket割り当てられます (ここでは使用されていないため、有効かどうかは不明です)。また、試してみると:

ConnectivityManager cm = (ConnectivityManager) getBaseContext()
    .getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetwork = cm.getActiveNetworkInfo();

サービスまたは受信者から。activeNetworkとして戻ってきnullます。このように(サービスから)待っていてもactiveNetwork

        NetworkInfo activeNetwork = null;
        while (null == activeNetwork) {
            ConnectivityManager cm = (ConnectivityManager) getBaseContext()
                    .getApplicationContext().getSystemService(
                            Context.CONNECTIVITY_SERVICE);

            activeNetwork = cm.getActiveNetworkInfo();
            Log.d(this.getClass().getSimpleName(), "activeNetwork "
                    + activeNetwork);

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

ブラウザーを起動して UI から検索できるようになった後でも、null のままです。

フォローアップ: カーネル ビルドが不適切であることが判明しました。ゴミの山の上に構築すると、不安定な構造になると思います。:)

4

1 に答える 1