Cannot load lib from /vendor/lib in android 4.0.3 - android

I preinstalled app into /vendor/app, and lib into /vendor/lib. when I start app, exception caught:
> E/AndroidRuntime( 2446): at
> android.app.Activity.performCreate(Activity.java:4465)
> E/AndroidRuntime( 2446): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.access$600(ActivityThread.java:123)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
> E/AndroidRuntime( 2446): at
> android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
> 2446): at android.os.Looper.loop(Looper.java:137)
> E/AndroidRuntime( 2446): at
> android.app.ActivityThread.main(ActivityThread.java:4424)
> E/AndroidRuntime( 2446): at
> java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
> 2446): at java.lang.reflect.Method.invoke(Method.java:511)
> E/AndroidRuntime( 2446): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
> E/AndroidRuntime( 2446): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
> E/AndroidRuntime( 2446): at
> dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 2446):
> Caused by: java.lang.UnsatisfiedLinkError: Couldn't load
> jni_factory_test: findLibrary returned null E/AndroidRuntime( 2446):
> at java.lang.Runtime.loadLibrary(Runtime.java:365) E/AndroidRuntime(
> 2446): at java.lang.System.loadLibrary(System.java:535)
My env is:
export LD_LIBRARY_PATH /vendor/lib:/system/lib
What should I do?

Try with system.load call with path to vendor lib

Related

How to override or.apache.http in Android platform

I have wrote an Android application that uses HttpComponents from Apache to make a connection to server.
The version I used is 4.3 (newest), everything is ok, except when running.
I got exception
E/AndroidRuntime( 1699): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<in
it>(PoolingHttpClientConnectionManager.java:487)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:147)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:136)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:112)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.util.ApacheHTTP.<init>(ApacheHTTP.java:97)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.view.WeatherLifeActivity$3.<init>(WeatherLifeActivity.java:105)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.view.WeatherLifeActivity.onOptionsItemSelected(WeatherLifeActivity.j
ava:105)
E/AndroidRuntime( 1699): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
E/AndroidRuntime( 1699): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
E/AndroidRuntime( 1699): at android.view.View.performClick(View.java:4204)
E/AndroidRuntime( 1699): at android.view.View$PerformClick.run(View.java:17355)
E/AndroidRuntime( 1699): at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime( 1699): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1699): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1699): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 1699): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1699): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 1699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 1699): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1699): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:72)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:84)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientCon
nectionFactory.java:59)
E/AndroidRuntime( 1699): ... 25 more
E/AndroidRuntime( 1699): Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:52)
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:56)
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterF
actory.java:46)
E/AndroidRuntime( 1699): ... 28 more
The library (in jar archive) which I added to libs folder has been exported, it seems the application uses internal org.apache.http package instead of my own library.
The IDE is Intellij Idea.
Did anyone solve this issue before please help me?
This issue is presented a few times in SO. The solution I took was to use a repackaged version of the library called httpclientandroidlib. This was presented as a solution in a newer version of this question at How to Override Android Api Class with a class available in added jar?
You can use your own library in next way
com.yourlibrary.MyClass myClass= new com.yourlibrary.MyClass();

Getting resource not found exception in android app

