Opencv stopped working on Android 6.0

asked 2015-11-23 07:45:57 -0600

am using Opencv on my application and it works fine with Android 4.3 but it doesn't even open with Android 6.0.

I looked up for a solution on SO, and found one that says to set the package name. So I did it.

Follow code:

 public static boolean initOpenCV(String Version, final Context AppContext,
    final LoaderCallbackInterface Callback)
 {
        AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback);
        Intent intent = new Intent("org.opencv.engine.BIND");
        intent.setPackage("org.opencv.engine");
        if (AppContext.bindService(intent,
              helper.mServiceConnection, Context.BIND_AUTO_CREATE))
       {
                return true;
        }
       else
       {
            AppContext.unbindService(helper.mServiceConnection);
            InstallService(AppContext, Callback);
           return false;
        }
 }

But now I am getting the following error:

11-18 10:14:43.447 24901-24930/br.com.ibramed.dermos E/AndroidRuntime:      android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
11-18 10:14:43.447 24901-24930/br.com.ibramed.dermos E/AndroidRuntime:     at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
11-18 10:14:43.447 24901-24930/br.com.ibramed.dermos E/AndroidRuntime:     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
11-18 10:14:43.447 24901-24930/br.com.ibramed.dermos E/AndroidRuntime:     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
11-18 10:14:43.447 24901-24930/br.com.ibramed.dermos E/AndroidRuntime:     at android.app.Dialog.show(Dialog.java:319)

in the following code:

 case InstallCallbackInterface.NEW_INSTALLATION:
    {
        Looper.prepare();
        Log.d("Debug", ""+mAppContext);
        AlertDialog InstallMessage = new AlertDialog.Builder(mAppContext).create();
        InstallMessage.setTitle("Package not found");
        InstallMessage.setMessage(callback.getPackageName() + " package was not found! Try to install it?");
        InstallMessage.setCancelable(false); // This blocks the 'BACK' button
        InstallMessage.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                callback.install();
            }
        });

        InstallMessage.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new OnClickListener() {

            public void onClick(DialogInterface dialog, int which)
            {
                callback.cancel();
            }
        });

        InstallMessage.show();
    } break;

I have searched and found some people saying to keep track of the main Context, because Threads doesn't have context. But my app already does this and use the main context to create the AlertDialogs and it still doesn't work.

The error is when the app show the AlertDialog.

I really don't know what else to do. Can someone help?

edit retag flag offensive close merge delete