cant read file from data/data/pkg/files/...

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

cant read file from data/data/pkg/files/...

Postby komal339 » Mon Mar 30, 2009 3:50 am

Hi,
I am saving an image using openFileOutput and now i want to use this
image in my java script file.
I am saving image using this code :

Bitmap b=DownloadImage(imageUrl);
FileOutputStream fos = mcontx.openFileOutput(imageName,
Context.MODE_WORLD_WRITEABLE);
b.compress(CompressFormat.JPEG,75, fos);
fos.flush();
fos.close();


It successfully write the image , i can see it in the file explorer of
emulator.
and i can display that image using openFileInput in image view.
But,,
There is another activity where i am using webview to call javascript.
i want to read that image in my javascript.my javascript code is ::


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
</head>
<script language="javascript">
/* This function is invoked by the activity */
function display() {

var path="data/data/com.android.mypkg/files/"+window.mypage.getImageName();
document.getElementById("img").src=path;


}

</script>

<body onLoad="window.mypage.callAndroid()">
<!-- Calls into the javascript interface for the activity -->
<img id="img" src="" />

<p>
<b> <script type="text/javascript">
var hl=window.mypage.getHeadline();
document.write(hl);
</script>
</b>
</p>
</body>
</html>


it is not displaying an image.
can i read file from data/data/pkg/files/... directly like this?
Please help me
Thanx
komal339
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 6:10 am

Top

Postby flyer » Mon Mar 30, 2009 8:05 am

that path is the web server path, not your emulaotor path. you put that impage to web server www.xxx.com/image/path
flyer
Freshman
Freshman
 
Posts: 8
Joined: Mon Jan 14, 2008 7:07 am

Postby komal339 » Mon Mar 30, 2009 11:12 am

I dont want to save that image at server,, i want to save it in the android file system. because i want to use it when internet connection not is available.
komal339
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 6:10 am

Postby flyer » Tue Mar 31, 2009 2:46 am

if you just want to tell the user that connection is not available, you can change other way such as use ImageView.
and you also can use common View and dialog . but WebView is not a good idea beacuase the connection is not availbe . you can do nothing with it .

or
you can put a html page and a image file to that assets folder and directly edit that html page
like this : <html> <body> <image src="yourimage.png"></body></html> .
so use your WebView to open that page when you are offline

I hope this is helpful four you and sorry for my English
the following attachemnt is a sample from google
Attachments
WebViewDemo.rar
WebViewDemo
(52.17 KiB) Downloaded 52 times
flyer
Freshman
Freshman
 
Posts: 8
Joined: Mon Jan 14, 2008 7:07 am

Postby komal339 » Tue Mar 31, 2009 4:15 am

Hi flyer
Thanx for your reply

Basically i am downloading an image when internet is available and saving it in data/data/pkg/files/filename.jpg
As file:\\android_asset is in apk and is read only i cant save anything in this folder at run time.

when internet is not available and user use my app than i want to display that image from data/data/pkg/files/..
I want to display html page in my app and i want to use webview.

Is it possible to read from data/data/pkg...?

if yes, what mistake m i making?

Thanx in advance.
komal339
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 6:10 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests