简体   繁体   English

无法在Android中启动Web服务器服务

[英]Unable to start webserver service in android

i am developing a android app that makes a phone webserver it works fine when i use it without the service but i want to use service so that my webserver runs in background this is my code please have a look at it.. 我正在开发一个使手机网络服务器正常运行的android应用,当我不使用该服务而使用它时,但我想使用服务,以便我的网络服务器在后台运行,这是我的代码,请看一下。

Serivice runner class: 服务赛跑者课程:

package dolphin.developers.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import dolphin.devlopers.com.R;

public class web extends Activity implements OnClickListener  {
    public static final int progress_bar_type1 = 0;
    private static final String TAG = null; 


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.hotmail);

        Button btnShowProgressa;

        Button buttonStop = (Button) findViewById(R.id.button1ad);
        buttonStop.setOnClickListener(this);

        btnShowProgressa = (Button) findViewById(R.id.button2);
        btnShowProgressa.setOnClickListener(this);

    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        switch (arg0.getId()) {
        case R.id.button2:
          Log.d(TAG, "onClick: starting srvice");
          startService(new Intent(this, webser.class));
          break;
        case R.id.button1ad:
          Log.d(TAG, "onClick: stopping srvice");
          stopService(new Intent(this, webser.class));
          break;
        }

    }


    } 

Webserver service: 网络服务器服务:

package dolphin.developers.com;

import java.io.File;
import java.io.IOException;

import android.app.Service;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class webser extends Service {


    Thread hi;
    private static final String TAG = null;
    JHTTP pro;

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


    @Override
    public void onCreate() {

        Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

        Log.d(TAG, "onCreate");

           hi= new Thread(){


            public void run(){







            try{
                File documentRootDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/");
                  pro = new JHTTP(documentRootDirectory, 1234);

            }
            catch(IOException e ){
                e.printStackTrace();
            }


         }


}; hi.start();


    }




      @SuppressWarnings("deprecation")
    @Override

        public void onDestroy() {
        Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onDestroy");

        readysteadypo.stop();
        pro.stop();
      }


      @Override
        public void onStart(Intent intent, int startid) {
            Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
            Log.d(TAG, "onStart");
            pro.start();
        }




} 

Manifest file: 清单文件:

<Service 
  android:name="dolphin.developers.com.webser"/>

Logcat: Logcat:

08-05 13:04:12.221: W/ActivityManager(73): Unable to start service Intent { cmp=dolphin.devlopers.com/dolphin.developers.com.hot1 }: not found

The Problem is solved now. 现在问题已解决。 I added intent filter action and it is working fine. 我添加了intent filter操作,它工作正常。

Here goes the code: 代码如下:

<service android:name="dolphin.developers.com.webser" android:enabled="true">
    <intent-filter>
        <action android:name="dolphin.developers.com.webserv"></action>
    </intent-filter>
</service>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM