[android-developers] Re: [android-kernel] A simplest Application access "Content Provider"
Hi, getcontentResolver() is the method of Context class which is the super class of activity, so any non activity class cannot get access to the content resolver object.. one work around(even though its not good practice to do..)pass the content resolver object as parameter to the function you want to use it from another class which is a activity, but in your case i don't think you have that option of passing content resolver object from another class as you have only one class that is calling main in your program. On May 6, 7:51 am, linlo...@gmail.com wrote: > Sorry, > > I've corrected it. > If you have any idea about this issue, please help check it. > > Thanks. > > 2010/5/5 Mateusz Kozak > > > > > Why are you posting this on Android-kernel not on android-platform? > > > W dniu 2010-05-05 13:57 użytkownik napisał: > > > hi, > > > Usually, we can inherit class "Activity" to access "Content Provider", such > > as SMS/Contacts with following codes: > > === > > public class ActivityTest extends Activity { > > ... > > private void insertSms(String str_address, String content){ > > ContentResolver contentResolver = getContentResolver(); > > String strUriInbox = "content://sms/inbox"; > > ContentValues values = new ContentValues(); > > values.put("address", str_address); > > values.put("date", Calendar.getInstance().getTime().getTime()); > > values.put("protocol", "0"); > > values.put("status", "-1"); > > values.put("type", "1"); > > values.put("body", content); > > Uri uriSms = Uri.parse(strUriInbox); > > contentResolver.insert(uriSms, values); > > } > > } > > === > > > However, I don't want to show a activity if write SMS database. So, I > > design a simplest application without Activity with following codes: > > === > > package com.xxx.NoActivityTest; > > > public class NoActivityTest { > > public NoActivityTest(){ > > } > > > private void insertSms(String str_address, String content){ > > ContentResolver contentResolver = *getContentResolver*(); > > *//"NoActivityTest" > > don't inherit from "Activity", so, don't recongnize "getContentResolver()", > > so, can't get "ContentResolver" instance.* > > String strUriInbox = "content://sms/inbox"; > > ContentValues values = new ContentValues(); > > values.put("address", str_address); > > values.put("date", Calendar.getInstance().getTime().getTime()); > > values.put("protocol", "0"); > > values.put("status", "-1"); > > values.put("type", "1"); > > values.put("body", content); > > Uri uriSms = Uri.parse(strUriInbox); > > contentResolver.insert(uriSms, values); > > } > > > public static void main(String[] args) { > > NoActivityTest ex = new NoActivityTest(); > > ex.insertSms("13912345678", "test0001"); > > } > > } > > === > > > As you seen from comments, can't get "ContentResolver" instance because > > don't recongnize "getContentResolver()". > > How to overcome this issue? > > > Thanks. > > > -- > > unsubscribe: > > android-kernel+unsubscr...@googlegroups.com > > website:http://groups.google.com/group/android-kernel > > > -- > > unsubscribe: > > android-kernel+unsubscr...@googlegroups.com > > website:http://groups.google.com/group/android-kernel > > -- > 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 > athttp://groups.google.com/group/android-developers?hl=en -- 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: [android-kernel] A simplest Application access "Content Provider"
Sorry, I've corrected it. If you have any idea about this issue, please help check it. Thanks. 2010/5/5 Mateusz Kozak > Why are you posting this on Android-kernel not on android-platform? > > W dniu 2010-05-05 13:57 użytkownik napisał: > > > hi, > > Usually, we can inherit class "Activity" to access "Content Provider", such > as SMS/Contacts with following codes: > === > public class ActivityTest extends Activity { > ... > private void insertSms(String str_address, String content){ > ContentResolver contentResolver = getContentResolver(); > String strUriInbox = "content://sms/inbox"; > ContentValues values = new ContentValues(); > values.put("address", str_address); > values.put("date", Calendar.getInstance().getTime().getTime()); > values.put("protocol", "0"); > values.put("status", "-1"); > values.put("type", "1"); > values.put("body", content); > Uri uriSms = Uri.parse(strUriInbox); > contentResolver.insert(uriSms, values); > } > } > === > > However, I don't want to show a activity if write SMS database. So, I > design a simplest application without Activity with following codes: > === > package com.xxx.NoActivityTest; > > public class NoActivityTest { > public NoActivityTest(){ > } > > private void insertSms(String str_address, String content){ > ContentResolver contentResolver = *getContentResolver*(); > *//"NoActivityTest" > don't inherit from "Activity", so, don't recongnize "getContentResolver()", > so, can't get "ContentResolver" instance.* > String strUriInbox = "content://sms/inbox"; > ContentValues values = new ContentValues(); > values.put("address", str_address); > values.put("date", Calendar.getInstance().getTime().getTime()); > values.put("protocol", "0"); > values.put("status", "-1"); > values.put("type", "1"); > values.put("body", content); > Uri uriSms = Uri.parse(strUriInbox); > contentResolver.insert(uriSms, values); > } > > public static void main(String[] args) { > NoActivityTest ex = new NoActivityTest(); > ex.insertSms("13912345678", "test0001"); > } > } > === > > As you seen from comments, can't get "ContentResolver" instance because > don't recongnize "getContentResolver()". > How to overcome this issue? > > Thanks. > > > > -- > unsubscribe: > android-kernel+unsubscr...@googlegroups.com > website: http://groups.google.com/group/android-kernel > > -- > unsubscribe: > android-kernel+unsubscr...@googlegroups.com > website: http://groups.google.com/group/android-kernel -- 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: [android-kernel] A simplest Application access "Content Provider"
Please don't spam questions across every android group in the world. On Wed, May 5, 2010 at 4:57 AM, wrote: > hi, > > Usually, we can inherit class "Activity" to access "Content Provider", such > as SMS/Contacts with following codes: > === > public class ActivityTest extends Activity { > ... > private void insertSms(String str_address, String content){ > ContentResolver contentResolver = getContentResolver(); > String strUriInbox = "content://sms/inbox"; > ContentValues values = new ContentValues(); > values.put("address", str_address); > values.put("date", Calendar.getInstance().getTime().getTime()); > values.put("protocol", "0"); > values.put("status", "-1"); > values.put("type", "1"); > values.put("body", content); > Uri uriSms = Uri.parse(strUriInbox); > contentResolver.insert(uriSms, values); > } > } > === > > However, I don't want to show a activity if write SMS database. So, I > design a simplest application without Activity with following codes: > === > package com.xxx.NoActivityTest; > > public class NoActivityTest { > public NoActivityTest(){ > } > > private void insertSms(String str_address, String content){ > ContentResolver contentResolver = *getContentResolver*(); > *//"NoActivityTest" > don't inherit from "Activity", so, don't recongnize "getContentResolver()", > so, can't get "ContentResolver" instance.* > String strUriInbox = "content://sms/inbox"; > ContentValues values = new ContentValues(); > values.put("address", str_address); > values.put("date", Calendar.getInstance().getTime().getTime()); > values.put("protocol", "0"); > values.put("status", "-1"); > values.put("type", "1"); > values.put("body", content); > Uri uriSms = Uri.parse(strUriInbox); > contentResolver.insert(uriSms, values); > } > > public static void main(String[] args) { > NoActivityTest ex = new NoActivityTest(); > ex.insertSms("13912345678", "test0001"); > } > } > === > > As you seen from comments, can't get "ContentResolver" instance because > don't recongnize "getContentResolver()". > How to overcome this issue? > > Thanks. > > > > -- > unsubscribe: > android-kernel+unsubscr...@googlegroups.com > website: http://groups.google.com/group/android-kernel > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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