语言

Menu
Sites
Language
How to display local HTML/CSS in a webview?

Hello

I am new to Tizen, and I need your advice to make it work.

I created a "new tizen native project", then I selected "empty application".

After that I added into the "res" directory some "index.html".

I want to figure out what is the minimum code to just display this index.html full screen when the application is launched.

I only modified two files. And I called my app "koko" because I thought it sounded well, don't you.

This is what I tried :

> koko.cpp :
I added : using namespace Tizen::Web::Controls; So now I have :
using namespace Tizen::App;
using namespace Tizen::Base;
using namespace Tizen::System;
using namespace Tizen::Ui;
using namespace Tizen::Ui::Controls;
using namespace Tizen::Web::Controls;

And bellow I have this code, I which I only added the bold part :

bool
kokoApp::OnAppInitializing(AppRegistry& appRegistry)
{
    // TODO:
    // Initialize App specific data.
    // The App's permanent data and context can be obtained from the appRegistry.
    //
    // If this method is successful, return true; otherwise, return false.
    // If this method returns false, the App will be terminated.

    // Uncomment the following statement to listen to the screen on/off events.
    //PowerManager::SetScreenEventListener(*this);

    // Create a Frame
    kokoFrame* pkokoFrame = new kokoFrame;
    pkokoFrame->Construct();
    pkokoFrame->SetName(L"koko");
    AddFrame(*pkokoFrame);

    // LAUNCH THE WEBVIEW
    LoadUrl();

    // TODO: Add your initialization code here
    return true;
}

That is all, then I added the LoadUrl method in koko.h :

> koko.h :
public:
    void
    LoadUrl(void)
    {
        Tizen::Web::Controls::Web* pWeb = new Tizen::Web::Controls::Web();

        pWeb->LoadUrl(L"http://www.tizen.org");
    }

