Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploading problem #39

Closed
cs-marcoblagoiev opened this issue Jan 29, 2016 · 23 comments
Closed

File uploading problem #39

cs-marcoblagoiev opened this issue Jan 29, 2016 · 23 comments
Labels

Comments

@cs-marcoblagoiev
Copy link

I'm trying to implement file uploading in an app, and I'm testing on a phone with Android 5.0.1.

When I click the upload button, I can choose a file that i need, but after i select it, it doesn't appear selected in browser (this is how the looks like after i select the image:
image
)

Also, i have added <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> in my manifest file.

Any help is appreciated :)

@ocram ocram added the question label Jan 29, 2016
@ocram
Copy link
Contributor

ocram commented Jan 29, 2016

Thanks for your question!

  1. Did you really include the class from this library instead of the normal WebView class? That means, do you have <im.delight.android.webview.AdvancedWebView ...> in your layout XML?
  2. Did you implement all methods calls correctly, as shown in the project description? Most importantly, do you have the call to mWebView.onActivityResult(...) in the method onActivityResult(...) of your Activity or Fragment?
  3. Do you use Fragment?

@cs-marcoblagoiev
Copy link
Author

  1. Yes, I did.
  2. & 3. I am using Fragments ( android.support.v4.app.Fragment ). Yes, i implemented all the methods. This is the onActivityResult method from my Fragment:
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        webView.onActivityResult(requestCode, resultCode, intent);
        // ...
    }

Also, in the Activity that calls the Fragment that I'm using, i have this method:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        FragmentManager fragmentManager = getSupportFragmentManager();
        Fragment fragment = fragmentManager.findFragmentByTag("test");
        if (fragment != null) {
            ((CreditsFragment) fragment).onActivityResult(requestCode, resultCode, data);
        }
    }

Hope that i understood correctly how I was supposed to implement those methods.

@cristinaITdeveloper
Copy link

I have the same problem!

@ocram
Copy link
Contributor

ocram commented Feb 23, 2016

Thanks for the additional details, @marcoblagoiev and @LadyDeveloper!

  1. Do you have mWebView.setListener(getActivity(), this) in the onCreateView method of your Fragment?
  2. In the onActivityResult method of your Activity, can you add a unique logging statement or call to System.out.println after the super.onActivityResult line?
  3. In the onActivityResult method of your Fragment, can you add a unique logging statement or call to System.out.println after the super.onActivityResult line?
  4. Can you test the file upload and check if both logging statements from (2) and (3) are executed?
  5. Do you have ProGuard enabled? Did you include the ProGuard directives from the README?

@zilions
Copy link

zilions commented Mar 6, 2016

I am experiencing the exact same problem on Android 5.0.2, Am able to select a file, although it does not send the image data to the webview...

@ocram
Copy link
Contributor

ocram commented Mar 7, 2016

@zilions So have you tried the things I've suggested in the previous comment?

Or can you post excerpts from both your Activity and Fragment?

I can only imagine this is because the events are not correctly redirected from the Activity to the Fragment.

What you all seem to have in common is that you're using the Fragment class from android.support.v4, right?

@nashirox
Copy link

nashirox commented Mar 7, 2016

I have same problem now. Activity
And @mwaclawek was mentioned above, i called to System.out.println after the super.onActivityResult line.
and it says

I/chromium: [INFO:CONSOLE(0)] "event.returnValue is deprecated. Please use the standard event.preventDefault() instead.", source:  (0)

Any help is appreciated.

@ocram
Copy link
Contributor

ocram commented Mar 7, 2016

@nashirox That warning is not related. Can you please try the suggestions posted in my previous two comments? Or post the important parts of your Activity and Fragment classes?

@nashirox
Copy link

nashirox commented Mar 7, 2016

@mwaclawek thx for your reply.
Bellow is my code and I have <im.delight.android.webview.AdvancedWebView ...> in R.layout.activity_image_app_view.

public class ImageAppViewActivity extends AppCompatActivity implements AdvancedWebView.Listener {
    private AdvancedWebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_app_view);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");

        TextView textTitle = (TextView) toolbar.findViewById(R.id.textTitle);
        textTitle.setText("");

        ToggleButton toggle = (ToggleButton) toolbar.findViewById(R.id.toggle1);

        toggle.setVisibility(View.GONE);

        setupWebView();

        FlurryAgent.onPageView();
    }

    private void setupWebView() {
        mWebView = (AdvancedWebView) findViewById(R.id.advWebView);
        mWebView.setListener(this, this);
        mWebView.loadUrl("https://github.com/delight-im/Android-AdvancedWebView");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_image_app_view, menu);
        return true;
    }

    @SuppressLint("NewApi")
    @Override
    protected void onResume() {
        super.onResume();
        mWebView.onResume();
    }

    @SuppressLint("NewApi")
    @Override
    protected void onPause() {
        super.onPause();
        mWebView.onPause();
    }

    @SuppressLint("NewApi")
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mWebView.destroy();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mWebView.onPause();
    }

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

        Intent intent;

        switch (id) {
            case android.R.id.home:
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                } else {
                    super.onBackPressed();
                }
                break;
            case R.id.action_refresh:
                mWebView.reload();
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        System.out.println();
        mWebView.onActivityResult(requestCode, resultCode, intent);
    }

    @Override
    public void onPageStarted(String s, Bitmap bitmap) {

    }

    @Override
    public void onPageFinished(String s) {

    }

    @Override
    public void onPageError(int i, String s, String s1) {

    }

    @Override
    public void onDownloadRequested(String s, String s1, String s2, String s3, long l) {

    }

    @Override
    public void onExternalPageRequest(String s) {

    }
}

