I've been trying to fix this problem with MediaRecorder video Rotation on and off for weeks. I cannot get the line setOrientationHint(90) to work on a physical Samsung Galaxy S1 running Android 2.3.3 (SDK 10). This should run fine on anything above SDK 9.
When I call setOrientationHint(90) I get an exception : setParameters(video-param-rotation-angle-degrees=90) failed. Detailed error details below.
As a result I'm forced to check SDK and only call setOrientationHint() if SDK>10. ie, this code works fine on all other SDK versions above 10 which I have tested. I have tested on Samsung Galaxy Nexus running 4.2.2 and works fine.
Here is my code:
(cut down to show order of calls to MediaRecorder)
mCamera = getCameraInstance();
mCamera.setPreviewDisplay(holder);
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setOrientationHint(90);
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: recording setup
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(720,480);
mMediaRecorder.setVideoFrameRate(15);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
// Step 4: Set output file
currentOutputFileName = DIRECTORY_PATH + "zzzz"+ iCount +".mp4";
mFile = new File(currentOutputFileName);
mMediaRecorder.setOutputFile(mFile.getAbsolutePath());
// Step 4.1: Set recording length
mMediaRecorder.setMaxDuration(10000);
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(cameraView.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
mMediaRecorder.prepare();
Has anyone had this problem? I can't find anyone else is experiencing this and I can't believe thats the case. Is it possible its just a Australian Samsung Galaxy S1 running 2.3.3 issue?
I've seen references to people having problems where that line runs but with the actual video does not rotate but I actually receive an Exception - the line doesn't run at all. I've checked and rechecked the command order and it seems fine. I think what is most important is that the setOrientationHint() command occurs before mediaRecorder.prepare()
Here is the Error:
AuthorDriver::setParameter() unrecognized key "video-param-rotation-angle-degrees"
setParameter(video-param-rotation-angle-degrees = 90) failed with result -5
Ln 1047 handleSetParameters("video-param-rotation-angle-degrees=90") error
Command (12) failed
setParameters(video-param-rotation-angle-degrees=90) failed: -2147483648
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x40015578)
FATAL EXCEPTION: main
java.lang.RuntimeException: setParameter failed.
at android.media.MediaRecorder.setParameter(Native Method)
at android.media.MediaRecorder.setOrientationHint(MediaRecorder.java:341)
at com.on3x.emergency.Recorder.prepareVideoRecorder(Recorder.java:196)
at com.on3x.emergency.Recorder.startRecording(Recorder.java:90)
at com.on3x.emergency.GUI.RecordActivity$1.onClick(RecordActivity.java:86)
at android.view.View.performClick(View.java:2538)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.on3x.emergency/.GUI.RecordActivity
Dumpstate > /data/log/dumpstate_app_error
If anyone can give ANY help it would be much appreciated. For now I've had to tell our client that its not something I can fix at this moment and Video will have to be sideways.
Is there another way of rotating videos? Basically my app records videos and uploads them to the server. At the moment this 2.3.3 phone cannot rotate the video so its uploaded sideways
Cheers
Edit:
This is the code I now have in place. As suggested by Ashish Gupta, AuthorDriver does not contain the appropriate param on Samsung Galaxy S1 (australian model) running 2.3.3
if (android.os.Build.VERSION.SDK_INT>=9) {
// attempt to rotate the video 90 degrees.
try {
mMediaRecorder.setOrientationHint(90);
Utils.logLine("orientation rotated 90", this, Utils.LOG_TYPE_DEBUG);
} catch (Exception e) {
Utils.logLine("error trying setOrientationHint"+ e.getMessage(), this, Utils.LOG_TYPE_ERROR, e);
e.printStackTrace();
}
} else {
Utils.logLine("orientation set skipped ", this, Utils.LOG_TYPE_DEBUG);
}
Note: Utils.logLine is simply a Utilility function I have for printing debug and error statements to log. Hopefully that might help someone else...
Looking at the logs you have attached, it seems that Samsung Galaxy S1 running Android 2.3.3 does not support setOrientationHint.
This is the code from AuthorDriver.cpp
PVMFStatus AuthorDriver::setParameter(
const String8& key, const String8& value) {
if (key == "max-duration") {
int64_t max_duration_ms;
if (safe_strtoi64(value.string(), &max_duration_ms)) {
return setMaxDurationOrFileSize(
max_duration_ms, true /* limit_is_duration */);
}
} else if (key == "max-filesize") {
int64_t max_filesize_bytes;
if (safe_strtoi64(value.string(), &max_filesize_bytes)) {
return setMaxDurationOrFileSize(
max_filesize_bytes, false /* limit is filesize */);
}
} else if (key == "audio-param-sampling-rate") {
int64_t sampling_rate;
if (safe_strtoi64(value.string(), &sampling_rate)) {
return setParamAudioSamplingRate(sampling_rate);
}
} else if (key == "audio-param-number-of-channels") {
int64_t number_of_channels;
if (safe_strtoi64(value.string(), &number_of_channels)) {
return setParamAudioNumberOfChannels(number_of_channels);
}
} else if (key == "audio-param-encoding-bitrate") {
int64_t audio_bitrate;
if (safe_strtoi64(value.string(), &audio_bitrate)) {
return setParamAudioEncodingBitrate(audio_bitrate);
}
} else if (key == "video-param-encoding-bitrate") {
int64_t video_bitrate;
if (safe_strtoi64(value.string(), &video_bitrate)) {
return setParamVideoEncodingBitrate(video_bitrate);
}
}
// Return error if the key wasnt found
LOGE("AuthorDriver::setParameter() unrecognized key \"%s\"", key.string());
return PVMFErrArgument;
}
The key video-param-rotation-angle-degrees is not supported on Samsung Galaxy S1 aith Android 2.3.3
You can compare the logs between Nexus 4.2.2 and S1 2.3.3 and see if you see any noticeable difference.
Related
I am writing a program in Java for android. When calling the getSequencer method, I get a MidiUnavailableException exception.
When executing this code :
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
if (devices.length == 0) {
System.out.println("No MIDI devices found");
} else {
for (MidiDevice.Info dev : devices) {
System.out.println(dev);
}
}
I got the "No MIDI devices found". I realized that you can solve this problem by installing soundbank at this link:https://www.oracle.com/java/technologies/sound-banks.html
But it describes the installation method for Windows. And how to install soundbank for android?
I've been following a tutorial where I'm trying to use the JavaOSC library to add functionality for a native Android app to send OSC messages.
Below is the code I have for setting up an OSC thread:
private String myIP = "192.168.0.3";
private int myPort = 1234;
private OSCPortOut oscPortOut;
// This thread will contain all the code that pertains to OSC
private Thread oscThread = new Thread() {
#Override
public void run() {
try {
// Connect to some IP address and port
oscPortOut = new OSCPortOut(InetAddress.getByName(myIP), myPort);
Log.v(TAG, "CREATED PORT");
} catch(UnknownHostException e) {
Log.v(TAG, "error is", e);
// Error handling when your IP isn't found
return;
} catch(Exception e) {
// Error handling for any other errors
Log.v(TAG, "error is", e);
return;
}
/* The second part of the run() method loops infinitely and sends messages every 500
* milliseconds.
*/
while (true) {
if (oscPortOut != null) {
// Creating the message
Log.v(TAG, "CREATED MESSAGE");
Object[] thingsToSend = new Object[3];
thingsToSend[0] = "Hello World";
thingsToSend[1] = 12345;
thingsToSend[2] = 1.2345;
/* The version of JavaOSC from the Maven Repository is slightly different from the one
* from the download link on the main website at the time of writing this tutorial.
*
* The Maven Repository version (used here), takes a Collection, which is why we need
* Arrays.asList(thingsToSend).
*
* If you're using the downloadable version for some reason, you should switch the
* commented and uncommented lines for message below
*/
OSCMessage message = new OSCMessage(myIP, Arrays.asList(thingsToSend));
// OSCMessage message = new OSCMessage(myIP, thingsToSend);
/* NOTE: Since this version of JavaOSC uses Collections, we can actually use ArrayLists,
* or any other class that implements the Collection interface. The following code is
* valid for this version.
*
* The benefit of using an ArrayList is that you don't have to know how much information
* you are sending ahead of time. You can add things to the end of an ArrayList, but not
* to an Array.
*
* If you want to use this code with the downloadable version, you should switch the
* commented and uncommented lines for message2
*/
ArrayList<Object> moreThingsToSend = new ArrayList<Object>();
moreThingsToSend.add("Hello World2");
moreThingsToSend.add(123456);
moreThingsToSend.add(12.345);
OSCMessage message2 = new OSCMessage(myIP, moreThingsToSend);
//OSCMessage message2 = new OSCMessage(myIP, moreThingsToSend.toArray());
try {
// Send the messages
oscPortOut.send(message);
oscPortOut.send(message2);
Log.v(TAG, "SENDING");
// Pause for half a second
sleep(500);
} catch (Exception e) {
// Error handling for some error
}
}
}
}
};
I ended up getting some network errors, where research showed that I may need to add the following permission lines to the Android.manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
However, after adding those lines and running the app on the Simulator (a Nexus 7), but I keep getting errors saying that "The app has stopped".
This is actually my first Android project, so I'm sure I may be missing something obvious here (such as where to find logs in the case of this crash).
EDIT:
I'm on API 27. The only log I see from LogCat is the following:
12-13 17:07:54.299 2981-3026/com.deviantdev.pdsampleproject D/EGL_emulation: eglMakeCurrent: 0xa9f842a0: ver 2 0 (tinfo 0xa9f83300)
12-13 17:07:55.344 2981-2981/com.deviantdev.pdsampleproject I/Choreographer: Skipped 103 frames! The application may be doing too much work on its main thread.
12-13 17:07:55.362 2981-3026/com.deviantdev.pdsampleproject D/EGL_emulation: eglMakeCurrent: 0xa9f842a0: ver 2 0 (tinfo 0xa9f83300)
[ 12-13 17:07:55.416 2981: 2981 D/ ]
PlayerBase::stop() from IPlayer
12-13 17:07:55.416 2981-2981/com.deviantdev.pdsampleproject D/AudioTrack: stop() called with 90720 frames delivered
12-13 17:07:55.432 2981-2981/com.deviantdev.pdsampleproject I/opensl_stream: Input buffer size estimate: 0
12-13 17:07:55.432 2981-2981/com.deviantdev.pdsampleproject I/opensl_stream: Output buffer size estimate: 0
12-13 17:07:55.432 2981-2981/com.deviantdev.pdsampleproject I/opensl_stream: Lowest margin: 11968
From Android Marshmallow(API 23) and above , you may need to implement Runtime Permission . Here is an example ,
if (Build.VERSION.SDK_INT >= 23) {
String[] PERMISSIONS = {android.Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (!hasPermissions(mContext, PERMISSIONS)) {
ActivityCompat.requestPermissions((MainActivity) mContext, PERMISSIONS, REQUEST );
} else {
//do something
}
} else {
//do something
}
You can write this code inside onCreate and this is example to get WRITE_EXTERNAL_STORAGE permission at run time .
I think you should modify this line
String[] PERMISSIONS = {android.Manifest.permission.WRITE_EXTERNAL_STORAGE};
to
String[] PERMISSIONS = {android.Manifest.permission.INTERNET,android.Manifest.permission.ACCESS_NETWORK_STATE,android.Manifest.permission.ACCESS_WIFI_STATE};
Hope it's helpful .
We are now developing a payment card with NXP NQ220 (has embedded SE, called eSE) on Android N. The platform is MTK. Now, we can interact with eSE using OMA (using org.simalliance.openmobileapi.jar). It works as expected.
I was wondering if there is any ways to open channel in session without AID? Besides, is there any ways to control the power of eSE(power-on and power-off) and reset eSE in some situations?
My investigation as follows:
About open channel without AID, I have found following sentences in page 16 of Open Mobile API specification V3.
(h)Method: Channel openLogicalChannel(byte[] aid, Byte P2)
Open a logical channel with the SE, selecting the applet represented by the >given AID. If the AID is null, which means no applet is to be selected on >this channel, the default applet is used. It's up to the SE to choose which >logical channel will be used.
However, if we set aid to null in openLogicalChannel(byte[] aid), following exception will be shows. What happens about it? Is the default applet or eSE have problems?
01-30 01:06:39.941 V/SmartcardService( 2587): OpenLogicalChannel Exception: Access Control Enforcer: no APDU access allowed!
01-30 01:06:39.947 E/SeControlClient( 3239): Error occured:
01-30 01:06:39.947 E/SeControlClient( 3239): java.lang.SecurityException: Access Control Enforcer: no APDU access allowed!
01-30 01:06:39.947 E/SeControlClient( 3239): at org.simalliance.openmobileapi.SEService.checkForException(SEService.java:255)
01-30 01:06:39.947 E/SeControlClient( 3239): at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:295)
It seems there is no method in OMA to reset eSE. But I found reset() method in INxpNfcAdapterExtras. However, when I use INxpNfcAdapterExtras.reset(), it always return false. Following codes is how we get INxpNfcAdapterExtras.
private INxpNfcAdapterExtras getNxpNfcAdapterExtras() {
if (mNfcAdapter != null) {
try {
INxpNfcAdapter nxpNfcAdapter =
mNfcAdapter.getService().getNxpNfcAdapterInterface();
return nxpNfcAdapter.getNxpNfcAdapterExtrasInterface();
} catch (Exception e) {
Log.e(LOGTAG, "Exception occured:", e);
}
} else {
Log.e(LOGTAG, "Please initialize NfcAdapter first.");
}
return null;
}
About control the power of eSE, is it related to the platform? Can you give me some suggestions? Thank you very much.
Dont known
To access SE functions your application must be execute with owner of android device.
You could check this in : https://github.com/NXPNFCLinux/android_nxp-nci/blob/1d95fe24334fa12c9d9eccd1141f8739972c4288/aosp/packages/apps/Nfc/src/com/android/nfc/NfcService.java
The reset method check permission before:
public boolean reset(String pkg) throws RemoteException {
NfcService.this.enforceNfceeAdminPerm(pkg);
Bundle result;
boolean stat = false;
try {
stat = _nfcEeReset();
result = writeNoException();
} catch (IOException e) {
result = writeEeException(EE_ERROR_IO, e.getMessage());
}
Log.d(TAG,"reset" + stat);
return stat;
}
The check permission method:
public void enforceNfceeAdminPerm(String pkg) {
if (pkg == null) {
throw new SecurityException("caller must pass a package name");
}
NfcPermissions.enforceUserPermissions(mContext);
if (!mNfceeAccessControl.check(Binder.getCallingUid(), pkg)) {
throw new SecurityException(NfceeAccessControl.NFCEE_ACCESS_PATH +
" denies NFCEE access to " + pkg);
}
if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
throw new SecurityException("only the owner is allowed to call SE APIs");
}
}
To execute your app with device owner, you could follow my anwser here:
Device Admin API, how to be a device owner?
I'm not sure about what you mean "control the power of eSE". If it's on/off eSE, then eSE is integrated with NFC chip so if you disable NFC in Android eSE will be power off.
I have found another way to solve this issue. It used NXP's own class NxpNfcAdapterExtrasService.
1.I still don't know why the exception happens when we open channel use the default Applet(without AID). But, with the method in NxpNfcAdapterExtrasService, we can establish connection with eSE.
2.About the second question. The codes is right but the way of how to use INxpNfcAdapterExtras.reset() is wrong. This method will return true only when you do something with eSE. Like transmit and execute APDU commands. So you can use this method when you want to disconnect the connection with eSE.
3.About the third question, I don't know whether the openUicc()/closeUicc() method can control the eSE power. But, it seems this two method works as expected.
I'm using latest version of JavaCV to compress video and get mp4 file as per my requirement by using following piece of code.
File inputFile = new File(UTILS.getAppDirPath(),actual_input_file.getName());
File outputFile = new File(UTILS.getAppDirPath(),"comp_"+actual_file_name+".mp4");
FrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile,
grabber.getImageWidth(), grabber.getImageHeight(),
grabber.getAudioChannels());
recorder.setFrameRate(grabber.getFrameRate());
recorder.setSampleRate(grabber.getSampleRate());
recorder.setFormat("mp4");
if(grabber.getVideoBitrate()>bitrate)
{
recorder.setVideoBitrate(bitrate);
}
else
{
recorder.setVideoBitrate(grabber.getVideoBitrate());
}
recorder.start();
int count = 0;
Frame frame;
while ((frame = grabber.grabFrame()) != null) {
recorder.record(frame);
count++;
}
recorder.stop();
grabber.stop();
And these are the libraries which I have placed in libs directory of application,
/libs
/libs/armeabi
/libs/armeabi/libavcodec.so
libs/armeabi/libavdevice.so
libs/armeabi/libavfilter.so
libs/armeabi/libavformat.so
libs/armeabi/libavutil.so
libs/armeabi/libjniavcodec.so
libs/armeabi/libjniavdevice.so
libs/armeabi/libjniavfilter.so
libs/armeabi/libjniavformat.so
libs/armeabi/libjniavutil.so
libs/armeabi/libjnicvkernels.so
libs/armeabi/libjniopencv_calib3d.so
libs/armeabi/libjniopencv_contrib.so
libs/armeabi/libjniopencv_core.so
libs/armeabi/libjniopencv_features2d.so
libs/armeabi/libjniopencv_flann.so
libs/armeabi/libjniopencv_highgui.so
libs/armeabi/libjniopencv_imgproc.so
libs/armeabi/libjniopencv_legacy.so
libs/armeabi/libjniopencv_ml.so
libs/armeabi/libjniopencv_nonfree.so
libs/armeabi/libjniopencv_objdetect.so
libs/armeabi/libjniopencv_photo.so
libs/armeabi/libjniopencv_stitching.so
libs/armeabi/libjniopencv_superres.so
libs/armeabi/libjniopencv_video.so
libs/armeabi/libjniopencv_videostab.so
libs/armeabi/libjnipostproc.so
libs/armeabi/libjniswresample.so
libs/armeabi/libjniswscale.so
libs/armeabi/libnative_camera_r2.2.0.so
libs/armeabi/libnative_camera_r2.3.3.so
libs/armeabi/libnative_camera_r3.0.1.so
libs/armeabi/libnative_camera_r4.0.0.so
libs/armeabi/libnative_camera_r4.0.3.so
libs/armeabi/libnative_camera_r4.1.1.so
libs/armeabi/libnative_camera_r4.2.0.so
libs/armeabi/libnative_camera_r4.3.0.so
libs/armeabi/libnative_camera_r4.4.0.so
libs/armeabi/libopencv_calib3d.so
libs/armeabi/libopencv_contrib.so
libs/armeabi/libopencv_core.so
libs/armeabi/libopencv_features2d.so
libs/armeabi/libopencv_flann.so
libs/armeabi/libopencv_gpu.so
libs/armeabi/libopencv_highgui.so
libs/armeabi/libopencv_imgproc.so
libs/armeabi/libopencv_legacy.so
libs/armeabi/libopencv_ml.so
libs/armeabi/libopencv_nonfree.so
libs/armeabi/libopencv_objdetect.so
libs/armeabi/libopencv_photo.so
libs/armeabi/libopencv_stitching.so
libs/armeabi/libopencv_superres.so
libs/armeabi/libopencv_video.so
libs/armeabi/libopencv_videostab.so
libs/armeabi/libpostproc.so
libs/armeabi/libswresample.so
libs/armeabi/libswscale.so
libs/armeabi/libtbb.so
libs/android-support-v4.jar
libs/commons-net-3.3.jar
libs/ffmpeg.jar
libs/gson-2.2.4.jar
libs/javacpp.jar
libs/javacv.jar
libs/opencv.jar
Issue:
Everything is working fine when I test on Samsung Galaxy S4, Google Nexus 7, Samsung Galaxy Core.
It is failed with errors when I test on Motorola Razr,
Errors which I am facing:
First error message:
02-11 09:54:57.579: E/dalvikvm(22745): dlopen("/data/app-lib/com.myapp.example.apk-1/libjniavdevice.so") failed: dlopen failed: cannot locate symbol "av_input_audio_device_next" referenced by "libjniavdevice.so"...
02-11 09:54:57.579: W/dalvikvm(22745): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/bytedeco/javacpp/avdevice;
Second error message:
02-11 09:54:57.962: I/dalvikvm(22745): Could not find method java.awt.image.BufferedImage.getSampleModel, referenced from method org.bytedeco.javacpp.helper.opencv_core$AbstractIplImage.createFrom`
Third error message:
02-11 09:54:58.300: W/System.err(22745): org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open audio codec.`
Note:
As of now, I have included library files for armeabi and I do have the library files for x86 as well.
Can the processor of some specific devices (Motorola Razr) be the reason for such crash? i.e.: Motorola Razr has Krait processor.
I have used some code to create a simple app to allow the adding of contact details. The code is very simple and works fine in the emulator and on a number of devices that I have, except on the new HTC Sensation.
Here is the code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, number.getText().toString().trim())
.withValue(Phone.TYPE, "TYPE_MOBILE")
.build());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, name.getText().toString().trim())
.build());
try {
ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When I run it I get the following:
java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1328)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
at android.database.DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.applyBatch(ContentProviderNative.java:491)
at android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:95)
at android.content.ContentResolver.applyBatch(ContentResolver.java:641)
at uk.co.androidfun.getthatnumber.mainActivity.saveCallContact(mainActivity.java:157)
at uk.co.androidfun.getthatnumber.mainActivity$3.onClick(mainActivity.java:74)
at android.view.View.performClick(View.java:2532)
at android.view.View$PerformClick.run(View.java:9277)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I have looked and looked at the code and cannot see an issue, and as I say works well in the emulator run 2.3.3 but not on the phone running the same.
Thanks
John
I know this is an old question, but I was just hit by that weird NPE too, so this might help someone.
After some digging I found that one of the values I gave the newInsert was of the wrong type (damn refactoring!)
I had:
String val = ...;
builder.withValue(Data.RAW_CONTACT_ID, val);
Instead of:
long val = ...;
builder.withValue(Data.RAW_CONTACT_ID, val);
Fixing that solved the NPE.
So, looking at your code, I would first change "TYPE_MOBILE" to the Android const CommonDataKinds.Phone.TYPE_MOBILE (since this value might change among different vendors),
Second, make sure all the keys you're using in withValue have the same type as the one you're giving them (not sure 'null' is legal for ACCOUNT_TYPE), and print trimmed strings to make sure they have meaningful values.
Hope this helps!
Check what code refers to line of
androidfun.getthatnumber.mainActivity.saveCallContact(mainActivity.java:157)
There also should be more to your logcat, a Caused by etc etc that is usually more direct in pointing to the bad code.
I had the same problem with two HTC devices.
What solved it for me is adding some more values to the last data entry (I've added five more, other then the raw contact ID, phone number and mime tyep).
I have no idea why it works now, but it does.