Accessing the Front Camera [Coding Question] - Verizon Samsung Galaxy S III

Hey guys,
I have a small app I have been working on that uses the front camera. The way I have been obtaining use of the front camera seems to work on most phones, but users have been reporting trouble on the S3 and various other new devices. The way I have been accessing the front camera is like so:
Code:
// Find the ID of the front camera
CameraInfo cameraInfo = new CameraInfo();
for(int i = 0; i < numberOfCameras; i++) {
Camera.getCameraInfo(i, cameraInfo);
if(cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
defaultCameraId = i;
mCameraFound = true;
}
}
if(!mCameraFound)
displayDialog(8);
From some of the error reporting I've added into the app, I've noticed the S3 actually finds the front camera, but users report it only shows a blank screen? I was hoping someone here may have some experience with this or may be able to help me solve this issue. If you want to try the app out on your S3, check the link below. Thanks in advance.

Related

MapActivity, Buttons and OnClickListener

Hi all,
could you give me some help please? I have written a simple MapActivity that contains a mapview (defined in the xml file); it also contains a Button.
If the Button has no OnClickListener associated then the project runs fine (the mapview is of course empty).
If I add an OnclickListener the application simply Force closes.
Has anyone tried this? I was actually following the example in a book but I guess something has changed in the SDK since it was written?
I m using SDK 1.1 (for the moment).
If you have (recently) written something similar, could you give me some pointers please?
thanks
N
"could you give me some pointers please?"
Might be a nullpointer indeed. Check your LogCat (Eclipse: Window, show view, other, logcat), this will probably give you some nice hints.
LOL
ehhehe
havent checked the log yet, will do and then report back here.
if anyone else has other suggestions please dont hesitate!
thanks
N
LogCat
Vlemmix said:
"could you give me some pointers please?"
Might be a nullpointer indeed. Check your LogCat (Eclipse: Window, show view, other, logcat), this will probably give you some nice hints.
Click to expand...
Click to collapse
Vlemmix,
I checked the LogCat and seems too be a nullpointer indeed, but I cannot identify the mistake in the code.
This is the java source for the class. could you please have a look ?
If I un-comment the commented lines, I get a force close. Leave them uncommented and everything works (no click event on the button tho).
package com.chipset.testgps;
import com.google.android.maps.MapView;
import android.widget.Button;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
public class main extends MapActivity {
@Override
public boolean isRouteDisplayed(){
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Button but = (Button) findViewById(R.id.gpsButton);
// but.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v){
//
// }
// });
final MapView map = (MapView) findViewById(R.id.myMap);
setContentView(R.layout.main);
}
}
Any help please??
thanks
N
1)
First do the setContentView, after that the Button is findable. The system could not find your Button now, so that's why it is a null. Your MapView map also would be a null in your code.
2)
If you define an object within {} it is only available within that {}
You probably going to need the Object "but" later, so make it a private variable of the class.
3)
Classname should start with a capital.
4) Visit anddev.org or some site like that for coding problems, xda seems to be more focused on system/firmware issues, not application code.
So, this should work:
public class MainActivity extends MapActivity {
final Button but;
final MapView map;
@Override
public boolean isRouteDisplayed() {
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
but = (Button) findViewById(R.id.gpsButton);
but.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
}
});
map = (MapView) findViewById(R.id.myMap);
}
}
Right
Hi Vlemmix.
Thanks very much for your help. I can understand what you are telling me, but if its so:
1) with the listener's lines commented, my code does show both the button and the mapview.. shouldnt it force close anyways if the problem is the setcontentView?
2) yeah agree with you on this one, though since I couldnt get even this simplest code to work, I didnt really want to overcomplicate it for now.
3) this is not a requirement is it? I mean its a coding convention, a good one yes, but not mandatory..?
4) Will do thanks, I m trying to get my bearings with all the dev websites etc.
PS about the API Key.. is this strictly required for developing on localhost (testing on the emu)? I find the info a bit confusing to be honest..
I will give your mods a shot this evening and will post here later tonight.
For the moment a big thank you for showing me my (silly) mistakes (I kinda miss .NET at times.. I wouldnt have messed up that bad with it..).
thanks!
N
Quick reply:
1) You can only find a view when the content is set. No content: nothin' to find!
3) Just do it! ;-)
API key, localhost? I don't understand your question... I'm on SDK1.1, did some work on the emulator, now most on the G1, no big difference. Don't know about keys. You probably need a key for generation an apk for the market though.
ApiKey
Vlemmix said:
Quick reply:
1) You can only find a view when the content is set. No content: nothin' to find!
3) Just do it! ;-)
API key, localhost? I don't understand your question... I'm on SDK1.1, did some work on the emulator, now most on the G1, no big difference. Don't know about keys. You probably need a key for generation an apk for the market though.
Click to expand...
Click to collapse
Will try and let you know mate!
The API Key you need to put in the xml for the MapView. apparently google has made this a requirement instead of the bogus key. I just dont understand if this is true also for the apps you test on the emu or only the ones that go 'live'..
Vlemmix
HI there,
just wanted to let you know that moving the setcontentview worked a treat!
Im so very embarassed now
thanks again for your help mate, I owe you one.
N
You're welcome, no problem!

