elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Historial del navegador en: 31 Enero 2014, 12:03 pm
Alguien sabe si se puede saber que url he visitado con mi navegador o poder ver el historial de navegacion con un programa hecho en java?
2  Comunicaciones / Android / Re: Login en android en: 16 Enero 2014, 12:07 pm
esta es la clase main:

public class MainActivity extends Activity {
    EditText un,pw;
    TextView error;
    Button ok;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        un=(EditText)findViewById(R.id.et_un);
        pw=(EditText)findViewById(R.id.et_pw);
        ok=(Button)findViewById(R.id.btn_login);
        error=(TextView)findViewById(R.id.tv_error);
 
        ok.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
 
                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("email", un.getText().toString()));
                postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
                postParameters.add(new BasicNameValuePair("gestion","0"));
                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("192.168.1.108/index.php", postParameters);
                    String res=response.toString();
                    res= res.replaceAll("\\s+","");
                    if(res.equals("1"))
                        error.setText("Correct Username or Password");
                    else
                        error.setText("Sorry!! Incorrect Username or Password");
                } catch (Exception e) {
                    un.setText(e.toString());
                }
 
            }
        });
    }
}

clase HTTP:

public class CustomHttpClient {
    /** The time it takes for our client to timeout */
    public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds
 
    /** Single instance of our HttpClient */
    private static HttpClient mHttpClient;
 
    /**
     * Get our single instance of our HttpClient object.
     *
     * @return an HttpClient object with connection parameters set
     */
    private static HttpClient getHttpClient() {
        if (mHttpClient == null) {
            mHttpClient = new DefaultHttpClient();
            final HttpParams params = mHttpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
        }
        return mHttpClient;
    }
 
    /**
     * Performs an HTTP Post request to the specified url with the
     * specified parameters.
     *
     * @param url The web address to post the request to
     * @param postParameters The parameters to send via the request
     * @return The result of the request
     * @throws Exception
     */
    public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpPost request = new HttpPost(url);
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
            request.setEntity(formEntity);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
 
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
 
            String result = sb.toString();
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
    /**
     * Performs an HTTP GET request to the specified url.
     *
     * @param url The web address to post the request to
     * @return The result of the request
     * @throws Exception
     */
    public static String executeHttpGet(String url) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(url));
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
 
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
 
            String result = sb.toString();
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

este es el XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="210dip"
    android:layout_marginTop="10dip"
    android:background="#DDDDDD">
    <TextView
        android:id="@+id/tv_un"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#444444"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="9dip"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="10dip"
        android:text="User Name:"/>
    <EditText
        android:id="@+id/et_un"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_toRightOf="@id/tv_un"
        android:layout_alignTop="@id/tv_un"/>
     <TextView
        android:id="@+id/tv_pw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#444444"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/tv_un"
        android:layout_marginRight="9dip"
        android:layout_marginTop="15dip"
        android:layout_marginLeft="10dip"
        android:text="Password:"/>
    <EditText
        android:id="@+id/et_pw"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_toRightOf="@id/tv_pw"
        android:layout_alignTop="@id/tv_pw"
        android:layout_below="@id/et_un"
        android:layout_marginLeft="17dip"
        android:password="true"        />
    <Button
        android:id="@+id/btn_login"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_below="@id/et_pw"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="15dip"
        android:layout_marginLeft="110dip"
        android:text="Login" />
     <TextView
        android:id="@+id/tv_error"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:textSize="7pt"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/btn_login"
        android:layout_marginRight="9dip"
        android:layout_marginTop="15dip"
        android:layout_marginLeft="15dip"
        android:textColor="#AA0000"
        android:text=""/>
</RelativeLayout>

trabajo en JAVA y me da el siguiente error al poner el email y el password:

Java.lang.illegalStateException:Target host must not be null or set in parameters scheme=null, host=null, path=212.227.59.52/settings/gestionj.php
3  Comunicaciones / Android / Login en android en: 16 Enero 2014, 10:35 am
Alguien podria indicarme como hacer un login en android que se conecte a una base de datos mediante json? voy MUY perdido llevo 1 mes intentando de todo pero no hay manera. Estaria muy agradecido... :(
Saludos!
4  Programación / Java / Webcam Shots Aleatorios en: 2 Enero 2014, 11:14 am
Hola amigos, llevo 1 mes encallado en el desarrollo de una aplicacion que haga webcam shots aleatorios cada 10 segundos, de momento solo he conseguido que reporoduzca video, y no hay manera de hacer que haga webcamshots, he probado de todo.
Aqui les dejo el codigo que tengo hasta ahora espero qe puedan ayudarme :huh:

import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;

import javax.media.Buffer;
import javax.media.CaptureDeviceInfo;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;






import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class pruebawebcam {
   public static void main(String[] args) {
   // TODO Auto-generated method stu
      otro perro=new otro();
      perro.show();
      perro.proceso();
   
   //    public ImagePanel imgpanel = null;

   }
}
class otro extends JFrame{
   JLabel Imagen;
   otro(){
      Imagen=new JLabel();
      Imagen.setBounds(30,40,20,20);
      add(Imagen);
      setBounds(400,400,400,400);
      setLayout( null ); // use a BorderLayou   
      setTitle("Prueba de Camara Web");
   }
    public void actionPerformed(ActionEvent e)
    {
       JButton capture = null;
      JComponent c = (JComponent) e.getSource();
      capture = new JButton("Capture");
      
      if (c == capture)
      {
         
          CaptureDeviceInfo di = null;
          MediaLocator ml = null;
         
           Player player = null;
           VideoFormat vf = null;
          BufferToImage btoi = null;
      //    ImagePanel imgpanel = null;
         Buffer buf = null;
          Image img = null;
        // Grab a frame
        FrameGrabbingControl fgc = (FrameGrabbingControl)
        player.getControl("javax.media.control.FrameGrabbingControl");
        buf = fgc.grabFrame();
   
        // Convert it to an image
        btoi = new BufferToImage((VideoFormat)buf.getFormat());
        img = btoi.createImage(buf);
   
        // show the image
    //    imgpanel.setImage(img);
   
        // save image
        saveJPG(img,"c:\\test.jpg");
      }
    }
   public void proceso(){
         Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
      try{
         MediaLocator ml = new MediaLocator("vfw://0");
         Player p = Manager.createRealizedPlayer(ml);
         
         Component video = p.getVisualComponent();
         
         video.setBounds(20,30,600,600);
         if ( video != null ){
            // agragar el video al componente
                add( video);
         }
               

         p.start();
      }catch(Exception e){
         e.printStackTrace();
      }
   }
    public static void saveJPG(Image img, String s)
    {
      BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = bi.createGraphics();
      g2.drawImage(img, null, null);
   
      FileOutputStream out = null;
      try
      {
        out = new FileOutputStream(s);
      }
      catch (java.io.FileNotFoundException io)
      {
        System.out.println("File Not Found");
      }
   
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
      param.setQuality(0.5f,false);
      encoder.setJPEGEncodeParam(param);
   
      try
      {
        encoder.encode(bi);
        out.close();
      }
      catch (java.io.IOException io)
      {
        System.out.println("IOException");
      }
    }
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines