android-contentprovider

Android SQLite database and app update

青春壹個敷衍的年華 提交于 2019-11-29 21:44:13
I have developed an android app and released version 1.0. The app contains SQLite local database with 5 tables. Now we planned to release version 2.0 also update the version 1.0 users. In version 2.0 we have included extra two tables with previous 5 table, so 7 tables now. Now my question is, The version 1.0 users all have some data in the local database, If he update to the version 2.0 the previous data will get lost? If it so. then what is the alternate method? You should put all changes in your onUpgrade method you can use this code: @Override public void onUpgrade(SQLiteDatabase db, int

Android - sqlite content providers and multithreading

孤者浪人 提交于 2019-11-29 20:44:02
问题 I'm a little confused about content providers. If I have multiple activities in my application do they each get their own instance of the content provider? it's just essentially a class/interface? In one activity I will have many threads simultaneously writing to the database. How do I deal with allowing one thread to write at a time? Do I just catch SQLiteDatabaseLockedException, put the thread to sleep then retry? Or is there a better way? Are the database locks released when an activity

Android Contentprovider - update within an insert method

空扰寡人 提交于 2019-11-29 18:04:35
问题 Is it ok to call the SQLiteDatabase update method in the insert() overridden method of a content provider? 回答1: Basically it's fine, but since you didn't provided code, I just can post 2 possible ways for it First: // In your content provider public Uri insert(...) { long insertId = db.insert(...); if(insertId == -1) { // insert failed, do update db.update(...); } } Second: public Uri insert(...) { long insertId = db.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE)

Writing custom Content Provider for photos on phone (part 2)

邮差的信 提交于 2019-11-29 17:23:53
I'm working on a custom Content Provider for my app. This is part of a course I'm taking on Android apps, so please don't expect the rationale for doing all this to be too great ;-) The whole point here is for me to learn about CP. I've got a previous post which goes on and on with this , but I think I've managed to simplify my problem quite a bit. So, I'm working on a "gallery app". Since I don't know how and where thumbnail images are stored on the phone, I've decided to simply use MediaStore.Images.Thumbnails to access the thumbs, and show them in my GridView. However, to fullfill the

cursorboundexception whille displaying listview from content provider

白昼怎懂夜的黑 提交于 2019-11-29 16:42:29
somebody pls get me out of this.I am trying to display a list from an sqlite database which worked absolutely fine but dont know what went wrong it showed cant find provider info.I fixed it and then when i am running the code with list_cursor.moveToFirst() it just shows the 1st item in list again and again which proves that it is fetching data....When I use list_cursor.moveToNext() it shows the following exception:PLS HELP ME 10-13 15:11:41.017 5337-5337/com.phase3.mascotnew E/AndroidRuntime: FATAL EXCEPTION: main Process: com.phase3.mascotnew, PID: 5337 android.database

How can I get/set bookmarks per account on Android

旧时模样 提交于 2019-11-29 16:36:22
Managing bookmarks using Android's default Browser, one can see that they are different kind of bookmarks. Local bookmarks, per (Google) account bookmarks. Getting all bookmarks (local and per-account) is quite straightforward. Here is how I proceed: public static List<Bookmark> getBookmarks(ContentResolver contentResolver) { String[] projection = new String[] { BookmarkColumns._ID, BookmarkColumns.TITLE, BookmarkColumns.URL, BookmarkColumns.VISITS, BookmarkColumns.DATE, BookmarkColumns.FAVICON}; ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>(); Cursor cursor = contentResolver.query

Returning a memory mapped InputStream from a content provider?

霸气de小男生 提交于 2019-11-29 15:33:50
问题 The the client side of a content provider consumer I can do something like this, to get a proper InputStream for reading the picture: InputStream is = getContentResolver().openInputStream(pictureUri); It is a nice API, and will on the server side, the actual content provider result in a call to: public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { // Open a proper ParcelFileDescriptor, most likely using openFileHelper(uri, mode) } But what if the picture

Android - get date time from SMS timestamp in miliseconds

こ雲淡風輕ζ 提交于 2019-11-29 15:29:19
is it possible to convert Sms table date value e.g. 1293457709636 (miliseconds) to meaningful Date time value. just do long ms = 1293457709636; // or whatever you have read from sms Date dateFromSms = new Date(ms); You can convert Sms table date in to meaningful Date time like this. import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); Calendar calendar = Calendar.getInstance(); long now = 1293457709636L; calendar.setTimeInMillis(now); Log.i("time", "time"+formatter.format(calendar

Link Android application with contacts/phonebook programmatically

别说谁变了你拦得住时间么 提交于 2019-11-29 15:11:35
问题 I'm currently writing an App which allows to extend the standart Android contacts / phonebook. The user can add some informations / content associated with a specific contact. I want the standart phonebook to show an link to my application on every contact which has additional data in my application. For example WhatsApp is able to do so. If somebody from you phonebook has an WhatsApp account the phonebook displays a small WhatsApp icon next to the contact. If you hit the icon WhatsApp starts

How to represent 2 cursors as 1 sorted cursor?

自作多情 提交于 2019-11-29 14:47:39
I have 2 different sets of data, each of them use its own ContentProvider . Querying to them I can get 2 different cursors. Those 2 cursors has 2 different primary keys, but there's one and the same field ( DATE ) which I can use for ordering (other fields are different). My goal is to have one final merged Cursor which will be sorted by those DATE field. I have investigated MergeCursor but it doesn't fit to me, since it returns merged/concatenated (but not sorted Cursor ). Any ideas, clues? You can try this class from AOSP repository: https://android.googlesource.com/platform/frameworks/base