Problem Reading Data from Sensors

Ok, so I'm trying to write a simple app to display the data from all of the sensors on a device. My problem is that whenever I try to instantiate my SensorManager object, my app's screen goes black, followed shortly by the Force Close / Wait dialogue.
My code:
Code:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//initialize graphics
setContentView(R.layout.main);
xaccelDisplay = (TextView) findViewById(R.id.xaccelDisplay);
yaccelDisplay = (TextView) findViewById(R.id.yaccelDisplay);
zaccelDisplay = (TextView) findViewById(R.id.zaccelDisplay);
//set up sensor manager
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
/*sensorManager.registerListener(this,
sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0),
SensorManager.SENSOR_DELAY_GAME);*/
}
Anyone have suggestions? I've looked for demo programs for how to access the sensors, but they all seem to use the sensor functions labeled as deprecated by the official Android website... maybe I'm missing something obvious.

Application crashes when trying to get a list of loaded modules

I have been looking into the C-Sharp__DLLImport project here:
http://forum.xda-developers.com/showthread.php?t=1006331&highlight=dllimport
I am trying to modify the FileSystem project to be able to get a list of the modules that are loaded for each process.
Code:
STDMETHODIMP CFileSystemIO::GetModulesForProcess(DWORD dwPID, BSTR* result)
{
// Get the process snapshot
HANDLE hModuleSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
// Initialize the module entry structure
MODULEENTRY32 moduleEntry = { 0 };
moduleEntry.dwSize = sizeof( moduleEntry );
// Get the first module info
BOOL Return = FALSE;
Return = Module32First( hModuleSnapshot, &moduleEntry);
// Getting process info failed.
if( !Return )
{
CloseHandle( hModuleSnapshot );
return S_FALSE;
}
int x = 1;
CString modList(TEXT(""));
do
{
modList.AppendFormat(TEXT("%d-%d-%d-%d-%d-%d-%s-%s\n"),
moduleEntry.dwSize,
moduleEntry.th32ProcessID,
moduleEntry.GlblcntUsage,
moduleEntry.ProccntUsage,
moduleEntry.modBaseAddr,
moduleEntry.modBaseSize,
moduleEntry.szModule,
moduleEntry.szExePath);
}
while( Module32Next( hModuleSnapshot, &moduleEntry ));
// Close the handle
CloseHandle( hModuleSnapshot );
// set the result
*result = (modList.AllocSysString());
return S_OK;
}
The code is based off a similar function that is already in the project (the CFileSystemIO::MessageBoxRunningProc function which works fine).
By putting some MessageBoxes in there for debugging, I can confirm that the Module32First and Module32Next methods are working correctly. When it gets to the line:
*result = (modList.AllocSysString());
The application crashes. I put a try/catch around there and it didn't trigger a CMemoryException or any other exception.
Any idea why this method would be causing the app to crash?
As an update to this, I was able to figure out the problem. I was unaware of this, but closing the handle generated in the method to get the process messes up the generation of the modules. I didn't think this would be the case since when you generate the handle it also takes a pid. I ended up combining the 2 methods.
The final project uses com interop to call the native methods and it builds a tasklist with all the corresponding modules as subclasses. You can find out which libraries and interfaces are in use by which applications, and where those dll files are located on your phone. If anyone wants to see it, I can post it at some point. It's not a very elegant looking interface, but it gets the job done.

