Just wanted to see if anyone could help me out or point me in the right direction. I'm learning how to make a simple music player where the user clicks on list view items and it streams the mp3. There's a play button up top and next and previous song buttons (haven't added seek functionality yet). However it keeps crashing when I select new song. Here's my activity code:
public class AudioActivity extends AppCompatActivity {
ListView listView;
ArrayList<String> musicList;
ArrayAdapter adapter;
MediaPlayer player;
ImageButton prev;
ImageButton play;
ImageButton next;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
prev = (ImageButton) findViewById(R.id.previous);
play = (ImageButton) findViewById(R.id.play);
next = (ImageButton) findViewById(R.id.next);
listView = findViewById(R.id.musiclist);
musicList = new ArrayList<>();
musicList.add("song");
musicList.add("song1");
musicList.add("song2");
musicList.add("song3");
musicList.add("song4");
adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, musicList);
listView.setAdapter(adapter);
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
String url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3";
try {
player.stop();
//player.release();
player.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
try {
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
break;
case 1:
url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3";
try {
player.stop();
//player.release();
player.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
try {
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
break;
default:
break;
}
player.start();
}
});
}
public void onPlayBtnClicked(){
if(!player.isPlaying())
{
player.start();
}else
{
player.pause();
}
}
}
04/05 00:08:09: Launching app
$ adb shell am start -n "com.example.brads.group08/com.example.brads.group08.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Connecting to com.example.brads.group08
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.brads.group08 is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/zygote: Debugger is active
Connected to the target VM, address: 'localhost:8600', transport: 'socket'
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10091(com.example.brads.group08) identical 4 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1448)
I/InstantRun: starting instant run server: is main process
D/OpenGLRenderer: HWUI GL Pipeline
[ 04-05 04:08:16.176 10444:10464 D/ ]
HostConnection::get() New Host Connection established 0xa5a26b40, tid 10464
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/EGL_emulation: eglCreateContext: 0xa5a70f60: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
I/zygote: Do partial code cache collection, code=21KB, data=30KB
I/zygote: After code cache collection, code=21KB, data=30KB
I/zygote: Increasing code cache capacity to 128KB
I/zygote: Do partial code cache collection, code=31KB, data=56KB
I/zygote: After code cache collection, code=31KB, data=56KB
I/zygote: Increasing code cache capacity to 256KB
I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Do full code cache collection, code=116KB, data=72KB
I/zygote: After code cache collection, code=90KB, data=45KB
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
W/MediaPlayer: Use of stream types is deprecated for operations other than volume control
W/MediaPlayer: See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
E/MediaPlayerNative: stop called in state 1, mPlayer(0x0)
E/MediaPlayerNative: error (-38, 0)
V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#89d8a5e): Cookies: null
V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager#a4007a4
V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService#89d8a5e): cookieHandler: java.net.CookieManager#a4007a4 Cookies: null
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/Choreographer: Skipped 163 frames! The application may be doing too much work on its main thread.
E/MediaPlayer: Error (-38,0)
I/zygote: Do partial code cache collection, code=123KB, data=81KB
I/zygote: After code cache collection, code=123KB, data=81KB
I/zygote: Increasing code cache capacity to 512KB
V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#7615caf): Cookies: null
E/MediaPlayerNative: attachNewPlayer called in state 64
E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.IllegalStateException
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127)
at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127)
at android.widget.AbsListView.onTouchUp(AbsListView.java:4054)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813)
at android.view.View.dispatchTouchEvent(View.java:11776)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12015)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.brads.group08, PID: 10444
java.lang.IllegalStateException
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127)
at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127)
at android.widget.AbsListView.onTouchUp(AbsListView.java:4054)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813)
at android.view.View.dispatchTouchEvent(View.java:11776)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12015)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
Related
I created a small Softkeyboard for Android Studio and now want to add Speech to Text, but I am getting this error when I start the application in the logcat:
Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:5174)
The Keyboard on itself and the Speech to Text on itself worked just fine.
Source Code:
package edmt.dev.androidcustomkeyboard;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.media.AudioManager;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputConnection;
import android.widget.ImageButton;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Locale;
public class OrthKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
private KeyboardView kv;
private Keyboard keyboard;
public static SpeechInnerClass SpeechInnerClass;
private boolean isCaps = false;
public static String auto_word ="";
//Press Ctrl+O
#Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard,null);
keyboard = new Keyboard(this,R.xml.qwerty);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
SpeechInnerClass = new SpeechInnerClass();
return kv;
}
#Override
public void onPress(int i) {
}
#Override
public void onRelease(int i) {
}
#Override
public void onKey(int i, int[] ints) {
InputConnection ic = getCurrentInputConnection();
playClick(i);
// MainActivity.count ++;
if(i==-4222522|i==-4222521|i==-4222523|i==-4222525){
if(i==-4222522){
ic.commitText("Case 2",1);
}
if(i==-4222521){
ic.commitText("Case 1",1);
}
if(i==-4222523){
ic.commitText("Case 3",1);
}
if(i==-4222525){
SpeechInnerClass.startVoiceInput();
ic.commitText(SpeechInnerClass.output,1);
}
}
else {
switch (i) {
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
isCaps = !isCaps;
keyboard.setShifted(isCaps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char) i;
if (Character.isLetter(code) && isCaps)
code = Character.toUpperCase(code);
ic.commitText(String.valueOf(code), 1);
SettingsActivity.count++;
if ((char) i == ' ') {
auto_word = "";
}
if (96 < i && i < 123) {
auto_word = auto_word + (char) i;
}
}
}
}
private void playClick(int i) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
switch(i)
{
case 32:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
case 10:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
default: am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
}
#Override
public void onText(CharSequence charSequence) {
}
#Override
public void swipeLeft() {
}
#Override
public void swipeRight() {
}
#Override
public void swipeDown() {
}
#Override
public void swipeUp() {
}
public static class SpeechInnerClass extends AppCompatActivity {
private static final int REQ_CODE_SPEECH_INPUT = 100;
public static CharSequence output = "Test";
private TextView mVoiceInputTv;
private ImageButton mSpeakBtn;
public boolean voice = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(voice=true){
startVoiceInput();
}
}
public void startVoiceInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hello, How can I help you?");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
output=(result.get(0));
}
break;
}
}
}
}
}
Full Logcat:
2019-07-14 13:23:02.202 12121-12121/? D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2019-07-14 13:23:02.211 12121-12121/? D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2019-07-14 13:23:02.214 12121-12121/? D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2019-07-14 13:23:02.216 12121-12121/? D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2019-07-14 13:39:26.230 12121-12121/? I/dcustomkeyboar: Not late-enabling -Xcheck:jni (already on)
2019-07-14 13:39:26.247 12121-12121/? E/dcustomkeyboar: Unknown bits set in runtime_flags: 0x8000
2019-07-14 13:39:26.247 12121-12121/? W/dcustomkeyboar: Unexpected CPU variant for X86 using defaults: x86
2019-07-14 13:39:26.339 12121-12121/edmt.dev.androidcustomkeyboard I/dcustomkeyboar: The ClassLoaderContext is a special shared library.
2019-07-14 13:39:26.451 12121-12121/edmt.dev.androidcustomkeyboard W/dcustomkeyboar: JIT profile information will not be recorded: profile file does not exits.
2019-07-14 13:39:26.461 12121-12121/edmt.dev.androidcustomkeyboard I/chatty: uid=10132(edmt.dev.androidcustomkeyboard) identical 10 lines
2019-07-14 13:39:26.462 12121-12121/edmt.dev.androidcustomkeyboard W/dcustomkeyboar: JIT profile information will not be recorded: profile file does not exits.
2019-07-14 13:39:26.484 12121-12121/edmt.dev.androidcustomkeyboard I/InstantRun: starting instant run server: is main process
2019-07-14 13:39:26.725 12121-12920/edmt.dev.androidcustomkeyboard D/OpenGLRenderer: Swap behavior 1
2019-07-14 13:39:26.726 12121-12920/edmt.dev.androidcustomkeyboard W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-07-14 13:39:26.727 12121-12920/edmt.dev.androidcustomkeyboard D/OpenGLRenderer: Swap behavior 0
2019-07-14 13:39:26.739 12121-12920/edmt.dev.androidcustomkeyboard D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2019-07-14 13:39:26.739 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglCreateContext: 0xd85a7cc0: maj 2 min 0 rcv 2
2019-07-14 13:39:26.758 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglMakeCurrent: 0xd85a7cc0: ver 2 0 (tinfo 0xc61374e0)
2019-07-14 13:39:26.778 12121-12920/edmt.dev.androidcustomkeyboard W/Gralloc3: mapper 3.x is not supported
2019-07-14 13:39:26.785 12121-12920/edmt.dev.androidcustomkeyboard D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
2019-07-14 13:39:26.814 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglMakeCurrent: 0xd85a7cc0: ver 2 0 (tinfo 0xc61374e0)
2019-07-14 13:39:26.835 12121-12920/edmt.dev.androidcustomkeyboard D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2019-07-14 13:39:26.944 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglMakeCurrent: 0xd85a7cc0: ver 2 0 (tinfo 0xc61374e0)
2019-07-14 13:39:26.964 12121-12920/edmt.dev.androidcustomkeyboard D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
2019-07-14 13:39:26.967 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglMakeCurrent: 0xd85a7cc0: ver 2 0 (tinfo 0xc61374e0)
2019-07-14 13:39:34.439 12121-12920/edmt.dev.androidcustomkeyboard D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
2019-07-14 13:39:34.447 12121-12920/edmt.dev.androidcustomkeyboard D/EGL_emulation: eglMakeCurrent: 0xd85a7cc0: ver 2 0 (tinfo 0xc61374e0)
2019-07-14 13:39:34.484 12121-12121/edmt.dev.androidcustomkeyboard E/InputEventReceiver: Exception dispatching input event.
2019-07-14 13:39:34.484 12121-12121/edmt.dev.androidcustomkeyboard E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
2019-07-14 13:39:34.489 12121-12121/edmt.dev.androidcustomkeyboard E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:5174)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:5131)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at edmt.dev.androidcustomkeyboard.OrthKeyboard$SpeechInnerClass.startVoiceInput(OrthKeyboard.java:201)
at edmt.dev.androidcustomkeyboard.OrthKeyboard.onKey(OrthKeyboard.java:85)
at android.inputmethodservice.KeyboardView.detectAndSendKey(KeyboardView.java:847)
at android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1354)
at android.inputmethodservice.KeyboardView.onTouchEvent(KeyboardView.java:1217)
at android.view.View.dispatchTouchEvent(View.java:13417)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:460)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1849)
at android.app.Dialog.dispatchTouchEvent(Dialog.java:861)
at android.inputmethodservice.SoftInputWindow.dispatchTouchEvent(SoftInputWindow.java:152)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:418)
at android.view.View.dispatchPointerEvent(View.java:13676)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5479)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5282)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4838)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4804)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4944)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4812)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5001)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4838)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4804)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4812)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7502)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7471)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7432)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7627)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Runti
2019-07-14 13:39:34.489 12121-12121/edmt.dev.androidcustomkeyboard D/AndroidRuntime: Shutting down VM
2019-07-14 13:39:34.499 12121-12121/edmt.dev.androidcustomkeyboard E/AndroidRuntime: FATAL EXCEPTION: main
Process: edmt.dev.androidcustomkeyboard, PID: 12121
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:5174)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:5131)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at edmt.dev.androidcustomkeyboard.OrthKeyboard$SpeechInnerClass.startVoiceInput(OrthKeyboard.java:201)
at edmt.dev.androidcustomkeyboard.OrthKeyboard.onKey(OrthKeyboard.java:85)
at android.inputmethodservice.KeyboardView.detectAndSendKey(KeyboardView.java:847)
at android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1354)
at android.inputmethodservice.KeyboardView.onTouchEvent(KeyboardView.java:1217)
at android.view.View.dispatchTouchEvent(View.java:13417)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2755)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:460)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1849)
at android.app.Dialog.dispatchTouchEvent(Dialog.java:861)
at android.inputmethodservice.SoftInputWindow.dispatchTouchEvent(SoftInputWindow.java:152)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:418)
at android.view.View.dispatchPointerEvent(View.java:13676)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5479)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5282)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4838)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4804)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4944)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4812)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5001)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4838)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4804)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4812)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4785)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7502)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7471)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7432)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7627)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7319)
2019-07-14 13:39:34.500 12121-12121/edmt.dev.androidcustomkeyboard E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
try it
runOnUiThread(new Runnable() {
#Override
public void run() {
//Code
}
});
I'm new to Android and Java development and am looking for some guidance in setting up a simple soundboard app. What I am trying to do and am having issues in getting it working effectively is handling events for multiple mediaplayers.
For example I am creating a soundboard whereby when I click a button I want all other sounds to be stopped and released from memory and the button I have just pressed to play its assigned sound. I realise that repeating code blocks is not a good programming approach, but I have tried this with arrays and switch statements too with little effect. Any guidance on how to effectively release sounds from memory when using multiple MediaPlayers would be very useful to me. I have included my code below for 4 buttons (I have over 30 on this app)
public class MainActivity extends AppCompatActivity {
private MediaPlayer Meow1,Meow2,Meow3,Meow4;
private Button meowButton1,meowButton2,meowButton3,meowButton4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Meow1 = new MediaPlayer();
Meow1 = MediaPlayer.create(getApplicationContext(), R.raw.meow1);
// final Boolean Meow1Pause = !Meow1.isPlaying() && Meow1.getCurrentPosition() >1;
meowButton1 = (Button) findViewById(R.id.Meow1);
meowButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow1.isPlaying())
{ pauseMusic1();
} else {
Meow1.start();
}}
});
Meow1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow1.stop();
Meow1.reset();
Meow1.release();
}
});
Meow2 = new MediaPlayer();
Meow2 = MediaPlayer.create(getApplicationContext(), R.raw.meow2);
meowButton2 = (Button) findViewById(R.id.Meow2);
meowButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow2.isPlaying() ){
pauseMusic();
} else {
Meow2.start();
}}
});
Meow2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow2.stop();
Meow2.reset();
Meow2.release();
}
});
Meow3 = new MediaPlayer();
Meow3 = MediaPlayer.create(getApplicationContext(), R.raw.meow3);
meowButton3 = (Button) findViewById(R.id.Meow3);
meowButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow3.isPlaying())
{ pauseMusic();
} else {
Meow3.start();
}}
});
Meow3.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow3.stop();
Meow3.reset();
Meow3.release();
}
});
Meow4 = new MediaPlayer();
Meow4 = MediaPlayer.create(getApplicationContext(), R.raw.meow4);
meowButton4 = (Button) findViewById(R.id.Meow4);
meowButton4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow4.isPlaying())
{ pauseMusic();
} else {
Meow4.start();
}}
});
}
public void pauseMusic() {
if(Meow1 != null && Meow1.isPlaying()) Meow1.pause();
if(Meow2 != null && Meow2.isPlaying()) Meow2.pause();
if(Meow3 != null && Meow3.isPlaying()) Meow3.pause();
if(Meow4 != null && Meow4.isPlaying()) Meow4.pause();
}
}
Run Compiler:
A: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SplashScreen, firebase_previous_id(_pi)=-6549553702477848745, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-6549553702477848744}]
I/zygote: Do partial code cache collection, code=124KB, data=67KB
I/zygote: After code cache collection, code=124KB, data=67KB
I/zygote: Increasing code cache capacity to 512KB
V/FA: Activity resumed, time: 6376787
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
I/chatty: uid=10085(u0_a85) RenderThread identical 2 lines
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
V/FA: Inactivity, disconnecting from the service
V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
cleanDrmObj: mDrmObj=null mDrmSessionId=null
D/TAG1: Button 2 pressed
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: g.convery.cat_sounds, PID: 12276
java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at g.convery.cat_sounds.MainActivity$1.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
W/MediaPlayer-JNI: MediaPlayer finalized without being released
W/MediaPlayer-JNI: MediaPlayer finalized without being released
Application terminated.
LOGCAT:
05-31 09:21:30.099 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:21:30.211 12276-12288/g.convery.cat_sounds I/chatty: uid=10085(u0_a85) FinalizerDaemon identical 33 lines
05-31 09:21:30.212 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:21:30.283 12276-12284/g.convery.cat_sounds I/zygote: Do partial code cache collection, code=124KB, data=67KB
05-31 09:21:30.286 12276-12284/g.convery.cat_sounds I/zygote: After code cache collection, code=124KB, data=67KB
05-31 09:21:30.287 12276-12284/g.convery.cat_sounds I/zygote: Increasing code cache capacity to 512KB
05-31 09:21:31.159 12276-12307/g.convery.cat_sounds I/chatty: uid=10085(u0_a85) RenderThread identical 2 lines
05-31 09:24:41.746 12276-12276/g.convery.cat_sounds E/AndroidRuntime: FATAL EXCEPTION: main
Process: g.convery.cat_sounds, PID: 12276
java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at g.convery.cat_sounds.MainActivity$1.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
05-31 09:24:47.955 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:24:47.956 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
You are using the media player after releasing it. Remove these lines from your onCompletionListener and add them to onDestroy of your activity instead
Meow1.release();
Meow2.release();
Meow3.release();
Meow4.release();
Also calling create automatically creates a new instance, you can remove these lines as well
Meow1 = new MediaPlayer();
Meow2 = new MediaPlayer();
Meow3 = new MediaPlayer();
Meow4 = new MediaPlayer();
A better approach would be to use a single media player and just change the datesource when ever user wants to play different source, but this method will take some time before it plays the audio as it will prepare the audio everytime, this would be negligible unless your audio size is quite huge
Look how you're controlling your media now:
if (Meow4.isPlaying()) {
pauseMusic();
} else {
Meow4.start();
}
The first time you call Meow4.isPlaying() you will receive IllegalStateException because your player is not initialized.
Look how your MediaPlayer state is defined and call appropriate function
The second point, when you encounter a duplicate block, you should think of a function.
Meow3 = new MediaPlayer();
Meow3 = MediaPlayer.create(getApplicationContext(), R.raw.meow3);
meowButton3 = (Button) findViewById(R.id.Meow3);
meowButton3.setOnClickListener(new View.OnClickListener() {
});
meowButton3.setOnCompletionListener...
in a function: registerPlayer(Context context, int resourceId, Button controlButton)
Or with higher level of abstraction, create a subclass of `MediaPlayer` and wrap these logic inside it
Definitely you don't want to Meow1.pause() over and over. Instead, store your MeoX in a list then loop over it:
List<MediaPlayer> players = new ArrayList<>();
players.add(Meow1);
....
public void pauseMusic() {
players.stream().filter(p -> p != null && p.isPlaying()).forEach(p -p.pause());
}
I am establishing server-client communication between Android app and ESP8266 NodeMCU-1.0. The ESP is creating server on specified network and the mobile is connecting to same network.
For testing purpose I am sending "try123" string when the send button is pressed. And receiving appropriate response on the serial monitor of IDE (i.e. data is received on server). But the server response which is "Test_successful" string. I am sending this string to client using client.print. In app I am toasting the server response.
The problem is that if I am making the HTTP request using browser using the locally generated URL, then the response "Test_successful" is visible. But In app toast it's showing empty and while debugging it's showing error Unexpected line status.
ESP code (server side):
#include <ESP8266WiFi.h>
const char* ssid = "DARSHAN95";
const char* password = "12345678";
//const char* ssid = "TP-LINK_42C148";
//const char* password = "";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
//client.flush();
delay(100);
// Send the response to the client
client.print("Test_Sucessfull");
delay(200);
Serial.println("Client disonnected");
}
Android App code:
Please ignore the text input block on the and its code.
package com.example.access.test123;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class MainActivity extends AppCompatActivity {
EditText Message;
Button Send;
String data;
HttpURLConnection http;
String sendingMessage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Message = (EditText) findViewById(R.id.message);
Send = (Button) findViewById(R.id.send);
Send.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
HttpAsync task = new HttpAsync();
task.execute();
}
});
}
public void sendDataMethod() throws UnsupportedEncodingException{
sendingMessage = Message.getText().toString();
String data = "Error";
BufferedReader reader = null;
//Sending Data
try{
String ip = "http://192.168.43.76/?try123";
//String address = ip + sendingMessage;
//URL url = new URL(address);
URL url = new URL(ip);
URLConnection conn = url.openConnection();
http = (HttpURLConnection)conn;
http.setRequestMethod("POST"); // PUT is another valid option
http.setDoOutput(true);
http.setDoInput(true);
//Server Response
int i = http.getResponseCode();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
sb.append(line + "\n");
}
data = sb.toString();
}
catch(IOException e){;
Log.d("Error2", e.toString());
}
finally {
try{
if(reader != null) {
reader.close();
}
}
catch (IOException ex){
Log.d("Error3", ex.toString());
}
}
}
private class HttpAsync extends AsyncTask {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Object doInBackground(Object[] objects) {
try {
sendDataMethod();
}
catch (UnsupportedEncodingException e) {
Log.d("Error", e.toString());
}
return null;
}
#Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
Toast.makeText(MainActivity.this, data, Toast.LENGTH_SHORT).show();
}
}
}
Debugging results:
02/07 22:40:23: Launching app
$ adb install-multiple -r -t A:\New folder\Test123\app\build\intermediates\split-apk\debug\dep\dependencies.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_1.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_2.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_3.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_6.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_9.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_8.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_7.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_4.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_5.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_0.apk A:\New folder\Test123\app\build\outputs\apk\debug\app-debug.apk
Split APKs installed
$ adb shell am start -n "com.example.access.test123/com.example.access.test123.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Connecting to com.example.access.test123
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/art: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8601', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1436)
W/System: ClassLoader referenced unknown path: /data/app/com.example.access.test123-2/lib/arm64
I/art: Starting a blocking GC HeapTrim
I/InstantRun: starting instant run server: is main process
I/art: Starting a blocking GC Instrumentation
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView#3280086[]
D/WindowClient: Add to mViews: DecorView#3280086[MainActivity], this = android.view.WindowManagerGlobal#d5cc9ee
D/OpenGLRenderer: Dumper init 4 threads <0x7c6a19ee40>
D/OpenGLRenderer: <com.example.access.test123> is running.
D/OpenGLRenderer: CanvasContext() 0x7c6773f880
D/ViewRootImpl[MainActivity]: hardware acceleration is enabled, this = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0}
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0}, this = DecorView#3280086[MainActivity]
D/OpenGLRenderer: CanvasContext() 0x7c6773f880 initialize window=0x7c73e55e00, title=com.example.access.test123/com.example.access.test123.MainActivity
D/Surface: Surface::allocateBuffers(this=0x7c73e55e00)
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/OpenGLRenderer: Created EGL context (0x7c6a19f600)
D/OpenGLRenderer: ProgramCache.init: enable enhancement 1
I/OpenGLRenderer: Get disable program binary service property (0)
I/OpenGLRenderer: Initializing program atlas...
I/ProgramBinary/Service: ProgramBinaryService client side disable debugging.
I/ProgramBinary/Service: ProgramBinaryService client side disable binary content debugging.
D/ProgramBinary/Service: BpProgramBinaryService.getReady
D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryData
I/OpenGLRenderer: Program binary detail: Binary length is 249276, program map length is 124.
I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 74, and path is /dev/ashmem.
I/OpenGLRenderer: No need to use file discriptor anymore, close fd(74).
D/OpenGLRenderer: Initializing program cache from 0x0, size = -1
D/MALI: eglCreateImageKHR:513: [Crop] 0 0 896 1344 img[896 1344]
D/Surface: Surface::connect(this=0x7c73e55e00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 0, 0, 189, 441
D/OpenGLRenderer: ProgramCache.generateProgram: 0
D/OpenGLRenderer: ProgramCache.generateProgram: 34359738371
D/OpenGLRenderer: ProgramCache.generateProgram: 5242945
D/OpenGLRenderer: ProgramCache.generateProgram: 5242944
D/OpenGLRenderer: ProgramCache.generateProgram: 240518168576
D/OpenGLRenderer: ProgramCache.generateProgram: 68724719680
V/InputMethodManager: onWindowFocus: android.support.v7.widget.AppCompatEditText{8687c92 VFED..CL. .F....ID 228,66-851,212 #7f070042 app:id/message} softInputMode=288 first=true flags=#81810100
D/OpenGLRenderer: ProgramCache.generateProgram: 103084458052
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/System.out: [socket][0] connection /192.168.43.76:80;LocalPort=-1(0)
[ 02-07 22:40:39.251 29396:29665 D/ ]
[Posix_connect Debug]Process com.example.access.test123 :80
I/System.out: [socket][/192.168.43.1:49348] connected
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull
D/WindowClient: Add to mViews: android.widget.LinearLayout{3957537 V.E...... ......I. 0,0-0,0}, this = android.view.WindowManagerGlobal#d5cc9ee
D/OpenGLRenderer: CanvasContext() 0x7c56092d40
D/ViewRootImpl[Toast]: hardware acceleration is enabled, this = ViewRoot{f7a400d Toast,ident = 1}
D/Surface: Surface::allocateBuffers(this=0x7c58339e00)
D/OpenGLRenderer: CanvasContext() 0x7c56092d40 initialize window=0x7c58339e00, title=Toast
D/Surface: Surface::connect(this=0x7c58339e00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
D/OpenGLRenderer: ProgramCache.generateProgram: 1
D/Surface: Surface::disconnect(this=0x7c58339e00,api=1)
D/Surface: Surface::disconnect(this=0x7c58339e00,api=1)
D/WindowClient: Remove from mViews: android.widget.LinearLayout{3957537 V.E...... ......ID 0,0-156,140}, this = android.view.WindowManagerGlobal#d5cc9ee
I/art: Do partial code cache collection, code=28KB, data=28KB
I/art: After code cache collection, code=27KB, data=28KB
I/art: Increasing code cache capacity to 128KB
Note: At D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull
The string is received but with above error.
Results:
IDE monitor displaying data sent from client i.e. app
Finally Found the solution, the error was with the syntax of the response packet sent from ESP side
so just replaced
client.print("Test_Successfull");
with
client.print("HTTP/1.1 200 OK\r\nConnection: Closed\r\n\r\nTest_Successful");
For some reason my app is keep coming up with "app name" has stopped. I have added the error log below but cannot work out what the problem is. I have tried many times to figure it out but still not getting anywhere. Hopefully you can understand the error log.
04-29 12:20:07.016 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.019 1694-4363/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
04-29 12:20:07.019 1694-4363/system_process D/OpenGLRenderer: Swap behavior 1
04-29 12:20:07.019 1694-4363/system_process W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
04-29 12:20:07.019 1694-4363/system_process D/OpenGLRenderer: Swap behavior 0
04-29 12:20:07.020 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.070 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.465 1694-1712/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{6dd3b2c u0 thomashaywoodproductions.buildaempiredesign/.GameLogin t154 f}
04-29 12:20:07.481 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x333 imply creation of host color buffer
[ 04-29 12:20:07.485 1694: 1712 D/ ]
HostConnection::get() New Host Connection established 0x96c6e480, tid 1712
04-29 12:20:07.521 1296-1296/? E/EGL_emulation: tid 1296: eglCreateSyncKHR(1669): error 0x3004 (EGL_BAD_ATTRIBUTE)
04-29 12:20:07.558 1296-1353/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.559 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.560 1694-1712/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
04-29 12:20:07.569 1296-1353/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.586 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.594 1296-1353/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.601 1296-2069/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
04-29 12:20:07.687 2343-2343/com.google.android.googlequicksearchbox:search I/OptInState: There is a new client and it does not support opt-in. Dropping request.
04-29 12:20:07.692 2343-2343/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: Micro detection mode: [mDetectionMode: [1]].
04-29 12:20:07.693 2343-2343/com.google.android.googlequicksearchbox:search I/AudioController: Using mInputStreamFactoryBuilder
04-29 12:20:07.700 2343-18556/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Starting detection.
04-29 12:20:07.701 2343-9163/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.staticplugins.z.c#6dbc476
04-29 12:20:07.702 1305-1775/? W/APM_AudioPolicyManager: getInputForAttr() failed opening input: samplingRate 16000, format 1, channelMask 10
04-29 12:20:07.702 2343-9163/com.google.android.googlequicksearchbox:search E/AudioRecord: Could not get audio input for session 4025, record source 1999, sample rate 16000, format 0x1, channel mask 0x10, flags 0
04-29 12:20:07.703 2343-9163/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
04-29 12:20:07.703 2343-9163/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
04-29 12:20:07.703 2343-9163/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.staticplugins.z.c#6dbc476
04-29 12:20:07.703 2343-9163/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
04-29 12:20:07.704 2343-2343/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady
04-29 12:20:07.706 2343-18556/com.google.android.googlequicksearchbox:search W/SpeechLevelGenerator: Really low audio levels detected. The audio input may have issues.
04-29 12:20:07.715 2343-18556/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Detection finished
04-29 12:20:07.714 2343-9163/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.staticplugins.z.c#6dbc476
04-29 12:20:07.715 2343-18556/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream
04-29 12:20:07.716 2343-2485/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Stopping hotword detection.
04-29 12:20:07.716 2343-18556/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.a.g: Error reading from input stream
at com.google.android.apps.gsa.staticplugins.recognizer.i.a.a(SourceFile:342)
at com.google.android.apps.gsa.staticplugins.recognizer.i.a$1.run(SourceFile:1367)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85)
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.g(SourceFile:2531)
at com.google.android.apps.gsa.speech.audio.ap.read(SourceFile:555)
at java.io.InputStream.read(InputStream.java:101)
at com.google.android.apps.gsa.speech.audio.al.run(SourceFile:362)
at com.google.android.apps.gsa.speech.audio.ak$1.run(SourceFile:471)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85)
04-29 12:20:07.717 2343-18556/com.google.android.googlequicksearchbox:search I/AudioController: internalShutdown
04-29 12:20:07.718 2343-2343/com.google.android.googlequicksearchbox:search I/MicroDetector: Keeping mic open: false
04-29 12:20:07.718 2343-2343/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #onError(false)
04-29 12:20:07.718 2343-18555/com.google.android.googlequicksearchbox:search I/DeviceStateChecker: DeviceStateChecker cancelled
04-29 12:20:08.132 1694-1719/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
04-29 12:20:08.134 1694-1719/system_process W/WindowManager: Failed looking up window
java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W#f29c3c4 does not exist
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:9415)
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:9406)
at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2387)
at com.android.server.wm.Session.remove(Session.java:193)
at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3290)
at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5917)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3626)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
04-29 12:20:08.146 2216-2360/com.google.android.apps.nexuslauncher W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
Here is the file code
public class GameLogin extends AppCompatActivity {
SharedPreferences sharedPref = GameLogin.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
EditText etEmail;
EditText etPassword;
Button bLogin;
TextView registerLink;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_login);
etEmail = (EditText) findViewById(R.id.etEmail);
etPassword = (EditText) findViewById(R.id.etPassword);
bLogin = (Button) findViewById(R.id.bLogin);
registerLink = (TextView) findViewById(R.id.tvRegisterHere);
registerLink.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Intent registerIntent = new Intent(GameLogin.this, GameRegister.class);
GameLogin.this.startActivity(registerIntent);
}
});
bLogin.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
final String email = etEmail.getText().toString();
final String password = etPassword.getText().toString();
Response.Listener<String> responceListener = new Response.Listener<String>(){
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponce = new JSONObject(response);
boolean success = jsonResponce.getBoolean("success");
if (success){
editor.putString(getString(R.string.player_data_gamename), jsonResponce.getString("gamename"));
editor.putString(getString(R.string.player_data_startdate), jsonResponce.getString("startdate"));
editor.putInt(getString(R.string.player_data_userid), jsonResponce.getInt("userid"));
editor.commit();
Intent intent = new Intent(GameLogin.this, GameUserArea.class);
GameLogin.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(GameLogin.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(email, password, responceListener);
}
});
}
}
When I run the below Java for Android code, I get a NullPointerException on the line that calls getSkuDetails in the doInBackground method in the GetItemList class. But when I step through in the debugger, all the parameters to getSkuDetails have values. pName is not an empty string and querySkus has two items in it. The exact error message I'm getting is "Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference." Does anyone know why?
package com.myknitcards;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.vending.billing.IInAppBillingService;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class AvailableCards extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
new GetItemList(packagename, priceView).execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}
Here's my log:
01-25 19:02:18.888: D/AndroidRuntime(4802): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:18.894: D/AndroidRuntime(4802): CheckJNI is OFF
01-25 19:02:18.951: D/ICU(4802): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:19.016: I/Radio-JNI(4802): register_android_hardware_Radio DONE
01-25 19:02:19.048: D/AndroidRuntime(4802): Calling main entry com.android.commands.pm.Pm
01-25 19:02:19.054: I/art(4802): System.exit called, status: 0
01-25 19:02:19.055: I/AndroidRuntime(4802): VM exiting with result code 0.
01-25 19:02:19.904: D/AndroidRuntime(4816): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:19.911: D/AndroidRuntime(4816): CheckJNI is OFF
01-25 19:02:19.969: D/ICU(4816): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:20.030: I/Radio-JNI(4816): register_android_hardware_Radio DONE
01-25 19:02:20.061: D/AndroidRuntime(4816): Calling main entry com.android.commands.am.Am
01-25 19:02:20.065: I/ActivityManager(607): Force stopping com.myknitcards appid=10087 user=-1: set debug app
01-25 19:02:20.066: I/ActivityManager(607): Killing 4727:com.myknitcards/u0a87 (adj 7): stop com.myknitcards
01-25 19:02:20.077: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:20.077: I/WindowState(607): WIN DEATH: Window{9799d39 u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:20.179: I/ActivityManager(607): Force finishing activity ActivityRecord{16bdee6 u0 com.myknitcards/.MyKnitCardsMain t53}
01-25 19:02:20.182: W/ActivityManager(607): Spurious death for ProcessRecord{d0de1a6 0:com.myknitcards/u0a87}, curProc for 4727: null
01-25 19:02:20.183: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.myknitcards/.MyKnitCardsMain} from uid 2000 on display 0
01-25 19:02:20.195: D/AndroidRuntime(4816): Shutting down VM
01-25 19:02:20.226: I/ActivityManager(607): Start proc 4826:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:20.233: I/art(4826): Late-enabling -Xcheck:jni
01-25 19:02:20.272: E/art(4826): Failed sending reply to debugger: Broken pipe
01-25 19:02:20.272: I/art(4826): Debugger is no longer active
01-25 19:02:20.292: W/ActivityThread(4826): Application com.myknitcards is waiting for the debugger on port 8100...
01-25 19:02:20.293: I/System.out(4826): Sending WAIT chunk
01-25 19:02:20.341: I/OpenGLRenderer(607): Initialized EGL, version 1.4
01-25 19:02:21.296: I/art(4826): Debugger is active
01-25 19:02:21.495: I/System.out(4826): Debugger has connected
01-25 19:02:21.495: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.695: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.895: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.096: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.297: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.498: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.698: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.898: I/System.out(4826): debugger has settled (1457)
01-25 19:02:22.975: W/System(4826): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:23.044: D/OpenGLRenderer(4826): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:23.076: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.080: D/Finsky(1556): [143] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.084: D/com.myknitcards(4826): In-app Billing is set up OK
01-25 19:02:23.105: I/Adreno-EGL(4826): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:23.108: I/OpenGLRenderer(4826): Initialized EGL, version 1.4
01-25 19:02:23.133: W/AppOps(607): Finishing op nesting under-run: uid 1000 pkg android code 24 time=1451855407389 duration=1783 nesting=0
01-25 19:02:23.222: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +3s7ms
01-25 19:02:23.225: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:23.231: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:24.523: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:24.524: I/ActivityManager(607): START u0 {cmp=com.myknitcards/.AvailableCards} from uid 10087 on display 0
01-25 19:02:24.533: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:24.533: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:24.533: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:24.542: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:24.666: I/ActivityManager(607): Displayed com.myknitcards/.AvailableCards: +134ms
01-25 19:02:24.667: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:24.719: D/OpenGLRenderer(4826): endAllStagingAnimators on 0xb388d500 (RippleDrawable) with handle 0xb36fe690
01-25 19:02:27.777: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:27.778: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:02:31.524: D/Synch Billing(4826): Error Null Pointer: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.741: W/System.err(4826): java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:87)
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:1)
01-25 19:02:34.742: W/System.err(4826): at android.os.AsyncTask$2.call(AsyncTask.java:295)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-25 19:02:34.743: W/System.err(4826): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
01-25 19:02:34.743: W/System.err(4826): at java.lang.Thread.run(Thread.java:818)
01-25 19:02:38.949: W/art(4826): Debugger told VM to exit with status 1
01-25 19:02:39.025: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:39.026: I/WindowState(607): WIN DEATH: Window{f33f18e u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:39.029: I/WindowState(607): WIN DEATH: Window{6d143a7 u0 com.myknitcards/com.myknitcards.AvailableCards}
01-25 19:02:39.047: I/Zygote(206): Process 4826 exited cleanly (1)
01-25 19:02:39.066: I/ActivityManager(607): Process com.myknitcards (pid 4826) has died
01-25 19:02:39.068: W/ActivityManager(607): Force removing ActivityRecord{d4915cb u0 com.myknitcards/.AvailableCards t54}: app died, no saved state
01-25 19:02:39.080: I/ActivityManager(607): Start proc 4874:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:39.100: I/art(4874): Late-enabling -Xcheck:jni
01-25 19:02:39.157: W/System(4874): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:39.223: D/OpenGLRenderer(4874): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:39.264: I/Adreno-EGL(4874): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:39.267: I/OpenGLRenderer(4874): Initialized EGL, version 1.4
01-25 19:02:39.342: D/Finsky(1556): [100] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.346: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.347: D/com.myknitcards(4874): In-app Billing is set up OK
01-25 19:02:39.404: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +335ms
01-25 19:02:39.404: W/InputMethodManagerService(607): Got RemoteException sending setActive(false) notification to pid 4826 uid 10087
01-25 19:02:39.412: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:40.885: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:40.888: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher (has extras)} from uid 1000 on display 0
01-25 19:02:40.895: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:40.895: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:40.895: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:40.905: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:41.013: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:41.014: I/art(607): Background partial concurrent mark sweep GC freed 25641(1654KB) AllocSpace objects, 19(376KB) LOS objects, 33% free, 18MB/27MB, paused 2.227ms total 106.933ms
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:43.233: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:43.616: I/PowerManagerService(607): Going to sleep due to lid switch (uid 1000)...
01-25 19:02:43.616: I/PowerManagerService(607): Sleeping (uid 1000)...
01-25 19:02:43.621: W/AudioPolicyIntefaceImpl(196): getOutputForAttr uid 10012 tried to pass itself off as 1000
01-25 19:02:43.622: W/AudioFlinger(196): uid 10012 tried to pass itself off as 1000
01-25 19:02:43.625: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:43.632: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:43.698: I/ActivityManager(607): Config changes=480 {1.0 310mcc?mnc en_US ldltr sw600dp w960dp h528dp 320dpi lrg land finger -keyb/v/h -nav/h s.6}
01-25 19:02:43.700: I/InputReader(607): Reconfiguring input devices. changes=0x00000004
01-25 19:02:43.700: I/InputReader(607): Device reconfigured: id=6, name='elan-touchscreen', size 1200x1920, orientation 1, mode 1, display id 0
01-25 19:02:43.703: V/AudioService.RotationHelper(607): publishing device rotation =1 (x90deg)
01-25 19:02:43.707: D/audio_hw_primary(196): adev_set_parameters: enter: rotation=90
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Music) in db, id: 4 (2, 0, 0, 0) --> (2, 0, 0, 0)
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Books) in db, id: 6 (2, 0, 1, 0) --> (2, 0, 1, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Movies & TV) in db, id: 8 (2, 0, 2, 0) --> (2, 0, 2, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Games) in db, id: 10 (2, 0, 3, 0) --> (2, 0, 3, 0)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Play Newsstand) in db, id: 12 (2, 0, 0, 1) --> (2, 0, 0, 1)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Google+) in db, id: 14 (2, 0, 1, 1) --> (2, 0, 1, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Keep) in db, id: 16 (2, 0, 2, 1) --> (2, 0, 2, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Calendar) in db, id: 20 (2, 0, 3, 1) --> (2, 0, 3, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Currents) in db, id: 22 (2, 0, 0, 2) --> (2, 0, 0, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Photos) in db, id: 24 (2, 0, 1, 2) --> (2, 0, 1, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Earth) in db, id: 26 (2, 0, 2, 2) --> (2, 0, 2, 2)
01-25 19:02:44.147: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:44.190: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.191: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.202: I/WindowManager(607): Screen frozen for +551ms due to Window{b92ff9b u0 com.android.launcher/com.android.launcher2.Launcher}
01-25 19:02:44.222: V/KeyguardServiceDelegate(607): onScreenTurnedOff()
01-25 19:02:44.249: I/DisplayManagerService(607): Display device changed state: "Built-in Screen", OFF
01-25 19:02:44.249: D/SurfaceFlinger(188): Set power mode=0, type=0 flinger=0xb6aa4000
01-25 19:02:44.529: D/SurfaceControl(607): Excessive delay in setPowerMode(): 280ms
01-25 19:02:44.530: E/ANDR-PERF-LOCK(204): Failed to apply optimization for resource: 4 level: 0
01-25 19:02:44.540: D/audio_hw_primary(196): adev_set_parameters: enter: screen_state=off
01-25 19:02:44.545: W/qcom_sensors_hal(607): hal_acquire_resources, no active sensors!
01-25 19:02:44.554: E/native(607): do suspend true
01-25 19:02:44.580: D/PhoneStatusBar(705): disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search quick_settings >
01-25 19:02:44.721: D/PhoneStatusBar(705): disable: < expand ICONS alerts SYSTEM_INFO back HOME* RECENT* clock SEARCH* quick_settings >
01-25 19:02:46.209: I/art(607): Starting a blocking GC Explicit
01-25 19:02:46.280: I/art(607): Explicit concurrent mark sweep GC freed 14241(923KB) AllocSpace objects, 8(160KB) LOS objects, 33% free, 17MB/26MB, paused 1.129ms total 70.343ms
01-25 19:02:46.953: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:46.953: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:03:03.251: D/WifiStateMachine(607): L2Connected CMD_START_SCAN source -2 41, 42 -> obsolete
01-25 19:03:03.787: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:14.835: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:29.947: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:41.038: E/(193): invalid crash request of size 4 (from pid=4794 uid=0)
01-25 19:03:41.165: E/Diag_Lib(4962): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.198: W/Sensors(4962): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f34a08
01-25 19:03:41.261: W/Sensors(4962): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:03:41.272: E/Sensors(4962): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:03:44.187: I/Keyboard.Facilitator.LanguageModelFlusher(1004): run()
01-25 19:03:44.188: I/Keyboard.Facilitator(1004): flushDynamicLanguageModels()
01-25 19:03:44.237: I/ConfigService(1203): onCreate
01-25 19:03:49.340: I/ConfigService(1203): onDestroy
01-25 19:03:54.819: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:09.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:57.794: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:12.826: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:13.472: E/(193): invalid crash request of size 4 (from pid=4962 uid=0)
01-25 19:05:13.615: E/Diag_Lib(4977): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:05:13.615: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.616: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.648: W/Sensors(4977): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6fc4a08
01-25 19:05:13.713: W/Sensors(4977): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:05:13.726: E/Sensors(4977): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:06:00.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:15.788: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:45.928: E/(193): invalid crash request of size 4 (from pid=4977 uid=0)
01-25 19:06:46.091: E/Diag_Lib(4991): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:06:46.091: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.092: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.119: W/Sensors(4991): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f2ea08
01-25 19:06:46.185: W/Sensors(4991): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:06:46.200: E/Sensors(4991): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:07:00.446: I/UsageStatsService(607): User[0] Flushing usage stats to disk
01-25 19:07:06.820: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:07:21.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:09.795: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:18.400: E/(193): invalid crash request of size 4 (from pid=4991 uid=0)
01-25 19:08:18.715: E/Diag_Lib(5008): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:08:18.717: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.718: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.748: W/Sensors(5008): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6ffca08
01-25 19:08:18.808: W/Sensors(5008): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:08:18.819: E/Sensors(5008): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:08:24.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:09:12.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
What could probably be happening is that mServiceConn instance of ServiceConnection connection class takes some time to connect, and until the connection is established, mService remains null.
To fix this, please try the following code:
public class AvailableCards extends Activity {
IInAppBillingService mService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
new GetItemList(packagename, priceView).execute();
}
};
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}