Prakhar Prakhar - 25 days ago 12
Android Question

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..

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:

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

Answer

The Problem is solved now. I added intent filter action and it is working fine.

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>
Comments