[android-developers] Re: Create database on sd card?
I have a bit of workaround to solve this. Although you will probably realize that this really doesn't seem like the final solution. Anyway, as a linux/unix variant, Android supports symbolic (or soft) links. Symbolic links allow you to tell the OS that a file is one directory when it is really in another. I had the same problem with a huge pre-built database (38MB). SqlOpenHelper wants to find its databases in /data/data//databases, so I created a symbolic link with the same name as my database there and pointed it to the real file in a directory on the sdcard. For instance, if I had a db called "mydb.sqlite" which is stored in the "/sdcard/myproj" directory which I want my Android app called "org.example.koolapp" to use, I would execute the following at the terminal/command prompt on my dev machine. adb shell ln -s /sdcard/myproj/mydb.sqlite /data/data/ org.example.koolapp/databases/mydb.sqlite A symbolic link is much smaller than the db and the SqlOpenHelper will now be able to find the db! Jack C. Holt Science Applications International Corporation twitter: hackeyflack On Oct 21, 1:29 pm, Mark Murphy wrote: > Markus wrote: > > I want to create a database that may become relatively large, a few > > megabytes maybe. maybe I should put this database on the sd card to > > save internal storage. > > > With SQLiteDatabase.openOrCreateDatabase() this should be quite > > straightforward. > > > But I'd like to use SQLiteOpenHelper since it takes care of creating > > and updating the db so nicely. Unfortunately SQLiteOpenHelper seems to > > be restricted to the internal storage. > > > Now I have noticed that SQLiteOpenHelper uses > > Context.openOrCreateDatabase() and Context.getDatabasePath() > > internally. > > For some reason, getReadableDatabase() uses getDatabasePath(), but > getWriteableDatabase() does not. That seems...odd. > > > Would it be too much of a dirty hack if I wrote my own ContextWrapper > > that implements these methods to create a database on the sd card? Or > > would this be a legitimate use of the API? > > That might work, but then if they change the implementation of > SQLiteOpenHelper, you might not realize that you also need to change > your ContextWrapper somehow to match. > > Since SQLiteOpenHelper is not that big and is only directly used by your > app, another approach is to grab their code, modify it to create an > SDOpenHelper that supports your database-on-SD model, and use that. > Assuming SQLiteOpenHelper is not using any package-private methods, of > course... > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > _Android Programming Tutorials_ Version 1.0 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: webview tel: URLs
Like Mark Murphy guessed, I set the WebViewClient and put some code in shouldOverrideUrlLoading() to do this. I created a method called setWebViewClient(WebView view) which creates an anonymous class for the WebViewClient that starts out like this... --- private void setWebViewClient(final WebView view) { view.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { . . . --- Inside the shouldOverrideUrlLoading() method I have code like the following if (url.startsWith("mailto:";) || url.startsWith("geo:") || url.startsWith("tel:") || url.startsWith("http://";) || url.startsWith("https://";)) { Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } This causes the Activity that is registered to handle each protocol type to automatically respond and load up. Jack C. Holt jackcholt.blogspot.com Twitter: hackeyflack --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to find the height of HTML content displayed in a webview
Yes there does seem to be a problem with View.getContentHeight(). I developed a small app that demonstrates a problem with the value returned in portrait versus landscape mode. I only tested this in the emulator using 1.5. When I press Ctrl-F12 to switch orientation repeatedly, I get 0 in portrait and > 0 in landscape. Here is the code: -- package com.jackcholt; import android.util.Log; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class DLSP extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_dlsp); final WebView dlspView = (WebView) findViewById (R.id.dlspView); dlspView.loadData("KEY WEST, Fla. — A ship last used by the U.S. Air Force to track missiles and spacecraft " + "became the world's second-largest intentionally sunk artificial reef Wednesday. " + "Using explosives attached to the hull, crews sank the decommissioned Gen. Hoyt S. " + "Vandenberg about seven miles off Key West, Fla. " + "The scheduled 10 a.m. blast to force the hulking vessel to the ocean floor was " + "delayed by about 20 minutes because of sealife in the vicinity — specifically, sea turtles. " + "Officials hope the newly sunken ship will attract fish and divers and relieve " + "recreational pressure on nearby natural reefs. " + "Beach in the Florida Panhandle.", "text/plain", "utf-8"); setWebViewClient(dlspView); } private void setWebViewClient(final WebView view) { view.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(final WebView view, final String url) { Log.i("DLSP", "Content Height: " + view.getContentHeight()); } }); } } --- Here's view_dlsp.xml: http://schemas.android.com/apk/res/ android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Commit default.properties?
Either this was a dumb question :) or maybe its just that sometimes you just have to be your own expert (no one responded to this, heellooo eecchhh). For anyone that finds this thread and has the same question; for the good of the community, I recommend that default.properties NOT be checked into your version control system. I believe it is never good to check in generated files. On May 18, 7:50 am, "Jack C. Holt" wrote: > I'm using the 1.5_r1 SDK. I notice that there is a generated file > called "default.properties" in the root directory of my project. The > comment inside the file says that it is GENERATED by Android Tools, > yet the comment also says "This file must be checked in Version > Control Systems." Is this a typo? Was the word "not" accidentally > left out? Why should a generated file be checked in? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Commit default.properties?
I'm using the 1.5_r1 SDK. I notice that there is a generated file called "default.properties" in the root directory of my project. The comment inside the file says that it is GENERATED by Android Tools, yet the comment also says "This file must be checked in Version Control Systems." Is this a typo? Was the word "not" accidentally left out? Why should a generated file be checked in? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Context Menu calling Activity.onMenuItemSelected() instead of Activity.onContextMenuItemSelected()
I have a ListActivity that I have registered a context menu for by calling registerForContextMenu(getListView()). I have also overridden onCreateContextMenu() as follows: public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, DELETE_ID, 0, R.string.really_delete); } and onContextItemSelected() as follows: public boolean onContextItemSelected(final MenuItem item) { switch (item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); long bookId = menuInfo.id; ContentResolver res = getContentResolver(); Uri thisBookUri = ContentUris.withAppendedId(mBookUri, bookId); Cursor bookCurs = managedQuery(thisBookUri, new String[] { YbkProvider.FILE_NAME }, null, null, null); String fileName = bookCurs.moveToFirst() ? bookCurs.getString(0) : null; File file = new File(fileName); if (file.exists()) { file.delete(); } res.delete(ContentUris.withAppendedId(mBookUri, bookId), null, null); refreshBookList(); return true; default: return super.onContextItemSelected(item); } } According to the documentation that I could find -- http://developer.android.com/reference/android/app/Activity.html#onCreateContextMenu(android.view.ContextMenu,%20android.view.View,%20android.view.ContextMenu.ContextMenuInfo) and http://developer.android.com/guide/topics/ui/menus.html -- clicking the item context menu should cause onContextItemSelected() to be called. Instead I noticed that Activity.onMenuItemSelected() was being called. Weird? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Jumping to #link after using loadDataWithBaseURL()
Well, I now have the solution and it had nothing to do with requestFocusNodeHref() and a lot to do with using javascript. But I believe I was right about my code being in the call tree of loadDataWithBaseUrl(). What I had to do was turn on Javascript by using this code: WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); And then in the definition of the WebViewClient I had to implement the onPageFinished(WebView, String) method. I used the following code: public void onPageFinished(final WebView view, final String url) { // make it jump to the internal link if (mFragment != null) { view.loadUrl("javascript:location.href=\"#" + mFragment + "\""); mFragment = null; } } The loadUrl() method causes the javascript to run. VERY IMPORTANT: I had to make sure to set the mFragment to null because the loadUrl() method caused the onPageFinished() method to get called again. If mFragment was not set to null onPageFinished() would get called again while mFragment was still non-null and an endless loop would have been the result. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Jumping to #link after using loadDataWithBaseURL()
Well, I'm either stumping everyone or have asked a stupid question ;^)... I think the problem may be that the call to loadDataWithBaseUrl() is within the WebView's webViewClient.shouldOverrideUrlLoading() method and therefore cannot run the javascript at that point. I'm now investigating using code like the following in the shouldOverrideUrlLoading() method: - webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { ... Message hrefMsg = android.os.Message.obtain(); view.requestFocusNodeHref(hrefMsg); ... return true; } }); - But I'm uncertain how to properly place the information about the internal link href in the Message to make this work. I have searched all over the android Google groups and can't find anything about it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Jumping to #link after using loadDataWithBaseURL()
I have googled for strings like "WebView internal link", read the FAQs, and read the online docs for WebView, WebSettings, WebViewClient, WebChromeClent and still I have not been able to determine how to make the web pages I have generated (which contain internal links [i.e., tags]) jump to an internal link once loaded with WebView.loadDataWithBaseURL(). I have even tried turning on javascript in the WebView using the following code: WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); Then I added the following javascript to the end of my generated HTML (but before the closing ): location.href="#12";alert('running javascript') I then load the generated HTML into my WebView using code like the following: webView.loadDataWithBaseURL( "content://com.example.app/gen", generatedHtml, "text/html","utf-8",""); The web page never jumps to the internal link and I never see any indication that the alert box was sent. In other words, the javascript may not be running. Anyway, I don't really want to use javascript to jump to the internal link but it is one method I have tried. I'd rather do it without javascript anyway. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Jumping to #link after using loadDataWithBaseURL()
Sorry, I forgot to mention that I am using the .loadDataWithBaseUrl() method. I assume that if I had used the loadUrl() this would not be an issue but I need to generate the HTML that is to be displayed in the WebVew. BTW, I tried appending the fragment (i.e., "#12" to the end of the base URL and it made no difference. On Dec 31 2008, 5:49 pm, "Jack C. Holt" wrote: > I am loading some HTML into a WebView that contains internal links > (i.e., tags). > > How do I make the WebView jump to that location once the WebView is > loaded? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Jumping to #link after using loadDataWithBaseURL()
I am loading some HTML into a WebView that contains internal links (i.e., tags). How do I make the WebView jump to that location once the WebView is loaded? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ContentProvider/SQLiteDatabase.delete() Docs
Does this fall under the "Note About API Documentation" sticky post? i.e., since it isn't documented, don't use it? On Dec 4, 9:52 am, "Jack C. Holt" <[EMAIL PROTECTED]> wrote: > The online docs for ContentProvider/SQLiteDatabase.delete() do not > document the third parameter "String[] whereArgs". > > I assume that the idea is that the second parameter (the where clause) > could contain replaceable parameters in the form of question marks (?) > and the Strings contained in the whereArgs array would replace the > question marks in the where clause. > > Could someone verify/debunk this assumption? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Cannot delete rows from sqlite database
See http://code.google.com/android/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction() On Nov 17, 3:28 pm, techvd <[EMAIL PROTECTED]> wrote: > Hi, > > I'm having a strange issue deleting rows from a sqlite database. > Here's the code snippet: > > mDb.beginTransaction(); > int nRows = mDb.delete("mytable", KEY_ITEM + "=" + rowId, > null); > mDb.endTransaction(); > return nRows > 0; > > The database is opened for write. The code above executes perfectly; > it even returns the number of rows deleted. However, the rows are > still in the table (even after I exit the app restart, etc.). Am I > missing anything here. The rest of the code is boilerplate and I can > read the data from the tables fine. > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] ContentProvider/SQLiteDatabase.delete() Docs
The online docs for ContentProvider/SQLiteDatabase.delete() do not document the third parameter "String[] whereArgs". I assume that the idea is that the second parameter (the where clause) could contain replaceable parameters in the form of question marks (?) and the Strings contained in the whereArgs array would replace the question marks in the where clause. Could someone verify/debunk this assumption? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---