Text to Voice for Keyboard - java

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
}
});

Related

MediaRecorder stop() failed

I know there are a few of these on SO already but none of them really were able to help my issue, but when I am running the code and start recording audio and then press my stop button it always fails because it is in the wrong state. I am not sure how I would go about fixing my states for this.
Here is my MainActivity.java code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.IOException;
import static android.Manifest.permission.RECORD_AUDIO;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class MainActivity extends AppCompatActivity {
Button buttonStartRecording, buttonStopRecording, buttonPlayLastRecordAudio,
buttonStopPlayingRecording;
String AudioSavePathInDevice = null;
MediaRecorder mediaRecorder;
public static final int RequestPermissionCode = 1;
MediaPlayer mediaPlayer;
AudioManager audioManager;
boolean isAudioPlayInSameDevice = true;
// AudioRouter audioRouter;
RadioGroup mRadioGroup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStartRecording = (Button) findViewById(R.id.start_recording);
buttonStopRecording = (Button) findViewById(R.id.stop_rec);
buttonPlayLastRecordAudio = (Button) findViewById(R.id.play_last_rec);
buttonStopPlayingRecording = (Button) findViewById(R.id.stop_playing_btn);
// mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);
buttonStopRecording.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(false);
buttonStopPlayingRecording.setEnabled(false);
buttonStartRecording.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onClick(View view) {
// Check audio permission
if (checkPermission()) {
AudioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "AudioRecording.3gp";
// Start Media recorder
MediaRecorderReady();
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
buttonStartRecording.setEnabled(false);
buttonStopRecording.setEnabled(true);
Toast.makeText(MainActivity.this, "Recording started",
Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
});
buttonStopRecording.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buttonStopRecording.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(true);
buttonStartRecording.setEnabled(true);
buttonStopPlayingRecording.setEnabled(false);
// Stop Media recorder
mediaRecorder.stop();
Toast.makeText(MainActivity.this, "Recording Completed",
Toast.LENGTH_LONG).show();
}
});
buttonPlayLastRecordAudio.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException {
int selectedId = 1;
if (selectedId == 1) {
isAudioPlayInSameDevice = true;
} else {
isAudioPlayInSameDevice = false;
}
// if you want to play audio on your Mobile speaker then set isAudioPlayInSameDevice true
// and if you want to play audio to connected device then set isAudioPlayInSameDevice false.
if (isAudioPlayInSameDevice) {
audioManager.setMode(audioManager.STREAM_MUSIC);
audioManager.setSpeakerphoneOn(true);
} else {
audioManager.setSpeakerphoneOn(false);
audioManager.setMode(audioManager.MODE_NORMAL);
}
audioManager.setBluetoothScoOn(false);
audioManager.stopBluetoothSco();
buttonStopRecording.setEnabled(false);
buttonStartRecording.setEnabled(false);
buttonStopPlayingRecording.setEnabled(true);
mediaPlayer = new MediaPlayer();
try {
// Start media player
System.out.println("Recorded Audio Path-" + AudioSavePathInDevice);
mediaPlayer.setDataSource(AudioSavePathInDevice);
if (isAudioPlayInSameDevice) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(MainActivity.this, "Recording Playing",
Toast.LENGTH_LONG).show();
}
});
buttonStopPlayingRecording.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buttonStopRecording.setEnabled(false);
buttonStartRecording.setEnabled(true);
buttonStopPlayingRecording.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(true);
if (mediaPlayer != null) {
// Stop Media Player
mediaPlayer.stop();
mediaPlayer.release();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
MediaRecorderReady();
}
}
}
});
}
private BroadcastReceiver mBluetoothScoReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
System.out.println("ANDROID Audio SCO state: " + state);
if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {
/*
* Now the connection has been established to the bluetooth device.
* Record audio or whatever (on another thread).With AudioRecord you can record with an object created like this:
* new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
* AudioFormat.ENCODING_PCM_16BIT, audioBufferSize);
*
* After finishing, don't forget to unregister this receiver and
* to stop the bluetooth connection with am.stopBluetoothSco();
*/
}
}
};
#RequiresApi(api = Build.VERSION_CODES.O)
public void MediaRecorderReady() {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_2_TS);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
#Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
registerReceiver(mBluetoothScoReceiver, intentFilter);
audioManager = (AudioManager) getApplicationContext().getSystemService(getApplicationContext().AUDIO_SERVICE);
// Start Bluetooth SCO.
audioManager.setMode(audioManager.MODE_NORMAL);
audioManager.setBluetoothScoOn(true);
audioManager.startBluetoothSco();
// Stop Speaker.
audioManager.setSpeakerphoneOn(false);
}
#Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mBluetoothScoReceiver);
// Stop Bluetooth SCO.
audioManager.stopBluetoothSco();
audioManager.setMode(audioManager.MODE_NORMAL);
audioManager.setBluetoothScoOn(false);
// Start Speaker.
audioManager.setSpeakerphoneOn(true);
}
private void requestPermission() {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{WRITE_EXTERNAL_STORAGE, RECORD_AUDIO}, RequestPermissionCode);
}
#Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case RequestPermissionCode:
if (grantResults.length > 0) {
boolean StoragePermission = grantResults[0] ==
PackageManager.PERMISSION_GRANTED;
boolean RecordPermission = grantResults[1] ==
PackageManager.PERMISSION_GRANTED;
// if (StoragePermission && RecordPermission) {
// Toast.makeText(BluetoothAudioRecorder.this, "Permission Granted",
// Toast.LENGTH_LONG).show();
// } else {
// Toast.makeText(BluetoothAudioRecorder.this,"Permission Denied",Toast.LENGTH_LONG).show();
// }
}
break;
}
}
public boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(getApplicationContext(),
WRITE_EXTERNAL_STORAGE);
int result1 = ContextCompat.checkSelfPermission(getApplicationContext(),
RECORD_AUDIO);
return result == PackageManager.PERMISSION_GRANTED &&
result1 == PackageManager.PERMISSION_GRANTED;
}
}
And then my logcat of when the error occurs:
2019-11-24 11:26:54.440 29627-29683/com.example.esense_application E/libc: Access denied finding property "vendor.gralloc.disable_ahardware_buffer"
2019-11-24 11:26:54.435 29627-29627/com.example.esense_application W/RenderThread: type=1400 audit(0.0:17779): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=24699 scontext=u:r:untrusted_app:s0:c7,c257,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
2019-11-24 11:26:54.487 29627-29627/com.example.esense_application I/System.out: ANDROID Audio SCO state: 1
2019-11-24 11:26:54.487 29627-29627/com.example.esense_application I/System.out: ANDROID Audio SCO state: 2
2019-11-24 11:26:54.868 29627-29627/com.example.esense_application I/System.out: ANDROID Audio SCO state: 1
2019-11-24 11:26:57.769 29627-29627/com.example.esense_application I/System.out: ANDROID Audio SCO state: 1
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: java.io.FileNotFoundException: /storage/emulated/0/AudioRecording.3gp: open failed: EACCES (Permission denied)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at libcore.io.IoBridge.open(IoBridge.java:496)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.media.MediaRecorder.prepare(MediaRecorder.java:1046)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at com.example.esense_application.MainActivity$1.onClick(MainActivity.java:67)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.view.View.performClick(View.java:7140)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.view.View.performClickInternal(View.java:7117)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.view.View.access$3500(View.java:801)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.view.View$PerformClick.run(View.java:27351)
2019-11-24 11:27:00.647 29627-29627/com.example.esense_application W/System.err: at android.os.Handler.handleCallback(Handler.java:883)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at android.os.Handler.dispatchMessage(Handler.java:100)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at android.os.Looper.loop(Looper.java:214)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7356)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at libcore.io.Linux.open(Native Method)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: at libcore.io.IoBridge.open(IoBridge.java:482)
2019-11-24 11:27:00.648 29627-29627/com.example.esense_application W/System.err: ... 15 more
2019-11-24 11:27:03.528 29627-29627/com.example.esense_application E/MediaRecorder: stop called in an invalid state: 4
2019-11-24 11:27:03.528 29627-29627/com.example.esense_application D/AndroidRuntime: Shutting down VM
2019-11-24 11:27:03.529 29627-29627/com.example.esense_application E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.esense_application, PID: 29627
java.lang.IllegalStateException
at android.media.MediaRecorder.stop(Native Method)
at com.example.esense_application.MainActivity$2.onClick(MainActivity.java:98)
at android.view.View.performClick(View.java:7140)
at android.view.View.performClickInternal(View.java:7117)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27351)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
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:930)
2019-11-24 11:27:03.540 29627-29627/com.example.esense_application I/Process: Sending signal. PID: 29627 SIG: 9
Your MediaRecorder is throwing when you try to stop() it because it has never entered the "recording" state. In fact, it never even entered the "prepared" state, because your call to prepare() did not complete successfully.
SOLUTION
Do not allow a call to start() until the prepare() call has returned (without throwing).
Do not allow a call to stop() until the start() call has returned (without throwing).
Make sure you have chosen a valid location for your output file. Try using getExternalFilesDir( null ) instead of Environment.getExternalStorageDirectory(). The bad file path is the reason your prepare() call is currently failing with an EACCESS.
As you can see, swallowing exceptions without addressing their root cause (i.e., just doing a e.printStackTrace() and carrying on), can rapidly lead to problems -- even in rough code used for learning/experimentation. If you are going to add an exception handler, it is better to provide real error handling -- and always make sure you understand why an exception is being thrown.

