Android Intent setType and addCategory methods causing build errors

1k views Asked by At

I'm working on an application that I compiled using Website2Apk and reverse engineered to turn into a workable project within Android Studio. I started with 115 errors, and now I've narrowed it down to just eight. Six of these build errors are related to the setType and addCategory methods in one of the java files. I'm at a complete loss towards what could be causing these errors.

Here is my code for that specific java file:

package com.valen.plazaone;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.Parcelable;
import android.util.Log;
import android.webkit.GeolocationPermissions.Callback;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebChromeClient.FileChooserParams;
import android.webkit.WebView;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.lang.Object;

/* renamed from: com.valen.plazaone.c */
class C0002c extends WebChromeClient {
    final /* synthetic */ MainActivity f11a;

    C0002c(MainActivity mainActivity) {
        this.f11a = mainActivity;
    }

    private File m5a() {
        return File.createTempFile("JPEG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + "_", ".jpg", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
    }

    public void onGeolocationPermissionsShowPrompt(String str, Callback callback) {
        callback.invoke(str, true, false);
    }

    public void onProgressChanged(WebView webView, int i) {
        if (i < 100 && this.f11a.f4d.getVisibility() == 8) {
            this.f11a.f4d.setVisibility(0);
        }
        this.f11a.f4d.setProgress(i);
        if (i == 100) {
            this.f11a.f4d.setVisibility(8);
        }
    }

    public boolean onShowFileChooser(WebView webView, ValueCallback valueCallback, FileChooserParams fileChooserParams) {
        File a;
        Throwable e;
        Intent intent;
        Parcelable intent2;
        Parcelable[] parcelableArr;
        Object[] objArr;
        Intent intent3;
        if (this.f11a.f7h != null) {
            this.f11a.f7h.onReceiveValue(null);
        }
        this.f11a.f7h = valueCallback;
        Intent intent4 = new Intent("android.media.action.IMAGE_CAPTURE");
        if (intent4.resolveActivity(this.f11a.getApplicationContext().getPackageManager()) != null) {
            try {
                a = m5a();
                try {
                    intent4.putExtra("PhotoPath", this.f11a.f8i);
                } catch (IOException e2) {
                    e = e2;
                    Log.e(MainActivity.f0f, "Unable to create Image File", e);
                    if (a != null) {
                        this.f11a.f8i = "file:" + a.getAbsolutePath();
                        intent4.putExtra("output", Uri.fromFile(a));
                    } else {
                        intent4 = null;
                    }
                    intent = new Intent("android.media.action.VIDEO_CAPTURE");
                    intent2 = new Intent("android.intent.action.GET_CONTENT");
                    intent2.addCategory();
                    intent2.setType("*/*");
                    if (intent == null) {
                        parcelableArr = new Intent[]{intent, intent4};
                    } else if (intent4 != null) {
                        objArr = new Intent[]{intent4};
                    } else {
                        parcelableArr = new Intent[0];
                    }
                    intent3 = new Intent("android.intent.action.CHOOSER");
                    intent3.putExtra("android.intent.extra.INTENT", intent2);
                    intent3.putExtra("android.intent.extra.TITLE", "Upload Files");
                    intent3.putExtra("android.intent.extra.INITIAL_INTENTS", parcelableArr);
                    this.f11a.startActivityForResult(intent3, 1);
                    return true;
                }
            } catch (IOException e3) {
                e = e3;
                a = null;
                Log.e(MainActivity.f0f, "Unable to create Image File", e);
                if (a != null) {
                    intent4 = null;
                } else {
                    this.f11a.f8i = "file:" + a.getAbsolutePath();
                    intent4.putExtra("output", Uri.fromFile(a));
                }
                intent = new Intent("android.media.action.VIDEO_CAPTURE");
                intent2 = new Intent("android.intent.action.GET_CONTENT");
                intent2.addCategory("android.intent.category.OPENABLE");
                intent2.setType("*/*");
                if (intent == null) {
                    parcelableArr = new Intent[]{intent, intent4};
                } else if (intent4 != null) {
                    parcelableArr = new Intent[0];
                } else {
                    objArr = new Intent[]{intent4};
                }
                intent3 = new Intent("android.intent.action.CHOOSER");
                intent3.putExtra("android.intent.extra.INTENT", intent2);
                intent3.putExtra("android.intent.extra.TITLE", "Upload Files");
                intent3.putExtra("android.intent.extra.INITIAL_INTENTS", parcelableArr);
                this.f11a.startActivityForResult(intent3, 1);
                return true;
            }
            if (a != null) {
                this.f11a.f8i = "file:" + a.getAbsolutePath();
                intent4.putExtra("output", Uri.fromFile(a));
            } else {
                intent4 = null;
            }
        }
        intent = new Intent("android.media.action.VIDEO_CAPTURE");
        intent2 = new Intent("android.intent.action.GET_CONTENT");
        intent2.addCategory("android.intent.category.OPENABLE");
        intent2.setType("*/*");
        if (intent == null) {
            parcelableArr = new Intent[]{intent, intent4};
        } else if (intent4 != null) {
            objArr = new Intent[]{intent4};
        } else {
            parcelableArr = new Intent[0];
        }
        intent3 = new Intent("android.intent.action.CHOOSER");
        intent3.putExtra("android.intent.extra.INTENT", intent2);
        intent3.putExtra("android.intent.extra.TITLE", "Upload Files");
        intent3.putExtra("android.intent.extra.INITIAL_INTENTS", parcelableArr);
        this.f11a.startActivityForResult(intent3, 1);
        return true;
    }
}

This specific error happens with all intent2's followed by a setType or addCategory. Does anyone know how to fix this error?

Thanks in advance.

1

There are 1 answers

4
Kamran Ahmed On

Either change the declaration of the variable intent2 from:

Parcelable intent2;

to:

Intent intent2;

Or if for some reason you cannot change that, type cast it to Intent whenever you are calling a method on it like:

((Intent) intent2).addCategory();
((Intent) intent2).setType("*/*");