didimoo / AndroidLocalStorage

How to implement correctly a LocalStorage feature in Android Webview
Apache License 2.0
85 stars 28 forks source link

The Given JS interface is NOT working. #1

Closed shantanookirtane closed 10 years ago

shantanookirtane commented 10 years ago

Please refer to the following stackoverflow page where I have posted details about the issue I am facing.

http://stackoverflow.com/questions/21298664/javascript-interface-not-working-in-my-android-application

Issue: The LocalStorage is NOT working for me. I tried adding some items in LocalStorage but when I am closing the application and opening again those items from Localstorage are getting wiped out.

didimoo commented 10 years ago

Hi ! Have you tried the given sample to check that it was working ? It seems that you've removed the fragment. I don't think that it is necessary. But since you didn't use the sample as it is, it is more difficult for me to find what is not working for you... Maybe you are missing a permission or something else.

You have tried the sample on your computer ? It was designed to be used on Android and not on a laptop's navigator which has already a working localStorage.

shantanookirtane commented 10 years ago

Hi

Thanks for the attention, I will try your project today on Samsung Note (OS 4.1.2), once I do that I will update with my objservation

shantanookirtane commented 10 years ago

By mistake I closed the issue so reponed again

shantanookirtane commented 10 years ago

I tried importing your project into my local workspace so that I can transfer the same to my Samsung Note 4.1.2 But there are lot of issues with your code. The code is not even compiling.

Adding screen shots for your reference.

issue_with_project

Following is my Android SDK in my workspace.

my_android_setup

didimoo commented 10 years ago

It is quite easy, it doesn't compile since you don't have the 17 API level installed on your computer. You have two solutions : either you download it through the Android SDK Manager, or you check another version (for example the 16) in the project's preferences. It should make everything work ;)

ggendre commented 10 years ago

Also, add an empty "gen" folder on your project root, so that Eclipse can build the projet.

shantanookirtane commented 10 years ago

Le me check this out today

Sorry if i have made any silly mistakes.... On 28 Jan 2014 05:39, "Guillaume Gendre" notifications@github.com wrote:

Also, add an empty "gen" folder on your project root, so that Eclipse can build the projet.

— Reply to this email directly or view it on GitHubhttps://github.com/didimoo/AndroidLocalStorage/issues/1#issuecomment-33467355 .

shantanookirtane commented 10 years ago

Hi

Thanks for your guidance, I checked today with your code and it works fine for me.

But when I added same in my code it is not working for me. I am clueless.

Can you and May you help me in resolving this issue? or am I asking too much

didimoo commented 10 years ago

Hi !

Ok, I'm relieved. I can first take a quick look at your code to see if any detail appears to me.

shantanookirtane commented 10 years ago

Me too :)

I am attaching here the latest .java files and few xml's for you to take a look at.

And in my custom.js I am doing following to set and get Item from localStorage.

-- first statement in my .js

try{ //we replace default localStorage with our Android Database one window.localStorage = LocalStorage; }catch(e){ //LocalStorage class was not found. be sure to add it to the webview alert("LocalStorage ERROR : can't find android class LocalStorage. switching to raw localStorage") }

Mostly I am setting up objects like map or array into localstorage.

-- setting into localstorage localStorage.setItem('videoListService', setObj(videoListMap));

-- getting from locaStorage

getObj(localStorage.getItem('videoListService'));

where

setObj is js function

function setObj(obj) { return JSON.stringify(obj); }

function getObj(obj) { return JSON.parse(obj); }

Your help is highly appreciated!!!

On 29 January 2014 04:24, Diane notifications@github.com wrote:

Hi !

Ok, I'm relieved. I can first take a quick look at your code to see if any detail appears to me.

— Reply to this email directly or view it on GitHubhttps://github.com/didimoo/AndroidLocalStorage/issues/1#issuecomment-33568126 .

Thanks & Regards, Shantanoo Kirtane

To enable ProGuard in your project, edit project.properties

to define the proguard.config property as described in that file.

#

Add project specific ProGuard rules here.

By default, the flags in this file are appended to flags specified

in ${sdk.dir}/tools/proguard/proguard-android.txt

You can edit the include path and order by changing the ProGuard

include property in project.properties.

#

For more details, see

http://developer.android.com/guide/developing/tools/proguard.html

Add any project specific keep options here:

If your project uses WebView with JS, uncomment the following

and specify the fully qualified class name to the JavaScript interface

class:

-keepclassmembers class fqcn.of.javascript.interface.for.webview {

public *;

}

shantanookirtane commented 10 years ago

Hey

Sorry if I am annoying you but Did you get a chance to look at my code, do you see any obivous thing?

Thanks in advance!!!

didimoo commented 10 years ago

Your code seems clean. Have you just changed the JavaScript code ?

shantanookirtane commented 10 years ago

yeah But not around localstorage.....

So u r saying everything is correct from the code prespective.? On 31 Jan 2014 05:23, "Diane" notifications@github.com wrote:

Your code seems clean. Have you just changed the JavaScript code ?

— Reply to this email directly or view it on GitHubhttps://github.com/didimoo/AndroidLocalStorage/issues/1#issuecomment-33775103 .

didimoo commented 10 years ago

It seems so. But for example, if you set the webview not the way it should be, it may not work the way you want !

What did you change in you java code ?

shantanookirtane commented 10 years ago

Related to webview.....

I m not loading webview by find(R.id.Webview) but instead Webview = new Webview(this)

And setContent(webview)

Also i have not changed anything in progaurd.xml..... is that required for app to work On 31 Jan 2014 07:04, "Diane" notifications@github.com wrote:

It seems so. But for example, if you set the webview not the way it should be, it may not work the way you want !

What did you change in you java code ?

— Reply to this email directly or view it on GitHubhttps://github.com/didimoo/AndroidLocalStorage/issues/1#issuecomment-33788910 .

didimoo commented 10 years ago

you use setContent (i don't know this method) or setContentView ? Do you have the init(); call ? Is it not possible for you to initialize your view with XML ?

shantanookirtane commented 10 years ago

Sorry setContentView

I can use view through xml that should not be an issue...

But do u know why my code is not working

Am i exploiting u r code in any way..... On 31 Jan 2014 07:29, "Diane" notifications@github.com wrote:

you use setContent (i don't know this method) or setContentView ? Do you have the init(); call ? Is it not possible for you to initialize your view with XML ?

— Reply to this email directly or view it on GitHubhttps://github.com/didimoo/AndroidLocalStorage/issues/1#issuecomment-33790249 .

shantanookirtane commented 10 years ago

Hey Just checking...... Did you notice anything which should not be coded the way it should be? Any clue why my code is not working but yours :) :(

I am really perplexed now.

shantanookirtane commented 10 years ago

The code is working for me :+1:
The issue was with the targetSdkVersion value, I was using 18 and should have used 19 as I am not setting a DB path in my app

Closing the issue