Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 08-13-2010, 06:13 AM   #1
New Member
 
Join Date: Aug 2010
Posts: 1
Friends: 0
View sgg_btech's Profile   View sgg_btech's Photo Album   View sgg_btech's Blog   View Social Groups
Hi,

My aim is to take a photo using the native android camera by using the Key or motion events. But it is not possible. I tried with junit testing.
Code for invoking camera

**package com.two.camera;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class CameraTwo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent();
i.setClassName("com.android.camera","com.android.c amera.Camera");
startActivity(i);
}
}**

I tried to send key events by writing a Android unit testing project with code.

package com.two.camera.test;

import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;

import com.two.camera.CameraTwo;


public class TestOne extends ActivityInstrumentationTestCase2<CameraTwo> {
private static final String CODE_1 = "KEYCODE_DPAD_CENTER";
private static final String CODE_2 = "KEYCODE_HOME";

public TestOne() {
super ("com.two.camera", CameraTwo.class);
}

@Override
protected void setUp() throws Exception {
super.setUp();
CameraTwo mainActivity = getActivity();
}
public void takephoto() {

sendKeys(CODE_1);
sleep(1000);
sleep(1000);
sendKeys(CODE_2);
// now on Add button
sendKeys("ENTER");

//SECOND METHOD
Instrumentation i = new Instrumentation();
i.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);

//THIRD METHOD
KeyEvent eventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
KeyEvent eventUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER);
dispatchKeyEvent(eventDown);
dispatchKeyEvent(eventUp);

Object j = null;
// JUST FOR TESTING THAT CODE IS MOVED UPTO HERE OR NOT
assertTrue("Add result should be 98", j.equals(1));
}

private void dispatchKeyEvent(KeyEvent eventDown) {
// TODO Auto-generated method stub
return;
}

private void sleep(int i) {
// TODO Auto-generated method stub
return;
}
}

I tried by executing the above test using Right click -> run as android junit test and from command line using

$ adb shell am instrument com.two.camera.test/android.test.InstrumentationTestRunner

Please guide me in this regard Thanks in advance
sgg_btech is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
SmartCam: Motion sensing camera app rarunach Android Games And Applications 2 12-05-2009 02:35 PM
Input Method Framework swaroop Android Development, Answers, Tutorials, and Code Snippets 1 11-11-2009 07:33 AM
Method of locking ringer volume? ffolliet G1 2 05-10-2009 01:04 AM
While loop in the onCreate method jdc3 Android Development, Answers, Tutorials, and Code Snippets 0 04-03-2009 09:17 AM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 08:32 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.