bullheadandplato / AndroidEqualizer

Android Equalizer View that can also manage the audio track frequencies
Apache License 2.0
236 stars 72 forks source link

My App crashes while trying to show dialog #9

Closed ArvinCS closed 4 years ago

ArvinCS commented 4 years ago

`package me.arvin.audiofy.audioplayer;

import me.arvin.audiofy.R;

import android.app.Activity; import android.app.ActivityManager; import android.os.Handler; import android.os.Build; import android.content.Context; import android.content.ComponentName; import android.util.Log;

import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager;

import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger;

import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.PluginRegistry.Registrar;

import com.bullhead.equalizer.DialogEqualizerFragment;

public class EqualizerPlugin implements MethodCallHandler { private static final Logger LOGGER = Logger.getLogger(EqualizerPlugin.class.getCanonicalName());

private final MethodChannel channel;
private final Handler handler = new Handler();

private Context context;
private FragmentActivity activity;

public static void registerWith(final Registrar registrar) {
    final MethodChannel channel = new MethodChannel(registrar.messenger(), "arvinciu/equalizer");
    channel.setMethodCallHandler(new EqualizerPlugin(channel, ((FragmentActivity)registrar.activity())));
}

private EqualizerPlugin(final MethodChannel channel, FragmentActivity activity) {
    this.channel = channel;
    this.activity = activity;
    this.context = activity.getApplicationContext();
    this.channel.setMethodCallHandler(this);
}

@Override
public void onMethodCall(final MethodCall call, final MethodChannel.Result response) {
    try {
    handleMethodCall(call, response);
    } catch (Exception e) {
    dispose();
    LOGGER.log(Level.SEVERE, "Unexpected error!", e);
    response.success(0); // error
    }
}

@SuppressWarnings("unchecked")
private void handleMethodCall(final MethodCall call, final MethodChannel.Result response) {
    final int sessionId = call.argument("sessionId");
    handleSendMessage("id: " + sessionId);
    switch (call.method) {
        case "show": {
            DialogEqualizerFragment fragment = DialogEqualizerFragment.newBuilder()
                .setAudioSessionId(sessionId)
                .themeColor(ContextCompat.getColor(this.context, R.color.EqprimaryColor))
                .textColor(ContextCompat.getColor(this.context, R.color.EqtextColor))
                .accentAlpha(ContextCompat.getColor(this.context, R.color.EqplayingCardColor))
                .darkColor(ContextCompat.getColor(this.context, R.color.EqprimaryDarkColor))
                .setAccentColor(ContextCompat.getColor(this.context, R.color.EqsecondaryColor))
                .build();

            try{
                if(!activity.isFinishing())fragment.show(activity.getSupportFragmentManager(), "equalizer");
            } catch (Exception e){
                handleSendMessage(e.toString());
            }
        }
    }
    response.success(2);
}

public void handleSendMessage(String text) {
    channel.invokeMethod("audio.sendMessage", buildArguments(text));
}

private static Map<String, Object> buildArguments(Object value) {
    Map<String, Object> result = new HashMap<>();
    result.put("value", value);
    return result;
}

private void dispose() {

}

}`

Can you help me what's wrong with my code? There is a difference with the code, because i'm connecting Flutter with Java so the code must like that. Thank you!

bullheadandplato commented 4 years ago

What is exception?

ArvinCS commented 4 years ago

I tried to get the error log, but it crashed without any log

ArvinCS commented 4 years ago

I'm sure session id etc aren't null. It crashed when show() method invoked

bullheadandplato commented 4 years ago

Without crash logs I cannot identify the issue

ArvinCS commented 4 years ago

Yeah me too :( I followed all the instruction step by step

bullheadandplato commented 4 years ago

Did you find the issue?