Bellow is activity_image_app_view.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.nashirox.view.main.ImageAppViewActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:theme="@style/ActionBarStyle"
        android:minHeight="?attr/actionBarSize"
        app:contentInsetStart="0dp"
        android:layout_gravity="center">

        <RelativeLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                android:text="site title"
                android:id="@+id/textTitle" android:textColor="@color/white" android:maxLines="1"
                android:layout_weight="1"
                android:ellipsize="end"
                android:layout_centerVertical="true" android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" android:layout_toLeftOf="@+id/toggle1"
                android:layout_toStartOf="@+id/toggle1"/>

            <ToggleButton
                android:id="@+id/toggle1"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:background="@drawable/follow_toggle"
                android:checked="false"
                android:clickable="true"
                android:text=""
                android:textOff=""
                android:textOn="" android:layout_alignParentTop="true"
                android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <im.delight.android.webview.AdvancedWebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/advWebView"
        android:layout_below="@+id/toolbar"
        android:layout_alignParentStart="true"/>
</RelativeLayout>

@ocram
Copy link
Contributor

ocram commented Mar 7, 2016

@nashirox Thanks! So it appears you're not using any Fragment here. That's fine. But in the onActivityResult method of your ImageAppViewActivity class, you wrote System.out.println(). Can you change this to something that actually prints some string, e.g. System.out.println("onActivityResult is being called")? Now when you select a file in the file input, that string should be logged and appear in your console. Can you check this?

Apart from that, what's the site that you're trying to use the file upload on? Where exactly is the file input and what's the HTML for that input field? Can you try the following URL instead?

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_accept

@nashirox
Copy link

nashirox commented Mar 7, 2016

@mwaclawek Im so appreciate your kindness. thx in advance.
First of all, I change System.out.println() to System.out.println("onActivityResult is being called"), and after select a file, console says I/System.out: onActivityResult is being called.

Secondly, http://slot-gazo.com/post is the site what i am trying to upload a file.

Thirdly, I tried http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_accept instead of the site abobe.
and it seems to be ok ...

2016-03-07 10 17 18

after click send button.

2016-03-07 10 17 24

@nashirox
Copy link

nashirox commented Mar 7, 2016

@mwaclawek It seems to be file selected, but HTML form cannot access selected image file...

@zilions
Copy link

zilions commented Mar 8, 2016

Managed to get it working. I'm using the .java file instead of the JAR library now, fixed all my issues. This is an amazing enhancement to the webview. The file input is now working on all different Android versions without any problems. Thanks for sharing this!

@nashirox
Copy link

nashirox commented Mar 8, 2016

As @zilions did, I changed using the .java file instead of JAR. But nothing gonna changed the situation.
Anyway, It would seems to be get correct intent in onActivityResult.
Intent { dat=content://com.android.providers.media.documents/document/image:4672 flg=0x1 }
But HTML input form doesn't accept uriString in intent such as content://com.android.providers.media.documents/document/image%3A4672

@ocram
Copy link
Contributor

ocram commented Mar 8, 2016

@nashirox In your case, everything seems to be working fine, actually. You can see this from the onActivityResult is being called log message that is correctly logged and the w3schools.com test site that is working as intended. Since the w3schools.com site with the basic <input type="file"> is working, the library seems to be working fine for you. If the other site you mentioned is not working, it can only be due to the different HTML. I saw there was a hidden file input and some more complex HTML/JS code. Is that log message shown in the console for both sites whenever you select the file?

@zilions Oh, great to hear that! And thanks for your appreciation! But that's still really strange and shouldn't be happening. Maybe we can find the cause for these issues together. Are you using ProGuard for obfuscation? Were you using an outdated JAR perhaps? When you included the Java source file directly now, did you change the package name at the top?

@zilions
Copy link

zilions commented Mar 9, 2016

Only been using Android Studio for a week or so, bare with me. Didn't change the package name of the JAR file. I know I included it correctly since Java knew all the class/function names and was throwing no errors within my main activity Java file. Not using ProGuard or obfuscation. The error was thrown during build, can't remember what it was right now sorry. Changed form the JAR file to the Java library instead and everything worked very well. Also deleted all of my code and replaced it with your code. I had a small error occur, but found it and fixed it since I was still using a custom web chrome client, so I removed it and everything went well.

@airanode
Copy link

Thank your for sharing this @mwaclawek. I just start today using your JAR and its working great, its easy to access files and GPS now.

@ocram
Copy link
Contributor

ocram commented Mar 11, 2016

@zilions Wish I knew what was causing the trouble in your case. That's really strange. But great that you could solve the problem!

@XeMoX Thanks for your appreciation :) Great to hear that!

@ocram
Copy link
Contributor

ocram commented Mar 30, 2016

You can all include this library via a Maven-based Gradle dependency now (please see README). No need for copying JARs of source code anymore. Sorry for the delay!

@ocram ocram closed this as completed Mar 30, 2016
@umairnow
Copy link

I have implemented the example with an activity, but when I press choose File, no picker is showing up. I am using this library with Gradle

@ocram
Copy link
Contributor

ocram commented May 26, 2016

@umairnow Thanks! What Android version are you running this on? Can you share the code that you used to set up this library? Did you read what the README says about file uploads?

@umairnow
Copy link

It's just not working on kitkat API 16 to 18. on other APIs it's working fine

@ocram
Copy link
Contributor

ocram commented May 27, 2016

@umairnow For the KitKat issue, please see the various other issues where this has already been discussed, e.g. #4 Thanks!

@delight-im delight-im locked and limited conversation to collaborators May 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants