Giter Club home page Giter Club logo

androidwebserver's Introduction

androidwebserver's People

Contributors

bodeme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidwebserver's Issues

index.html poping as a download file

Hi, I was trying the app, which i found awesome. My plan is to run a miniwebsite inside the classroom using my Andro-mobile and school wifinetwork.
While testing: Opening my Firefox and writing the local server address and port (example : 192.168.1.110:8080) nothing is loading.
If i write : 192.168.1.110:8080/ inde (purposefully wrong) -> i get the 404 page which a good sign.
if i write : 192.168.1.110:8080/index.html -> rather than opening the page on the Firefox, i get download pop message.
Also, it is possible to navigate between page inside the same root directory and is this code supporting php, apache, sql??

// modify notification for SDK 23+

/*

  • Copyright (C) 2009-2014 Markus Bode
  • Licensed under the GNU General Public License v3
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see http://www.gnu.org/licenses/.

*/

package com.bolutions.webserver;

import android.app.AlertDialog;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.*;

public class ServerService extends Service {

private int NOTIFICATION_ID = 4711;
private NotificationManager mNM;
private String message;
private Notification notification;
private Server server;
private boolean isRunning = false;

@Override
public void onCreate() {
    mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    showNotification();
}

private void showNotification() {
	updateNotifiction("");
  // startForeground(NOTIFICATION_ID, notification);
}

public void startServer(Handler handler, String documentRoot, int port) {
	try {
		isRunning = true;
		WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
		WifiInfo wifiInfo = wifiManager.getConnectionInfo();
		
		String ipAddress = intToIp(wifiInfo.getIpAddress());

		if( wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) {
			new AlertDialog.Builder(this).setTitle("Error").setMessage("Please connect to a WIFI-network for starting the webserver.").setPositiveButton("OK", null).show();
			throw new Exception("Please connect to a WIFI-network.");
		}
        
	    server = new Server(handler, documentRoot, ipAddress, port, getApplicationContext());
	    server.start();
	    
        Intent i = new Intent(this, StartActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

        updateNotifiction("Webserver is running on port " + ipAddress + ":" + port);
        
    	Message msg = new Message();
    	Bundle b = new Bundle();
    	b.putString("msg", "Webserver is running on port " + ipAddress + ":" + port);
    	msg.setData(b);
    	handler.sendMessage(msg);
    	
	} catch (Exception e) {
		isRunning = false;
		Log.e("Webserver", e.getMessage());
        updateNotifiction("Error: " + e.getMessage());
	}
	
}

public static String intToIp(int i) {
    return ((i       ) & 0xFF) + "." +
           ((i >>  8 ) & 0xFF) + "." +
           ((i >> 16 ) & 0xFF) + "." +
           ( i >> 24   & 0xFF);
}

public void stopServer() {
	if(null != server) {
		server.stopServer();
		server.interrupt();
		isRunning = false;
	}
}

public void updateNotificationold(String message) {
    CharSequence text = message;

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, StartActivity.class), 0);
    if (notification == null) {
        notification = new Notification(R.mipmap.ic_launcher, text, System.currentTimeMillis());
       // notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent);

        mNM.notify(NOTIFICATION_ID, notification);
    } else {
    	// notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent);
    	mNM.notify(NOTIFICATION_ID, notification);
    }
	
}
public void updateNotifiction(String message) {
    // In this sample, we'll use the same text for the ticker and the expanded notification
    CharSequence text = message;

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, StartActivity.class), 0);

    // Set the info for the views that show in the notification panel.
    notification = new Notification.Builder(this)
		.setSmallIcon(R.mipmap.ic_launcher)  // the status icon
		.setTicker(text)  // the status text
		.setWhen(System.currentTimeMillis())  // the time stamp
		.setContentTitle("Noti")  // the label of the entry
		.setContentText(text)  // the contents of the entry
		.setContentIntent(contentIntent)  // The intent to send when the entry is clicked
		.build();

    // Send the notification.
    mNM.notify(NOTIFICATION_ID, notification);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LocalService", "Received start id " + startId + ": " + intent);
    return START_NOT_STICKY;
}

@Override
public void onDestroy() {
    // Cancel the persistent notification.
    mNM.cancel(NOTIFICATION_ID);

    // Tell the user we stopped.
    Toast.makeText(this, "Service Stop", Toast.LENGTH_SHORT).show();
}

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

private final IBinder mBinder = new LocalBinder();

public class LocalBinder extends Binder {
	ServerService getService() {
        return ServerService.this;
    }
}

public boolean isRunning() {
	return isRunning;
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.