Hi, first post here
Looked a bit around, and hopefully I managed to hit the right subforum where this belong, anyway.
This question as been asked very frequently and has been answered to some extent. Having the html file in /assets folder at runtime works. But how is this solved if the html is saved with the application when run?
My situation at the moment is that I'm trying to make a RSS-feed that will save the html pages for later reading. As of now the progress I have is that I have no problems loading a saved page I put in the /assets folder. But if I save them on the sdcard/internal storage I will just get "Web page not available". I've confirmed that the file on the emulator (by pulling the file from the directory) is the same as I would be putting in the /asset folder.
So basically. Anyone been wondering the same or a general idea what "Web page not available" is caused. Any help would be appreciated.
Code for saving the content of a website (source code of a webpage of course):
Manifest file:
Looked a bit around, and hopefully I managed to hit the right subforum where this belong, anyway.
This question as been asked very frequently and has been answered to some extent. Having the html file in /assets folder at runtime works. But how is this solved if the html is saved with the application when run?
My situation at the moment is that I'm trying to make a RSS-feed that will save the html pages for later reading. As of now the progress I have is that I have no problems loading a saved page I put in the /assets folder. But if I save them on the sdcard/internal storage I will just get "Web page not available". I've confirmed that the file on the emulator (by pulling the file from the directory) is the same as I would be putting in the /asset folder.
So basically. Anyone been wondering the same or a general idea what "Web page not available" is caused. Any help would be appreciated.
Code for saving the content of a website (source code of a webpage of course):
Code:
public class SaveWebPage extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
processHttp("test.html");
} catch (Exception e) {
e.printStackTrace();
}
mWebView = (WebView) findViewById(R.id.webkit);
/* This will load a file in the asset folder (works) */
mWebView.loadUrl("file:///android_asset/data.html");
/* Trying to load a local file on the sdcard (Will not work) */
//mWebView.loadUrl("/sdcard/test.html");
}
public void processHttp(String saveAs) throws Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.google.com");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpClient.execute(httpGet, responseHandler);
File file = new File(Environment.getExternalStorageDirectory().toString(), saveAs);
OutputStream outStream = new FileOutputStream(file);
outStream.write(response.getBytes());
outStream.close();
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.savepage"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
android:debuggable="true"
<activity android:name=".SaveWebPage"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>