I am trying to build an app in AOSP, my development kit has HDPI density, I have double verified it with the following code snippet:
switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
Log.d(TAG, "\n\n\n\n LDPI \n\n\n\n");
break;
case DisplayMetrics.DENSITY_MEDIUM:
Log.d(TAG, "\n\n\n\n MDPI \n\n\n\n");
break;
case DisplayMetrics.DENSITY_HIGH:
Log.d(TAG, "\n\n\n\n HDPI \n\n\n\n");
// ...
break;
case DisplayMetrics.DENSITY_XHIGH:
Log.d(TAG, "\n\n\n\n XDPI \n\n\n\n");
// ...
break;
}
when I build my application in Android File system,and if I run it, then I am getting following error:
E/AndroidRuntime( 825): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.Button
E/AndroidRuntime( 825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime( 825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 825): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 825): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 825): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 825): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 825): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 825): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 825): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 825): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.Button
E/AndroidRuntime( 825): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
E/AndroidRuntime( 825): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 825): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
E/AndroidRuntime( 825): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 825): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime( 825): at android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime( 825): at com.example.MainActivity.onCreate(MainActivity.java:96)
E/AndroidRuntime( 825): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime( 825): ... 11 more
E/AndroidRuntime( 825): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 825): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 825): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime( 825): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
E/AndroidRuntime( 825): ... 29 more
E/AndroidRuntime( 825): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d}
E/AndroidRuntime( 825): at android.content.res.Resources.loadDrawable(Resources.java:1897)
E/AndroidRuntime( 825): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 825): at android.widget.TextView.<init>(TextView.java:620)
E/AndroidRuntime( 825): at android.widget.Button.<init>(Button.java:108)
E/AndroidRuntime( 825): at android.widget.Button.<init>(Button.java:104)
E/AndroidRuntime( 825): ... 32 more
My all the drawable resources are in drawable-hdpi.
But if I put drawables in all the drawable-* folder then app runs.
But then UI is getting scattered.
Does anybody have idea, what the problem could. Do I have to add any Variable or flag in the Android.mk
=========edit=========
The app works fine if I build with eclipse. And run on the same device.
Therefore issue might be in building app along with AOSP.
========================
Any help would be highly appreciated.
Regards,
Yuvi
So after struggling too long and googling for more then two days, I found the issue. There was no drawable-hdpi folder in apk. I have resolved the issue by adding the LOCAL_AAPT_FLAGS += -c mdpi,hdpi,xhdpi line in Android.mk file.
Those who are struggling with the same kind of problem follow these supper steps:
Check at which line it is giving error:
Binary XML file line #11: Error inflating class android.widget.Button
In my xml file it was:
<Button
android:id="#+id/btn_footer_back"
style="#style/normalButtonStyle"
android:layout_width="wrap_content"
android:layout_height="60px"
android:layout_marginRight="1dp"
android:background="#drawable/button_state_selector"
android:drawableLeft="#drawable/ic_back"
android:drawablePadding="10px"
android:text="#string/back"
android:visibility="gone" />
So, what is the next step now, the log itself tells the story, check the line:
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d}
Here r=0x7f02000d is the resource id, that you can find in yourproject/gen/R.java
if you search for 0x7f02000d in R.java then you will able to find which resource is creating the problem, in my case it was R.drawable.ic_back
Hope it helps other to resolve their problems.
Regards,
Yuvi
Your UI is scattered because your files are not matching to appropriate density or resolution while displaying on device. You should use density independent pixels in xml.
And Create Drawable folder and put your files in it. And give reference of the drawable folder.

java.lang.ArrayIndexOutOfBoundsException com.google.android.maps

I am getting this error in app that uses com.google.android.maps and the message is "Unfortunately the app has stopped."
E/AndroidRuntime( 3338): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 3338): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime( 3338): at
android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
3338): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(
3338): at android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime( 3338): at
java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
3338): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3338): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 3338): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 3338): at dalvik.system.NativeStart.main(Native
Method) E/AndroidRuntime( 3338): Caused by:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
E/AndroidRuntime( 3338): at
com.google.android.maps.MapActivity.createMap(MapActivity.java:575)
E/AndroidRuntime( 3338): at
com.google.android.maps.MapActivity.onCreate(MapActivity.java:423)
E/AndroidRuntime( 3338): at
com.ee.map.MainActivity.onCreate(MainActivity.java:170)
E/AndroidRuntime( 3338): at
android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime( 3338): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime( 3338): ... 11 more
Has anybody seen such error and do you know what can causes this?
What is in com.google.android.maps.MapActivity.createMap(MapActivity.java:575)?

ActivityNotFoundException when include Android library