Multiple MediaPlayers keep failing - Android studio

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());
}

MediaPlayer music Android Studio

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'

How to fix HandleSignInResult return false?

I'm making a notes app using firebase auth and realtime database.
I'm stuck at the setup of google authentication.
this is my Code:
`package zohar.com.blablabla;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
public class LoginActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {
SignInButton signInButton;
GoogleApiClient mGoogleApiClient;
public static final int RC_SIGN_IN = 9001;
public static final String TAG = "SignInActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signInButton = (SignInButton) findViewById(R.id.signInButtonGoogle);
signInButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
signIn();
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
//connected successfully
Toast.makeText(this, "You are successfully connected!", Toast.LENGTH_SHORT).show();
Intent toMainActivityIntent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(toMainActivityIntent);
}
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed:" + connectionResult);
Toast.makeText(this, "We are currently facing with google/'s api issues,
please try again later", Toast.LENGTH_LONG).show();
}
}`
The problam is that every time when I click on the sign in button its not even showing the account picker (I dont know if its importent but I have more than 1 google accounts on my emulator). When I click it the screen turns little dark and than turns regular.
Everytime HandleSignInResult returns False.
*I did register my project and insert the sha-1.
**Sorry if I made some spelling/grammar mistakes. I'm still learning english and it's not my primary language.
Thanks.
EDIT: This are the warns:
08-14 10:52:34.116 2355-2355/? W/art: Unexpected CPU variant for X86 using
defaults: x86
08-14 10:52:34.404 2355-2355/zohar.com.notescloud W/System: ClassLoader
referenced unknown path: /data/app/zohar.com.notescloud-2/lib/x86
08-14 10:52:34.564 2355-2378/zohar.com.notescloud W/DynamiteModule: Local
module descriptor class for com.google.firebase.auth not found.
08-14 10:52:34.579 2355-2378/zohar.com.notescloud W/DynamiteModule: Local
module descriptor class for com.google.firebase.auth not found.
08-14 10:52:35.009 2355-2355/zohar.com.notescloud 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
08-14 10:52:35.209 2355-2355/zohar.com.notescloud W/System: ClassLoader referenced unknown path:
08-14 10:52:35.405 2355-2355/zohar.com.notescloud W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000006/n/x86
08-14 10:52:35.856 2355-2430/zohar.com.notescloud W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-14 10:52:36.030 2355-2355/zohar.com.notescloud 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
c
Debug:
08-14 11:02:08.029 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=46612, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=3256989730768445770}]
08-14 11:02:08.072 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LoginActivity, firebase_previous_id(_pi)=3256989730768445770, firebase_screen_class(_sc)=SignInHubActivity, firebase_screen_id(_si)=3256989730768445773}]
08-14 11:02:08.178 2355-11693/zohar.com.notescloud D/FA: Connected to remote service
08-14 11:02:08.183 2355-2430/zohar.com.notescloud D/EGL_emulation: eglMakeCurrent: 0x9aa2b320: ver 2 0 (tinfo 0x9c741ef0)
08-14 11:02:08.205 2355-2430/zohar.com.notescloud D/EGL_emulation: eglMakeCurrent: 0x9aa2b320: ver 2 0 (tinfo 0x9c741ef0)
08-14 11:02:08.947 2355-2355/zohar.com.notescloud D/SignInActivity: handleSignInResult:false
08-14 11:02:08.953 2355-11693/zohar.com.notescloud D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SignInHubActivity, firebase_previous_id(_pi)=3256989730768445773, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=3256989730768445770}]
EDIT2: FIXED!
I was so dumb and gave the auto-completion make GOOGLE_SIGN_IN to GOOGLE_GAMES_SIGN_IN.
Sry guys.

Java for Android Null Pointer Exception on IInAppBillingService.getSkuDetails

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;
}
}

Categories

Resources