Custom camera app issues (distorted)

Guys, Im creating an app with camera features.
But the preview on Nexus 5 with Lollipop is really distorted.
Anyone seen something like this?
After some debugging I discovered that my class that was extending SurfaceView and had the public void surfaceChanged(SurfaceHolder holder, int pixelFormat, int holderWidth, int holderHeight) {} method, was receiving 1080 in both width and height.
(Sorry if posted on the wrong category, my first post)

[Completed] Android ROM modification help needed

Hi,
I'm playing with a MTK ROM (4.2.2), I have to modify it in various ways, but I'm new to the whole area and I'm taking it one thing at a time. I'd really appreciate any help and advice I can get.
Currently I have to find out how to change the default rotation of the camera image/feed. The device has only one camera, the CameraInfo.orientation value is set to 90 and the image is upside-down. I want to find a way to set it to 270, so it would be ok.
So far I've found this in /frameworks.av.camera/ICameraService.cpp:
Code:
// get information about a camera
virtual status_t getCameraInfo(int cameraId,
struct CameraInfo* cameraInfo) {
Parcel data, reply;
data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
data.writeInt32(cameraId);
remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
cameraInfo->facing = reply.readInt32();
cameraInfo->orientation = reply.readInt32();
return reply.readInt32();
}
and this in /frameworks/base/core/jni/android_hardware_Camera.cpp:
Code:
static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
jint cameraId, jobject info_obj)
{
CameraInfo cameraInfo;
status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
if (rc != NO_ERROR) {
jniThrowRuntimeException(env, "Fail to get camera info");
return;
}
env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
char value[PROPERTY_VALUE_MAX];
property_get("ro.camera.sound.forced", value, "0");
jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0);
env->SetBooleanField(info_obj, fields.canDisableShutterSound,
canDisableShutterSound);
}
Neither of those are actually the place where the CameraInfo.orientation is being set, which is what I'm looking for. Also I want to find out where can I set the camera to be facing front or back.
Again, I'd really appreciate any pointers you could give me. Thanks!
Chris_M. said:
Hi,
I'm playing with a MTK ROM (4.2.2), I have to modify it in various ways, but I'm new to the whole area and I'm taking it one thing at a time. I'd really appreciate any help and advice I can get.
Currently I have to find out how to change the default rotation of the camera image/feed. The device has only one camera, the CameraInfo.orientation value is set to 90 and the image is upside-down. I want to find a way to set it to 270, so it would be ok.
So far I've found this in /frameworks.av.camera/ICameraService.cpp:
Code:
// get information about a camera
virtual status_t getCameraInfo(int cameraId,
struct CameraInfo* cameraInfo) {
Parcel data, reply;
data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
data.writeInt32(cameraId);
remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
cameraInfo->facing = reply.readInt32();
cameraInfo->orientation = reply.readInt32();
return reply.readInt32();
}
and this in /frameworks/base/core/jni/android_hardware_Camera.cpp:
Code:
static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
jint cameraId, jobject info_obj)
{
CameraInfo cameraInfo;
status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
if (rc != NO_ERROR) {
jniThrowRuntimeException(env, "Fail to get camera info");
return;
}
env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
char value[PROPERTY_VALUE_MAX];
property_get("ro.camera.sound.forced", value, "0");
jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0);
env->SetBooleanField(info_obj, fields.canDisableShutterSound,
canDisableShutterSound);
}
Neither of those are actually the place where the CameraInfo.orientation is being set, which is what I'm looking for. Also I want to find out where can I set the camera to be facing front or back.
Again, I'd really appreciate any pointers you could give me. Thanks!
Click to expand...
Click to collapse
Hello,
Please refer here [Guide]How To Port & Modify Roms For Mediatek[Everything] and read the entire thread carefully.
If you still run into queries please post in the thread itself, the experts there might be able to assist you.
Regards
Vatsal,
Forum Moderator.
Thanks, Vatsal!
Just to share - in the end I found that all the camera settings are in ../mediatek/custom/mt6572/hal/imgsensor/src/cfg_setting_imgsensor.cpp
Glad you found the fix mate.
Thread closed!

Categories

Resources