I have a test project which uses OI FileManager. I added that project to my test project as an Android library, then I call an Activitity in the library. It shows error:
E/AndroidRuntime( 1359): FATAL EXCEPTION: main
E/AndroidRuntime( 1359): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.filemanager.FileManagerActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1359): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1359): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1359): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1359): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1359): at com.androidcoretest.FileExplorerTest$1.onClick(FileExplorerTest.java:24)
E/AndroidRuntime( 1359): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime( 1359): at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime( 1359): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 1359): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1359): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1359): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1359): at dalvik.system.NativeStart.main(Native Method)
When I add full path of that Activity in the Manifest, it generates another error.
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
It shows:
E/AndroidRuntime( 1393): FATAL EXCEPTION: main
E/AndroidRuntime( 1393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidcoretest/org.openintents.filemanager.FileManagerActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 1393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 1393): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 1393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 1393): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1393): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1393): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1393): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1393): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1393): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1393): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1393): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.startForwardActivity(EulaOrNewVersion.java:127)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.showEula(EulaOrNewVersion.java:69)
E/AndroidRuntime( 1393): at org.openintents.distribution.DistributionLibrary.showEulaOrNewVersion(DistributionLibrary.java:53)
E/AndroidRuntime( 1393): at org.openintents.filemanager.FileManagerActivity.onCreate(FileManagerActivity.java:312)
E/AndroidRuntime( 1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 1393): ... 11 more
W/ActivityManager( 59): Force finishing activity com.androidcoretest/org.openintents.filemanager.FileManagerActivity
I would say this is a bug of Eclipse. Eclipse and ADT recently have many bugs on building process: ClassNotFound and ActivityNotFound.
Update:
My code just use one line:
final Intent intent = new Intent(FileExplorerTest.this, FileManagerActivity.class);
startActivity(intent);
Actually I have 3 projects. 2 library projects and 1 test project. Library "OI File Manager" uses Library "OI Distribution", then the test project C uses library "IO File Manager".
Ensure you are linking the OI FileManager projects as a library rather than external jar. go to Project properties > Android > Library, then click add library.
Then as you are doing define the activity in your project manifest (however with ADT 20 i think this is automatic)
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
I guess it can't find com.androidcoretest/org.openintents.distribution.EulaActivity not the FileManager activity. Do you have that EulaActivity in the manifest?
See in your log:
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.androidcoretest/org.openintents.distribution.EulaActivity}; have
you declared this activity in your AndroidManifest.xml?

How to set sample rate as 100KHz using AudioTrack in Android?

I'm developing an Android app that will play a specific audio. This audio is generated by code. My problem is that I need the sample rate up to 100KHz, but I got the error message as below. Could anyone know how to set sample rate as 100KHz with AudioTrack. Thanks.
PS: As I know, only AudioTrack could modify audio data, that's why I use AudioTrack
---------------code start-------------------
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
100000,
AudioFormat.ENCODING_PCM_16BIT,
(int)minSize,
AudioTrack.MODE_STREAM);
---------------log start--------------------
> D/AndroidRuntime( 7952): Shutting down VM E/AndroidRuntime( 7952):
> FATAL EXCEPTION: main E/AndroidRuntime( 7952):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.examples.audiotracktest/com.examples.audiotracktest.AudioTrackTest}:
> java.lang.IllegalArgumentException: 100000Hz is not a supported sample
> rate. E/AndroidRuntime( 7952): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.access$1500(ActivityThread.java:132)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
> E/AndroidRuntime( 7952): at
> android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
> 7952): at android.os.Looper.loop(Looper.java:150) E/AndroidRuntime(
> 7952): at android.app.ActivityThread.main(ActivityThread.java:4293)
> E/AndroidRuntime( 7952): at
> java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
> 7952): at java.lang.reflect.Method.invoke(Method.java:507)
> E/AndroidRuntime( 7952): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
> E/AndroidRuntime( 7952): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
> E/AndroidRuntime( 7952): at dalvik.system.NativeStart.main(Native
> Method) E/AndroidRuntime( 7952): Caused by:
> java.lang.IllegalArgumentException: 100000Hz is not a supported sample
> rate. E/AndroidRuntime( 7952): at
> android.media.AudioTrack.audioParamCheck(AudioTrack.java:369)
> E/AndroidRuntime( 7952): at
> android.media.AudioTrack.<init>(AudioTrack.java:312) E/AndroidRuntime(
> 7952): at android.media.AudioTrack.<init>(AudioTrack.java:265)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AndroidAudioDevice.<init>(AndroidAudioDevice.java:21)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AudioThread.<init>(AudioThread.java:11)
> E/AndroidRuntime( 7952): at
> com.examples.audiotracktest.AudioTrackTest.onCreate(AudioTrackTest.java:29)
> E/AndroidRuntime( 7952): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
> E/AndroidRuntime( 7952): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
> E/AndroidRuntime( 7952): ... 11 more
100kHz is a non-standard sampling rate and most Android platforms only support the standard rates (ref. Wikipedia: Sampling Rate).
The closest standard rate is 96kHz (professional audio) but most phones don't support this high a rate. CD quality (44.1kHz) is widely supported and you might be lucky and get 48kHz (e.g. Nexus S).
Do check out this method in Audiotrack, audiotrack.setPlaybackRate(int sampleRateInHertz)

Categories

Resources