Running the "groups" command, I could see that my groupset only contained my own personal group:
$ groups
credentiality
I found that I could run "newgrp dialout" to get it added to my groupset:
$ groups
Update: Created a code.google.com project to keep stuff like this. Also, I got color syntax hilighting to work. See the README.txt in the vim/ directory of the repository.
Tonight I managed to compile vim to run natively on my android phone! My phone is rooted and running cyanogenmod CM6 rc3. Rooting is necessary to run vim, but cyanogen probably isn't necessary.
First I had to compile ncurses using the ndk. Follow that link and compile ncurses the way I did if you want to have any hope of compiling vim using these instructions.
Once I had ncurses built, I had to make just a few changes to vim to get it to work.
I downloaded vim from the mercurial archive, which as of today is pretty much the same as the 7.3 release, I think. I figured out how to call configure by trial and error:
vim_cv_memcpy_handles_overlap=no \ vim_cv_bcopy_handles_overlap=no \ vim_cv_memmove_handles_overlap=no \ vim_cv_stat_ignores_slash=no \ vim_cv_getcwd_broken=no \ vim_cv_tty_group=world \ vim_cv_terminfo=yes \ LDFLAGS="-L/path/to/ncurses-5.7/lib" \ CFLAGS="-I/path/to/ncurses-5.7/lib" \ vim_cv_toupper_broken=no \ CC=agcc.pl \ ./configure --host=arm-eabi --with-tlib=ncurses
$as_echo_n "checking uint32_t is 32 bits... " >&6; } if test "$cross_compiling" = yes; then : true # as_fn_error "could not compile program using uint32_t." "$LINENO" 5 else
I think that was it! Once it finished compiling, I copied over the runtime/ directory and the src/vim binary to /data/vim on my phone. I did an "export VIMRUNTIME=/data/vim/runtime", and vim worked great!
Once I got my VIMRUNTIME set, I was able to ":syntax on", although I'm not getting any color. But otherwise it seems to work great!
You can find a tarball of vim for android on the Downloads page: look for vim-7.3-android-binary.tar.gz. There's also a tarred-up copy of my build directory, although I'm not sure why anyone would want that.
CC=agcc.pl ./configure --host=arm-eabi --without-cxx-binding
$ adb pull /dev/mtd/mtd2 boot.img-from-phone
$ adb reboot bootloader [wait for bootloader to come up] $ sudo ./fastboot flash boot boot.img-from-phone $ sudo ./fastboot reboot
$ ./split_bootimg.pl boot.img Page size: 2048 (0x00000800) Kernel size: 2206592 (0x0021ab80) Ramdisk size: 167182 (0x00028d0e) Second size: 0 (0x00000000) Board name: Command line: no_console_suspend=1 msmsdcc_sdioirq=1 wire.search_count=5 Writing boot.img-kernel ... complete. Writing boot.img-ramdisk.gz ... complete.
$ sudo ./fastboot flash boot my-boot.img $ sudo ./fastboot reboot
# mount -oremount,rw /system # cp /system/lib/modules/bcm4329.ko /sdcard/bcm4329.ko-orig
# mount -oremount,ro /system
#include <stdio.h> int main() { printf("Hello, world!\n"); }
# cd /data # ./hello Hello, world!
weight = temperature_variance / (temperature_variance + thermometer_variance) 0.29 = 2 / (2+5)
estimate = guess + weight*(measurement - guess) 72.87 = 72 + 0.29*(75-72) or equivalently estimate = (1-weight)*guess + weight*measurement 72.87 = 0.71*72 + 0.29*75
temperature_variance*thermometer_variance estimate_variance = ----------------------------------------- (temperature_variance + thermometer_variance) 1.43 = 2*5 / (2+5)
weight = temperature_variance / (temperature_variance + thermometer_variance) 0.22 = 1.43 / (1.43+5)
estimate = guess + weight*(measurement - guess) 72.46 = 72.87 + 0.22*(71-72.87)
temperature_variance*thermometer_variance estimate_variance = ----------------------------------------- (temperature_variance + thermometer_variance) 1.11 = 1.43*5 / (1.43+5)
#!/usr/bin/octave global a = 1 global b = 0 global c = 0 function z = polynomial (i,j) global a global b global c x = i + (j * 1j); z = a*x*x + b*x + c; end [I,J] = meshgrid(-1:0.2:1); REAL = arrayfun(@real, arrayfun(@polynomial, I, J)); IMAG = arrayfun(@imag, arrayfun(@polynomial, I, J)); vtk_surf(I,J+IMAG,REAL, IMAG); input ("Orient it the way you want it before I save."); vtk_print('polynomial.jpg', '-djpeg'); input ("Done!");
#!/usr/bin/python
import Tkinter
import ImageTk,Image
root = Tkinter.Tk()
root.geometry('+640+480')
old_label = None
label = None
photo = None
def display_image(root, image):
global old_label
global label
global photo
root.geometry('%dx%d' % (image.size[0], image.size[1]))
photo = ImageTk.PhotoImage(image)
label = Tkinter.Label(root, image=photo)
label.place(x=0,y=0,width=image.size[0],height=image.size[1])
if old_label is not None:
old_label.destroy()
old_label = label
def image_loop():
global root
print '.'
image = get_image()
display_image(root, image)
root.after(1000,image_loop)
image_loop()
root.mainloop()
while true ; do nc -q 0 -l -p 12345 < foo.jpg ; done
#!/usr/bin/python
import socket
from PIL import ImageFile
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp.connect(('127.0.0.1', 12345))
tcp.send("1000 4")
file = open("bar.jpg", "w")
parser = ImageFile.Parser()
while 1:
jpgdata = tcp.recv(65536)
if not jpgdata:
tcp.close()
break
parser.feed(jpgdata)
file.write(jpgdata)
file.close()
image = parser.close()
image.show()
$ watch -n 0.3 xrefresh -geometry 1x1+500+500
$ sudo apt-get install automake autoconf libtool gettext pkg-config subversion build-essential
$ mkdir gphoto-svn
$ cd gphoto-svn
$ svn checkout https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/libgphoto2
$ cd libgphoto2
$ autoreconf -is
$ mkdir -p /tmp/gphoto2/local
$ ./configure --prefix=/tmp/gphoto2/local
$ make
$ make install
$ # neat, libgphoto2 installed to /tmp/gphoto2/local
$ cd ..
$ svn checkout https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/gphoto2
$ cd gphoto2
$ autoreconf -is
$ ./configure --prefix=/tmp/gphoto2/local --with-libgphoto2=/tmp/gphoto2/local
$ make
$ # make install is optional; I just ran ./gphoto2/gphoto2 directly
$ # edited files, then "make" to rebuild
This one fits the poem with a coat of mail
Of erudition; that one, with gala pomps and circumstance.
Both flail their absurd pennons to no avail,
Neglecting, poor wretches, the factor sublime -- its LOVELINESS!
#!/usr/bin/python
"""
Released into the public domain, 12 June 2010
This program calculates the sine and cosine of an angle in a geometrically
intuitive way.
Here's how it works:
Start with a unit circle and observe that the points (1,0) and (0,1) on the
circumference of the circle are separated by 90 degrees.
The midpoint between those two points, (0.5, 0.5), bisects that 90
degree angle, forming two 45 degree angles. We can extend the line from
the origin through (0.5, 0.5) until it reaches the circumference of the unit
circle (that is, until its distance from the origin is 1), and we get
(0.707, 0.707). Thus we know that the cosine and sine of 45 degrees are both
0.707.
Likewise, we can find the cosine and sine of 22.5 degrees by taking
the midpoint between (0.707, 0.707) and (1,0), then scaling the line until
it reaches the circumference. And we can find the cosine and sine of
67.5 degrees by taking the midpoint between (0.707, 0.707) and (0, 1).
We can continue to bisect angles until we get arbitrarily close to any
angle we choose. The allowable angular error is set below as MAX_THETA_ERROR.
Note that this method is agnostic to the angular units we use. If we start off
by telling the program that (0,1) and (1,0) are separated by an angle of 90,
then the program will return a result measured in degrees.
If instead we say that (0,1) and (1,0) are separated by pi/2, we'll get a
result in radians.
"""
import math
MAX_THETA_ERROR=0.01
def cos_sin(theta, x1,y1,theta1, x2,y2,theta2):
"""cos_sin returns the (cosine,sine) of a value within MAX_THETA_ERROR
units of theta, given two points (x1,y1) and (x2,y2) that live
at angular posisions theta1 and theta2 on the unit circle. theta,
theta1 and theta2 must all have the same kind of angular unit (degrees,
radians, etc.), but this function doesn't care what that unit is or
how many of them make up a circle.
theta2 must be greater than theta1, and (x1,y1) and (x2,y2) must be
points on the circumference of the unit circle, less than 180 degrees
apart.
for example, cos_sin(30.0, 0.0,1.0,0.0, 1,0,0.0,90.0) returns
(0.866089312575, 0.499889290387), which are the cosine and sine of 30.
"""
# Uncomment this to see the successive approximations
#print "target: %.2f. (%.2f, %.2f)=%.2f (%.2f,%.2f)=%.2f" % \
# (theta, x1, y1, theta1, x2, y2, theta2)
# if one of the points is close enough to theta, we're done!
if (abs(theta1 - theta) < MAX_THETA_ERROR):
return (x1,y1)
if (abs(theta2 - theta) < MAX_THETA_ERROR):
return (x2,y2)
# the midpoint is just the average of the two points
x_midpoint = (x1 + x2) / 2.0;
y_midpoint = (y1 + y2) / 2.0;
# scale (x_midpoint,y_midpoint) by 1/midpoint_length to get a point
# exactly 1 unit away from the origin
midpoint_length = math.sqrt(x_midpoint*x_midpoint + y_midpoint*y_midpoint)
x_midpoint = x_midpoint / midpoint_length
y_midpoint = y_midpoint / midpoint_length
# the midpoint bisects the angle between the two points
theta_midpoint = (theta1 + theta2) / 2.0;
# figure out which side of the midpoint our target value theta lives on,
# and bisect the extended midpoint with one of the original points to get
# closer to the target
if (theta >= theta_midpoint):
return cos_sin(theta, x_midpoint, y_midpoint, theta_midpoint, x2, y2, theta2)
else:
return cos_sin(theta, x1, y1, theta1, x_midpoint, y_midpoint, theta_midpoint)
angle = 30.0
(cosine, sine) = cos_sin(angle, 1.0,0.0,0.0, 0.0,1.0,90.0)
print "The cosine of %.2f is %.2f" % (angle, cosine)
print "The sine of %.2f is %.2f" % (angle, sine)
// Just some math to turn wheel odometry into position updates
// Released into the public domain 3 June 2010
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define PI (3.14159)
#define WHEELBASE (12.0)
// left wheel
double Lx = -WHEELBASE/2.0;
double Ly = 0.0;
// right wheel
double Rx = WHEELBASE/2.0;
double Ry = 0.0;
// given distances traveled by each wheel, updates the
// wheel position globals
void update_wheel_position(double l, double r) {
if (fabs(r - l) < 0.001) {
// If both wheels moved about the same distance, then we get an infinite
// radius of curvature. This handles that case.
// find forward by rotating the axle between the wheels 90 degrees
double axlex = Rx - Lx;
double axley = Ry - Ly;
double forwardx, forwardy;
forwardx = -axley;
forwardy = axlex;
// normalize
double length = sqrt(forwardx*forwardx + forwardy*forwardy);
forwardx = forwardx / length;
forwardy = forwardy / length;
// move each wheel forward by the amount it moved
Lx = Lx + forwardx * l;
Ly = Ly + forwardy * l;
Rx = Rx + forwardx * r;
Ry = Ry + forwardy * r;
return;
}
double rl; // radius of curvature for left wheel
rl = WHEELBASE * l / (r - l);
printf("Radius of curvature (left wheel): %.2lf\n", rl);
double theta; // angle we moved around the circle, in radians
// theta = 2 * PI * (l / (2 * PI * rl)) simplifies to:
theta = l / rl;
printf("Theta: %.2lf radians\n", theta);
// Find the point P that we're circling
double Px, Py;
Px = Lx + rl*((Lx-Rx)/WHEELBASE);
Py = Ly + rl*((Ly-Ry)/WHEELBASE);
printf("Center of rotation: (%.2lf, %.2lf)\n", Px, Py);
// Translate everything to the origin
double Lx_translated = Lx - Px;
double Ly_translated = Ly - Py;
double Rx_translated = Rx - Px;
double Ry_translated = Ry - Py;
printf("Translated: (%.2lf,%.2lf) (%.2lf,%.2lf)\n",
Lx_translated, Ly_translated,
Rx_translated, Ry_translated);
// Rotate by theta
double cos_theta = cos(theta);
double sin_theta = sin(theta);
printf("cos(theta)=%.2lf sin(theta)=%.2lf\n", cos_theta, sin_theta);
double Lx_rotated = Lx_translated*cos_theta - Ly_translated*sin_theta;
double Ly_rotated = Lx_translated*sin_theta + Ly_translated*sin_theta;
double Rx_rotated = Rx_translated*cos_theta - Ry_translated*sin_theta;
double Ry_rotated = Rx_translated*sin_theta + Ry_translated*sin_theta;
printf("Rotated: (%.2lf,%.2lf) (%.2lf,%.2lf)\n",
Lx_rotated, Ly_rotated,
Rx_rotated, Ry_rotated);
// Translate back
Lx = Lx_rotated + Px;
Ly = Ly_rotated + Py;
Rx = Rx_rotated + Px;
Ry = Ry_rotated + Py;
}
main(int argc, char **argv) {
if (argc != 3) {
printf("Usage: %s left right\nwhere left and right are distances.\n",
argv[0]);
return 1;
}
double left = atof(argv[1]);
double right = atof(argv[2]);
printf("Old wheel positions: (%lf,%lf) (%lf,%lf)\n",
Lx, Ly, Rx, Ry);
update_wheel_position(left, right);
printf("New wheel positions: (%lf,%lf) (%lf,%lf)\n",
Lx, Ly, Rx, Ry);
}
#include <avr/interrupt.h> #include <avr/signal.h> // Just count the number of interrupts we see int interrupt_counter = 0; SIGNAL(SIG_INTERRUPT0) { interrupt_counter++; } // I got lots of random resets until I added this handler. So apparently you shouldn't enable // an interrupt unless you have a handler installed. SIGNAL(SIG_INTERRUPT1) { interrupt_counter++; } And then in my init code: #define _BV(x) (1 << (x)) // setup for servicing INT0, INT1 interrupt pins // generate an interrupt on any logical change MCUCR |= _BV(ISC10); MCUCR &= ~_BV(ISC11); MCUCR |= _BV(ISC00); MCUCR &= ~_BV(ISC01); // enable the interrupt pins GICR |= _BV(INT1) | _BV(INT0); // Set d2 and d3 to be inputs DDRD &= ~(_BV(PD2) | _BV(PD3)); // Pullups off PORTD &= ~(_BV(PD2) | _BV(PD3));
$ sudo bash
sudo: /etc/sudoers is mode 0640, should be 0440
Segmentation fault
$ mkfifo foo
set fifo [open "foo" {RDWR NONBLOCK}]
fconfigure $fifo -blocking 1
proc read_fifo {} {
global fifo
gets $fifo x
puts "x is $x"
}
fileevent $fifo readable read_fifo
$ echo "asdf" > foo
/*
* V4L2 video capture example
*
* This program can be used and distributed without restrictions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/types.h> /* for videodev2.h */
#include <linux/videodev2.h>
#define CLEAR(x) memset (&(x), 0, sizeof (x))
struct buffer {
void *start;
size_t length;
};
static int fd = -1;
struct buffer *buffers = NULL;
static unsigned int n_buffers = 0;
static void errno_exit(const char *s) {
fprintf (stderr, "%s error %d, %s\n", s, errno, strerror (errno));
exit (EXIT_FAILURE);
}
static int xioctl(int fd, int request, void * arg) {
int r;
do r = ioctl (fd, request, arg);
while (-1 == r && EINTR == errno);
return r;
}
static void process_image(const void *p) {
fputc ('.', stdout);
fflush (stdout);
}
static int read_frame(void) {
struct v4l2_buffer buf;
unsigned int i;
if (-1 == read (fd, buffers[0].start, buffers[0].length)) {
switch (errno) {
case EAGAIN:
return 0;
case EIO:
/* Could ignore EIO, see spec. */
/* fall through */
default:
errno_exit ("read");
}
}
process_image (buffers[0].start);
return 1;
}
static void mainloop(void) {
unsigned int count;
count = 100;
while (count-- > 0) {
for (;;) {
fd_set fds;
struct timeval tv;
int r;
FD_ZERO (&fds);
FD_SET (fd, &fds);
/* Timeout. */
tv.tv_sec = 2;
tv.tv_usec = 0;
r = select (fd + 1, &fds, NULL, NULL, &tv);
if (-1 == r) {
if (EINTR == errno)
continue;
errno_exit ("select");
}
if (0 == r) {
fprintf (stderr, "select timeout\n");
exit (EXIT_FAILURE);
}
if (read_frame ())
break;
/* EAGAIN - continue select loop. */
}
}
}
static void uninit_device(void) {
unsigned int i;
free (buffers[0].start);
free (buffers);
}
static void init_read(unsigned int buffer_size) {
buffers = calloc (1, sizeof (*buffers));
if (!buffers) {
fprintf (stderr, "Out of memory\n");
exit (EXIT_FAILURE);
}
buffers[0].length = buffer_size;
buffers[0].start = malloc (buffer_size);
if (!buffers[0].start) {
fprintf (stderr, "Out of memory\n");
exit (EXIT_FAILURE);
}
}
static void init_device(char *dev_name) {
struct v4l2_capability cap;
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format fmt;
unsigned int min;
if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
fprintf (stderr, "%s is no V4L2 device\n",
dev_name);
exit (EXIT_FAILURE);
} else {
errno_exit ("VIDIOC_QUERYCAP");
}
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
fprintf (stderr, "%s is no video capture device\n",
dev_name);
exit (EXIT_FAILURE);
}
if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
fprintf (stderr, "%s does not support read i/o\n",
dev_name);
exit (EXIT_FAILURE);
}
/* Select video input, video standard and tune here. */
CLEAR (cropcap);
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect; /* reset to default */
if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
switch (errno) {
case EINVAL:
/* Cropping not supported. */
break;
default:
/* Errors ignored. */
break;
}
}
} else {
/* Errors ignored. */
}
CLEAR (fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = 640;
fmt.fmt.pix.height = 480;
// This worked with my capture card, but bombed with
// "VIDIOC_S_FMT error 22, Invalid argument" on my Logitech QuickCam Pro 4000
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
// This worked on the logitech:
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
errno_exit("VIDIOC_S_FMT");
/* Note VIDIOC_S_FMT may change width and height. */
/* Buggy driver paranoia. */
min = fmt.fmt.pix.width * 2;
if (fmt.fmt.pix.bytesperline < min)
fmt.fmt.pix.bytesperline = min;
min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
if (fmt.fmt.pix.sizeimage < min)
fmt.fmt.pix.sizeimage = min;
init_read (fmt.fmt.pix.sizeimage);
}
static void close_device(void) {
if (-1 == close (fd))
errno_exit ("close");
fd = -1;
}
static void open_device(char *dev_name) {
struct stat st;
if (-1 == stat (dev_name, &st)) {
fprintf (stderr, "Cannot identify '%s': %d, %s\n",
dev_name, errno, strerror (errno));
exit (EXIT_FAILURE);
}
if (!S_ISCHR (st.st_mode)) {
fprintf (stderr, "%s is no device\n", dev_name);
exit (EXIT_FAILURE);
}
fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd) {
fprintf (stderr, "Cannot open '%s': %d, %s\n",
dev_name, errno, strerror (errno));
exit (EXIT_FAILURE);
}
}
int main(int argc, char **argv) {
char *dev_name = "/dev/video1";
open_device(dev_name);
init_device(dev_name);
mainloop();
uninit_device();
close_device();
exit(EXIT_SUCCESS);
return 0;
}
error: no such device: ....
Failed to boot default entries.
search --no-floppy --fs-uuid --set ...
/libux/boot/vmlinuz-... root=/dev/sda1 ro quiet splash
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
GRUB_DISABLE_LINUX_UUID=true
echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
echo ""
# Launch an activity in the background:
$ am start -a com.google.ase.action.LAUNCH_SCRIPT -n com.google.ase/.activity.AseServiceLauncher -e com.google.ase.extra.SCRIPT_NAME test.py
# Launch an activity in a new terminal:
$ am start -a com.google.ase.action.LAUNCH_TERMINAL -n com.google.ase/.activity.AseServiceLauncher -e com.google.ase.extra.SCRIPT_NAME test.py
// DON'T FORGET TO INCLUDE THE INTERNET PERMISSION IN YOUR MANIFEST.XML
package com.example.HelloFormStuff;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromContainsFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
public class HelloFormStuffActivity extends Activity {
public int state = 0;
private static final String TAG = "HelloFormStuffActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(new Runnable() {
public void run() {
//XMPPConnection xmpp = new XMPPConnection("jabber.iitsp.com");
XMPPConnection xmpp = new XMPPConnection("gmail.com");
try {
xmpp.connect();
// for other jabber accounts, truncate after the @
//xmpp.login("username", "password");
// for gtalk / gmail, include the @
xmpp.login("your-gmail-account@gmail.com", "your-gmail-password");
} catch (XMPPException e) {
Log.v(TAG, "Failed to connect to " + xmpp.getHost());
e.printStackTrace();
}
ChatManager chatmanager = xmpp.getChatManager();
Chat newChat = chatmanager.createChat("friend@gmail.com", new MessageListener() {
// THIS CODE NEVER GETS CALLED FOR SOME REASON
public void processMessage(Chat chat, Message message) {
try {
Log.v(TAG, "Got:" + message.getBody());
chat.sendMessage(message.getBody());
} catch (XMPPException e) {
Log.v(TAG, "Couldn't respond:" + e);
}
Log.v(TAG, message.toString());
}
});
// Send something to friend@gmail.com
try {
newChat.sendMessage("OMNOMNOM");
} catch (XMPPException e) {
Log.v(TAG, "couldn't send:" + e.toString());
}
// Accept only messages from friend@gmail.com
PacketFilter filter
= new AndFilter(new PacketTypeFilter(Message.class),
new FromContainsFilter("friend@gmail.com"));
// Collect these messages
PacketCollector collector = xmpp.createPacketCollector(filter);
while(true) {
Packet packet = collector.nextResult();
if (packet instanceof Message) {
Message msg = (Message) packet;
// Process message
Log.v(TAG, "Got message:" + msg.getBody());
}
}
}
}).start();
//setContentView(this);
}
}
package com.example.HelloFormStuff;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
public class HelloFormStuffActivity extends Activity {
public int state = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
XMPPConnection xmpp = new XMPPConnection("jabber.iitsp.com");
try {
xmpp.connect();
xmpp.login("username","password"); // just username, no @ sign
} catch (XMPPException e) {
// TODO Auto-generated catch block
System.out.println("Failed to connect to " + xmpp.getHost());
e.printStackTrace();
}
ChatManager chatmanager = xmpp.getChatManager();
Chat newChat = chatmanager.createChat("destination@example.com", new MessageListener() {
public void processMessage(Chat chat, Message message) {
Toast.makeText(HelloFormStuffActivity.this, message.toString(), Toast.LENGTH_SHORT).show();
}
});
try {
newChat.sendMessage("IMing from my android");
} catch (XMPPException e) {
Toast.makeText(HelloFormStuffActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
...