(Note : I tried with L"http://www.tizen.org" to be sure it worked but then I'll change for this : L"file:///opt/usr/apps/koko/res/index.html")

The build is ok, but when I try on the emulator, the application doesn't even get launched. I looked at the log, I get :

ERROR / Tizen::Ui ( 2584 : 2584 ) : Tizen::Ui::_KeyEventManagerImpl::_KeyEventManagerImpl() (146). > [E_SYSTEM] pKeyMgr == null
ERROR / Tizen::Base ( 2584 : 2584 ) : result Tizen::Base::String::SubString(int, Tizen::Base::String&) const (1113). > [E_OUT_OF_RANGE] The startIndex(11) MUST be greater than or equal to 0, and less than the length of this string(11).
ERROR / Tizen::Base ( 2584 : 2584 ) : result Tizen::Base::String::SubString(int, Tizen::Base::String&) const (1113). > [E_OUT_OF_RANGE] The startIndex(11) MUST be greater than or equal to 0, and less than the length of this string(11).
ERROR / Tizen::Security ( 2043 : 2043 ) : static result Tizen::Security::_PrivilegeManager::RetrieveCipherPrivilegeEx(const Tizen::App::AppId&, Tizen::Base::String&, Tizen::Base::String&) (233). > [E_DATA_NOT_FOUND] The privilege information does not exist.
ERROR / Tizen::Security ( 2584 : 2584 ) : static void Tizen::Security::_AccessController::Initialize() (172). > Failed to retrieve privilege information
ERROR / Tizen::Security ( 2584 : 2584 ) : static result Tizen::Security::_AccessController::CheckUserPrivilege(Tizen::Security::_Privilege) (223). > [E_DATA_NOT_FOUND] The privilege information does not exist.
ERROR / Tizen::Security ( 2584 : 2584 ) : static result Tizen::Security::_AccessController::CheckUserPrivilege(Tizen::Security::_Privilege) (262). > [E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.
ERROR / Tizen::Web::Controls ( 2584 : 2584 ) : void Tizen::Web::Controls::Web::LoadUrl(const Tizen::Base::String&) (89). > [E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.

(I don't understand most of the above).

Do you have any advice so It could work ??

Please help ><

Jean

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

11 回复
kavish
Hi jeanlou, Just go to the Native application which you have created and select manifest.xml file. In manifest.xml you have to add two privileges. To add these privileges go to Privileges tab and click on Add button after that select privileges which you want to add. http://tizen.org/privilege/web.privacy http://tizen.org/privilege/web.service After adding these two privileges build and run your application.
youngsik yoon
And then you better use GetAppResourcePath() like this. ->LoadUrl(L"file://" + GetAppResourcePath() + L"your-local.html")
loubin
Hello Thank you so much for your replies. I made all of your mentioned modifications, but unfortunately now, the application crash as soon as I launch it : "koko has closed unexpectedly". The log are shorter : ERROR / Tizen::Ui ( 2486 : 2486 ) : Tizen::Ui::_KeyEventManagerImpl::_KeyEventManagerImpl() (146). > [E_SYSTEM] pKeyMgr == null ERROR / Tizen::Base ( 2486 : 2486 ) : result Tizen::Base::String::SubString(int, Tizen::Base::String&) const (1113). > [E_OUT_OF_RANGE] The startIndex(11) MUST be greater than or equal to 0, and less than the length of this string(11). ERROR / Tizen::Base ( 2486 : 2486 ) : result Tizen::Base::String::SubString(int, Tizen::Base::String&) const (1113). > [E_OUT_OF_RANGE] The startIndex(11) MUST be greater than or equal to 0, and less than the length of this string(11). Do you have any idea ? What does this mean? :0
kavish
Hi jeanlou, E_OUT_OF_RANGE means "The value of the argument is outside the valid range defined by the method." So just check the value of argument you are passing in method. Whatever you are passing value it will be less then that. E_SYSTEM means "The method cannot proceed due to a severe system error. "
loubin
Hi Kavish Thank your for your explanations. However I don't see how to solve the problem as I don't see anywhere in my code where is would use any "SubString" the log seems to say : result Tizen::Base::String::SubString(int, Tizen::Base::String&) const (1113)> [E_OUT_OF_RANGE]
kavish
Hi jeanlou, Just debug your application and see where is the problem. To Debugging Applications on the Emulator use below link. https://developer.tizen.org/help/topic/org.tizen.native.appprogramming/html/app_dev_process/debugging_app_emulator.htm To Debugging Applications on a Target Device use given link. https://developer.tizen.org/help/topic/org.tizen.native.appprogramming/html/app_dev_process/debugging_app_target.htm
loubin
Hi Kavish Thank your for helping ! I just tried the debugging applications, but it can't run well because of these errors I got in the log I suppose : .gdbinit: No such file or directory. Reading symbols from /Users/remy/tizen_workspace/koko/Debug-Tizen-Emulator/koko.exe...done. warning: Could not load shared library symbols for 205 libraries, e.g. /usr/lib/libsys-assert.so. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? warning: Could not load shared library symbols for /usr/lib/libslp_devman_plugin.so. (etc..) I couldn't find clear fixing method by googling this one either..
kavish
OnInitializing(void) { result r = E_SUCCESS; __pWeb = new Web(); __pWeb->Construct(Rectangle(10, 10, 470, 400)); AddControl(*__pWeb); if (__pWeb) { __pWeb->SetLoadingListener(this); r = __pWeb->AddJavaScriptBridge(*this); } String url(L"file://"); // Use the GetAppDataPath() method to access data directory path. // If it will not work for res folder then Keep the index.html file data folder url.Append(App::GetInstance()->GetAppDataPath() + L"index.html"); AppLog("url = %ls, GetValidUrl", url.GetPointer(), GetValidUrl(url).GetPointer()); __pWeb->LoadUrl(url); --- return r; } Check with this code and it will work for you.
kavish
You have to use the IJavaScriptBridge interface because it provides a communication channel between JavaScript and native object.
loubin
Thank you for your answers ! I tried to implement your code and this is what I had to face : 1 - As often in the documentation (https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.apireference%2FclassTizen_1_1Web_1_1Controls_1_1Web.html), you have "OnInitializing(void)" but when you create a new project, you only have kokoApp::OnAppInitializing(AppRegistry& appRegistry) Is this the same thing after all? Because if I create my own "OnInitializing" class it won't be automatically launched at app initialization right? If I just change it to put void instead of "AppRegistry& appRegistry" (in koko.h) I get this warning "'kokoApp::OnAppInitializing' hides overloaded virtual function [-Woverloaded- virtual]" which I don't understand either. 2 - It can't build due to several errors : UiApp* kokoApp::CreateInstance(void) { // Create the instance through the constructor. return new kokoApp(); } This throws "allocating an object of abstract class type 'kokoApp'" error 3 - Then in your code I put in OnAppInitializing(void), you didn't specify about any Frame creation? should I still put it as I did? 4 - This r = __pWeb->AddJavaScriptBridge(*this); throws "no viable conversion from 'kokoApp' to 'const Tizen::Web::Controls::IJavaScriptBridge'" 5 - I also get the error "use of undeclared identifier 'GetValidUrl'", and couldn't find out what to import and where, so as it works. 6 - What do you mean by "---" ? Sorry for the many questions ... t_t
kavish
It will be good to share more code snippet so that easy to find out what mistake you have done. It also help to solve your problem.