Amazfit Sports Watch / PACE: Change miles/km without factory reset - Other SmartWatches

I spend a couple of hours to understand how Huami decides whether to show KM or MI as well as 12/24h on the watch displays that support this. I finally figured it out.
So, if you want to switch to MI display and 12h display, do this:
Code:
adb shell content insert --uri content://settings/secure --bind value:s:1 --bind name:s:measurement
adb reboot
If you want to switch to KM and 24h display, do this:
Code:
adb shell content insert --uri content://settings/secure --bind value:s:0 --bind name:s:measurement
adb reboot
PLEASE NOTE: This will only change the display in the watchfaces, NOT in the Sports app. If I see that correctly, the Sports app has hard coded values (so can only show mi or km depending on what is compiled in the app, not switch between them)
The 12/24h display only changes on supported watchfaces ("Marathon life").

Neuer_User said:
I spend a couple of hours to understand how Huami decides whether to show KM or MI as well as 12724 on the watch displays that support this. I finally figured it out.
So, if you want to switch to MI display and 12h display, do this:
Code:
adb shell content insert --uri content://settings/secure --bind value:s:1 --bind name:s:measurement
adb reboot
If you want to switch to KM and 24h display, do this:
Code:
adb shell content insert --uri content://settings/secure --bind value:s:0 --bind name:s:measurement
adb reboot
PLEASE NOTE: This will only change the display in the watchfaces, NOT in the Sports app. If I see that correctly, the Sports app has hard coded values (so can only show mi or km depending on what is compiled in the app, not switch between them)
The 12/24h display only changes on supported watchfaces ("Marathon life").
Click to expand...
Click to collapse
Thanks! It works on my watch that running on original 1.3.0n firmware.

It give me idea to check what else can be set without watch UI. If somebody wants to try.
Code:
adb shell dumpsys | grep 'settings/'
settings/secure/long_press_timeout: pid=424 uid=1000 user=0 target=7dcde54
settings/secure/show_ime_with_hard_keyboard: pid=424 uid=1000 user=0 target=2dc071fd
settings/secure/show_ime_with_hard_keyboard: pid=424 uid=1000 user=0 target=459cef2
settings/secure/accessibility_display_inversion_enabled: pid=424 uid=1000 user=0 target=2dc071fd
settings/secure/accessibility_display_inversion_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/incall_power_button_behavior: pid=424 uid=1000 user=-1 target=3c538bc0
settings/secure/wake_gesture_enabled: pid=424 uid=1000 user=-1 target=3c538bc0
settings/secure/default_input_method: pid=424 uid=1000 user=-1 target=3c538bc0
settings/secure/default_input_method: pid=424 uid=1000 user=0 target=459cef2
settings/secure/immersive_mode_confirmations: pid=424 uid=1000 user=-1 target=3c538bc0
settings/secure/enabled_input_methods: pid=424 uid=1000 user=0 target=459cef2
settings/secure/selected_input_method_subtype: pid=424 uid=1000 user=0 target=459cef2
settings/secure/accessibility_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/touch_exploration_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/accessibility_display_magnification_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/enabled_accessibility_services: pid=424 uid=1000 user=-1 target=38770943
settings/secure/touch_exploration_granted_accessibility_services: pid=424 uid=1000 user=-1 target=38770943
settings/secure/accessibility_script_injection: pid=424 uid=1000 user=-1 target=38770943
settings/secure/accessibility_display_daltonizer_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/accessibility_display_daltonizer: pid=424 uid=1000 user=-1 target=38770943
settings/secure/high_text_contrast_enabled: pid=424 uid=1000 user=-1 target=38770943
settings/secure/enabled_notification_listeners: pid=424 uid=1000 user=0 target=3aa730f9
settings/secure/enabled_notification_listeners: pid=424 uid=1000 user=-1 target=3b1e83e
settings/secure/enabled_notification_listeners: pid=424 uid=1000 user=-1 target=2576f69f
settings/secure/pubkey_blacklist: pid=424 uid=1000 user=0 target=10c5a3ec
settings/secure/serial_blacklist: pid=424 uid=1000 user=0 target=10a0e3b5
settings/secure/enabled_print_services: pid=424 uid=1000 user=-1 target=2ce04a4a
settings/secure/user_setup_complete: pid=424 uid=1000 user=-1 target=315e5dbb
settings/secure/screensaver_enabled: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/secure/screensaver_activate_on_sleep: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/secure/screensaver_activate_on_dock: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/secure/sleep_timeout: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/secure/enabled_condition_providers: pid=424 uid=1000 user=-1 target=1e490631
settings/secure/voice_interaction_service: pid=424 uid=1000 user=0 target=1fe0c116
settings/secure/locationCoarseAccuracy: pid=424 uid=1000 user=0 target=3a8b1a97
settings/secure/locationPackagePrefixBlacklist: pid=424 uid=1000 user=-1 target=371e8484
settings/secure/location_providers_allowed: pid=424 uid=1000 user=-1 target=676d46d
settings/secure/measurement: pid=692 uid=10017 user=0 target=2e9fd8a2
settings/secure/measurement: pid=692 uid=10017 user=0 target=3d5cc933
settings/secure/prop.launcher.at_watchface: pid=692 uid=10017 user=0 target=364164f0
settings/secure/sport_total_distance: pid=692 uid=10017 user=0 target=8394a69
settings/secure/sport_today_distance: pid=692 uid=10017 user=0 target=2b46dcee
settings/system/time_12_24: pid=424 uid=1000 user=0 target=7dcde54
settings/system/end_button_behavior: pid=424 uid=1000 user=-1 target=3c538bc0
settings/system/accelerometer_rotation: pid=424 uid=1000 user=-1 target=3c538bc0
settings/system/user_rotation: pid=424 uid=1000 user=-1 target=3c538bc0
settings/system/screen_off_timeout: pid=424 uid=1000 user=-1 target=3c538bc0
settings/system/screen_off_timeout: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/system/pointer_location: pid=424 uid=1000 user=-1 target=3c538bc0
settings/system/pointer_speed: pid=424 uid=1000 user=-1 target=1290c58f
settings/system/show_touches: pid=424 uid=1000 user=-1 target=1f6fe01c
settings/system/mode_ringer_streams_affected: pid=424 uid=1000 user=0 target=2a932425
settings/system/vibrate_input_devices: pid=424 uid=1000 user=-1 target=f47d9fa
settings/system/screen_brightness: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/system/screen_brightness: pid=721 uid=1000 user=0 target=375e2bab
settings/system/screen_brightness_mode: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/system/screen_brightness_mode: pid=721 uid=1000 user=0 target=375e2bab
settings/system/screen_auto_brightness_adj: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/system/notification_light_pulse: pid=424 uid=1000 user=-1 target=35a8e208
settings/system/springboard_widget_order_in: pid=678 uid=10008 user=0 target=27f6dda1
settings/system/com.huami.watch.key.DEVICE_BOND_TYPE: pid=721 uid=1000 user=0 target=7299bc6
settings/system/EnableUnlockMIUI: pid=739 uid=1000 user=0 target=3b51d787
settings/system/light_changed_val: pid=678 uid=10008 user=0 target=2aee16b4
settings/system/key_music_open: pid=9938 uid=10015 user=0 target=397cfdb
settings/system/key_volumn_control_value: pid=9938 uid=10015 user=0 target=275a6a78
settings/system/sport_music_setting_source: pid=9938 uid=10015 user=0 target=1ec01551
settings/system/rise_hand_without_bl: pid=721 uid=1000 user=0 target=2dafea20
settings/global: pid=424 uid=1000 user=0 target=1fc9fd9
settings/global/debug_view_attributes: pid=424 uid=1000 user=0 target=7dcde54
settings/global/policy_control: pid=424 uid=1000 user=-1 target=3c538bc0
settings/global/wifi_suspend_optimizations_enabled: pid=424 uid=1000 user=0 target=c1a5d9e
settings/global/wifi_networks_available_notification_on: pid=424 uid=1000 user=0 target=35f4307f
settings/global/stay_on_while_plugged_in: pid=424 uid=1000 user=0 target=20f9884c
settings/global/stay_on_while_plugged_in: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/global/wifi_idle_ms: pid=424 uid=1000 user=0 target=88e6095
settings/global/wifi_sleep_policy: pid=424 uid=1000 user=0 target=e4ab5aa
settings/global/http_proxy: pid=424 uid=1000 user=0 target=4a5559b
settings/global/nsd_on: pid=424 uid=1000 user=0 target=2b5cdd38
settings/global/zen_mode: pid=424 uid=1000 user=0 target=13417111
settings/global/dock_audio_media_enabled: pid=424 uid=1000 user=0 target=2a932425
settings/global/adb_enabled: pid=424 uid=1000 user=0 target=27768276
settings/global/sampling_profiler_ms: pid=424 uid=1000 user=0 target=679b077
settings/global/wifi_scan_always_enabled: pid=424 uid=1000 user=0 target=89e94e4
settings/global/wifi_watchdog_poor_network_test_enabled: pid=424 uid=1000 user=0 target=93b0d4d
settings/global/wifi_watchdog_on: pid=424 uid=1000 user=0 target=2c05002
settings/global/device_provisioned: pid=424 uid=1000 user=0 target=27cedd13
settings/global/low_power: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/global/low_power_trigger_level: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/global/low_power_trigger_level: pid=424 uid=1000 user=-1 target=a221b50
settings/global/low_power_trigger_level: pid=616 uid=10007 user=-1 target=24b83149
settings/global/theater_mode_on: pid=424 uid=1000 user=-1 target=3f5f12d8
settings/global/overlay_display_devices: pid=424 uid=1000 user=0 target=28e76a4e
settings/global/auto_time: pid=424 uid=1000 user=0 target=3340376f
settings/global/last_charging_time: pid=678 uid=10008 user=0 target=32159c7c
settings/global/airplane_mode_on: pid=9953 uid=10011 user=0 target=2bedf1b6
settings/bookmarks: pid=424 uid=1000 user=0 target=1d53dd5a
Also you can see already set values with commands like:
Code:
adb shell content query --uri contetn://settings/system --projection name:value
adb shell content query --uri contetn://settings/global --projection name:value
adb shell content query --uri contetn://settings/secure --projection name:value

Neuer_User said:
PLEASE NOTE: This will only change the display in the watchfaces, NOT in the Sports app. If I see that correctly, the Sports app has hard coded values (so can only show mi or km depending on what is compiled in the app, not switch between them)
The 12/24h display only changes on supported watchfaces ("Marathon life").
Click to expand...
Click to collapse
I think, hardcoded only a string resources. After changing "measurement" watch starts count in kilometers. Look at the numbers in the sports app.

silver-alx said:
I think, hardcoded only a string resources. After changing "measurement" watch starts count in kilometers. Look at the numbers in the sports app.
Click to expand...
Click to collapse
Yes, completely agree. The values shown are in km, but the units are hard-coded.
I am pretty sure that the watch BTW always counts in km, but only calculates to miles for display. If they now also would affirmatively charge the text 'mi" to' km' everything would be ok.

Neuer_User said:
Yes, completely agree. The values shown are in km, but the units are hard-coded.
I am pretty sure that the watch BTW always counts in km, but only calculates to miles for display. If they now also would affirmatively charge the text 'mi" to' km' everything would be ok.
Click to expand...
Click to collapse
You have to edit strings in the sports app and see km. I did it already and completely satisfied. ))

silver-alx said:
You have to edit strings in the sports app and see km. I did it already and completely satisfied. ))
Click to expand...
Click to collapse
Yeah, it's already done in my Rom. But now the US guys can't get miles anymore. That's the problem : you can't have both in the sports app. But you can switch in the watchfaces [emoji1]

Neuer_User said:
Yeah, it's already done in my Rom. But now the US guys can't get miles anymore. That's the problem : you can't have both in the sports app. But you can switch in the watchfaces [emoji1]
Click to expand...
Click to collapse
Wrong )) You can introduce regions in the string resources and do "values-en" and "values-en-US" with different strings.

silver-alx said:
Wrong )) You can introduce regions in the string resources and do "values-en" and "values-en-US" with different strings.
Click to expand...
Click to collapse
Yes, you are right!!! Haven't thought about that. Thanks. Gonna do that in the next version!!

Neuer_User said:
Yes, you are right!!! Haven't thought about that. Thanks. Gonna do that in the next version!!
Click to expand...
Click to collapse
Welcome! ))

silver-alx said:
Welcome! ))
Click to expand...
Click to collapse
Hmm, I seem to be doing something wrong here.
So, I added the dir "values-en-rUS", containing the strings.xml (with "miles" in), recompiled the apk as always, verified that the new resources are in the apk (with aapt), then installed in the watch (reboot, etc).
When I change the country via "setprop persist.sys.country" to "US", the apk still uses the resources from the "values-en" folder.
Any idea what is wrong?
(I also tried "persist.sys.region", but that did not do anything either.)
EDIT:
Wait. I just remember that I am running my temporary ROM on the development watch I have. And I exchanged the apk on the real system partition. Stupid me. Ok, let's try again...
EDIT2:
Yes, it works. Just too late in the night here, I guess

Neuer_User said:
Yes, it works. Just too late in the night here, I guess
Click to expand...
Click to collapse
Nice work! ))

Work perfectly! Altough there are some more places that needs to be changed. For instance when the watch is in "backlight" mode. km show, but the clock shows "12h-pm" and not "24h" Is that something to change in adb aswell?

leholtet said:
Work perfectly! Altough there are some more places that needs to be changed. For instance when the watch is in "backlight" mode. km show, but the clock shows "12h-pm" and not "24h" Is that something to change in adb aswell?
Click to expand...
Click to collapse
Did you reboot?

Neuer_User said:
Did you reboot?
Click to expand...
Click to collapse
Yes i did.

leholtet said:
Yes i did.
Click to expand...
Click to collapse
What rom do you use?

Neuer_User said:
What rom do you use?
Click to expand...
Click to collapse
stock 1.3On. Model A1612.
When the clock is lit up, its 24h, but when it goes to "background" mode lights off. Its 12h.

leholtet said:
stock 1.3On. Model A1612.
When the clock is lit up, its 24h, but when it goes to "background" mode lights off. Its 12h.
Click to expand...
Click to collapse
On PACEfied it works correctly for me.

Update: It works on all the faces execpt marathon life on the oem rom

Related

HOWTO: Enable Flashlight on HTC devices

Some source code from Ateksoft!
http://www.ateksoft.com/dev/flashlight.htm
My experiments with extra brightness on the Magician have shown that MS saves this state somewhere else. If you don't change this place as well the real place (GPIO) is reset every 5 seconds or so.
Damn, my current Opera installation adds this to every post:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

Hard-SPL and SSPL

What is the difference between Hard-SPL and SSPL?
Thanks
Hard-SPL is flashed onto your device and accessible during cold-boot, SSPL is only loaded into RAM and started immediately.
Now the usual bashing: Do you actually READ THE WIKI? Use the search function? I mean, you know how to start a thread... why don't you try the other functions as well?
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #ffffcc; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

Halo Reach Tips application

Hey guys ,
I've been developing a tips application for Halo Reach over the past week or so. It's on the market now.
I've ran into a problem on one of my builds. I am force closing every time I try to open the scroll view with a linear layout that has image buttons. It's two activities deep into the app. I know the problem is I'm missing something in the manifest file. I currently have it added as an activity but I can't figure out what else it needs to work. When I comment out the onClicklistener stuff for the image buttons it no longer force closes.
Does anyone know what line of code needs to be in the manifest file to fix this? My code will be up soon to show you.
Sent from my ADR6300 using XDA App
What does the logcat say?
Sent from my SAMSUNG Captivate using XDA App
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): FATAL EXCEPTION: main
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): java.lang.RuntimeException: Unable to start activity ComponentInfo{jorny32.haloreachtips.donate/jorny32.haloreachtips.donate.Map}: java.lang.NullPointerException
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.os.Looper.loop(Looper.java:123)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at dalvik.system.NativeStart.main(Native Method)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): Caused by: java.lang.NullPointerException
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at jorny32.haloreachtips.donate.Map.onCreate(Map.java:26)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-19 17:49:57.412: ERROR/AndroidRuntime(1473): ... 11 more
09-19 17:49:57.422: WARN/ActivityManager(61): Force finishing activity jorny32.haloreachtips.donate/.Map
09-19 17:49:57.422: WARN/ActivityManager(61): Force finishing activity jorny32.haloreachtips.donate/.haloreachtipsdonate
09-19 17:49:57.923: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{4500ebe0 jorny32.haloreachtips.donate/.Map}
09-19 17:50:05.522: DEBUG/dalvikvm(216): GC_EXPLICIT freed 152 objects / 11536 bytes in 71ms
09-19 17:50:08.626: WARN/ActivityManager(61): Activity destroy timeout for HistoryRecord{44f4d970 jorny32.haloreachtips.donate/.haloreachtipsdonate}
09-19 17:50:08.626: WARN/ActivityManager(61): Activity destroy timeout for HistoryRecord{4500ebe0 jorny32.haloreachtips.donate/.Map}
09-19 17:50:10.512: DEBUG/dalvikvm(265): GC_EXPLICIT freed 46 objects / 2224 bytes in 51ms
09-19 17:50:14.342: INFO/Process(1473): Sending signal. PID: 1473 SIG: 9
09-19 17:50:14.432: INFO/WindowManager(61): WIN DEATH: Window{450fad00 jorny32.haloreachtips.donate/jorny32.haloreachtips.donate.haloreachtipsdonate paused=true}
09-19 17:50:14.432: INFO/ActivityManager(61): Process jorny32.haloreachtips.donate (pid 1473) has died.
This is the logcat reading...
Can I see the code on line 26 of your activity?
Or if you can show me your whole onCreate() method, I may be more helpful to you.
Here is my on create for the class called when it force closes
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
I'm guessing there is something wrong with your R.layout.maps, because there shouldn't be anything that you need to add in the manifest for a simple scrollview with a linear layout with image buttons
Can I see that file(maps.xml)? pm me if you don't want to display it publicly.
Magicman, thank you so much for the help. Here is the file.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="HTTP STUFF THAT IS A LINK SO I CAN"T POST IT HERE"
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical">
<ImageButton android:src="@drawable/button_beachhead" android:id="@+id/ImageButton01" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_boardwalk" android:id="@+id/ImageButton02" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_boneyard" android:id="@+id/ImageButton03" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_countdown" android:id="@+id/ImageButton05" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_forgeworld" android:id="@+id/ImageButton07" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_powerhouse" android:id="@+id/ImageButton12" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_reflection" android:id="@+id/ImageButton13" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_spire" android:id="@+id/ImageButton14" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_swordbase" android:id="@+id/ImageButton15" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_waterfront" android:id="@+id/ImageButton16" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:src="@drawable/button_zealot" android:id="@+id/ImageButton17" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageButton>
</LinearLayout>
</ScrollView>
I don't think anything is wrong with it??
Also, If I just comment out the onClickView things and the View ids in the Map.java class it allows me to go into the Map layout and scroll through it. I just no longer can click any of the buttons to open them.
package jorny32.haloreachtips.donate;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
public class Map extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
View Imagebutton01 = findViewById(R.id.ImageButton01);
Imagebutton01.setOnClickListener(this);
View Imagebutton02 = findViewById(R.id.ImageButton02);
Imagebutton02.setOnClickListener(this);
View Imagebutton03 = findViewById(R.id.ImageButton03);
Imagebutton03.setOnClickListener(this);
View Imagebutton06 = findViewById(R.id.ImageButton06);
Imagebutton06.setOnClickListener(this);
View Imagebutton07 = findViewById(R.id.ImageButton07);
Imagebutton07.setOnClickListener(this);
View Imagebutton013 = findViewById(R.id.ImageButton13);
Imagebutton013.setOnClickListener(this);
View Imagebutton014 = findViewById(R.id.ImageButton14);
Imagebutton014.setOnClickListener(this);
View Imagebutton015 = findViewById(R.id.ImageButton15);
Imagebutton015.setOnClickListener(this);
View Imagebutton016 = findViewById(R.id.ImageButton16);
Imagebutton016.setOnClickListener(this);
View Imagebutton017 = findViewById(R.id.ImageButton17);
Imagebutton017.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.ImageButton01:
Intent i = new Intent(this, Maps_Beachhead.class);
startActivity(i);
break;
case R.id.ImageButton02:
Intent j = new Intent(this, Maps_Boardwalk.class);
startActivity(j);
break;
case R.id.ImageButton03:
Intent k = new Intent(this, Maps_Boneyard.class);
startActivity(k);
break;
case R.id.ImageButton06:
Intent m = new Intent(this, Maps_Countdown.class);
startActivity(m);
break;
case R.id.ImageButton07:
Intent o = new Intent(this, Maps_Forgeworld.class);
startActivity(o);
break;
case R.id.ImageButton13:
Intent t = new Intent(this, Maps_Powerhouse.class);
startActivity(t);
break;
case R.id.ImageButton14:
Intent u = new Intent(this, Maps_Reflection.class);
startActivity(u);
break;
case R.id.ImageButton15:
Intent z = new Intent(this, Maps_Spire.class);
startActivity(z);
break;
case R.id.ImageButton16:
Intent w = new Intent(this, Maps_Swordbase.class);
startActivity(w);
break;
case R.id.ImageButton17:
Intent x = new Intent(this, Maps_Waterfront.class);
startActivity(x);
break;
}
}
}
Thats weird, your code seems to work for me on the emulator running 2.2 and my 2.1 galaxy s.
Have you tested on multiple devices? I'd be happy to test it for you if you pm me an apk file.
I downloaded your app, and I assume you implement a similar code on the main screen. Are you doing anything different?
Also, just a tip. Replace all of your ImageButtons with regular buttons. The drawables will still work, and you won't have any of the stock button on the edges, just the image. Unless you want to keep it that way.
Tip #2: I assume you are using setListAdapter(new ArrayAdapter<String>(this, android.R.layout.SOMETHING, arrayhere));
I recommend changing the android.R.layout.SOMETHING to R.layout.list_item. If you do this, you must create list_item.xml in your layout folder, and paste the following code:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000"
androidadding="10dp"
android:textSize="16sp" >
</TextView>
Click to expand...
Click to collapse
This just makes the text a little smaller and makes it easier on this eyes. You don't have to do this if you don't want to, its just my recommendation.
First off thank you so much for all your help. Seriously.
I will get back to you tomorrow and try to implement your idea. I think I will p m you the apk later. Thanks again. Talk soon.
Sent from my ADR6300 using XDA App

Getting a widget to pull data from database?

Right so I've created a very basic widget. It does nothing but display some text. The mechanics to setting it up are easy to learn. Now that I've learnt that I have to move on to what I actually want my widget to do. That would be where the database is involved. I want it to pull data from a database and have it show on my widget.
Eventually I will progress it so that the user can tap on it to bring up another bit of data from the database or just have a button do it. Right now though I just need to just get the data to show up. Let's say I have 500 rows, well I want the database to pull 1 row at random.
You don't need to tell me about the basics of a database because I already know that, I've used SQLite and all that, it's just getting it to work with a AppWidgetProvider that I can't get.
In fact I can already pull a random row from a database but I've only done it in an Activity. So how do I do this for a widget? Hopefully somoene here has experience with widgets!
I would really appreciate any help, thanks!
I used RemoteViews to manipulate/access my widget buttons from the provider. I'm not sure what type of view you are working with but look those up. It may be what you are looking for.
zalez said:
I used RemoteViews to manipulate/access my widget buttons from the provider. I'm not sure what type of view you are working with but look those up. It may be what you are looking for.
Click to expand...
Click to collapse
Interesting. I'll look into that. I saw some bits of code with RemoteViews but I have no idea about them so I better get learning.
Any chance there are some decent tutorials out there? I get the idea that a RemoteView is what handles the communication for the UI but I still don't get how I can pull data with that involved.
I mean would this work for example: http://stackoverflow.com/questions/5661815/app-with-widget-accesing-to-database?rq=1
I've seen some with tonnes of code and then there's the one above which only has a few lines.
When I went through this, I didn't find any tutorials so I pushed through it myself. Do you have a class to do your database queries?
Using a remote view to change the text you could use something like this inside your onUpdate:
Code:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); //set your widget layout
remoteViews.setImageViewResource(R.id.btnToggle, R.drawable.toggle_off); //this changes the image in the imageview btnToggle, remoteViews lets you use setText and a couple of other to manipulate certain widget items
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
This is just a quick example pulled from one of my apps, you could put the database function above it to grab the line of text you want and then set the text in the remote view. The updateAppWidget will update all widgets with this view so if you have multitple different widgets then you'll need to pass the specific widgetId rather then the array.
If you want it to update with a button press on the widget, I would advice you set a pending intent which launches a service, does what you need it to do and then the service update the widget using remote views much like the above code.
Hope that helps
zalez said:
When I went through this, I didn't find any tutorials so I pushed through it myself. Do you have a class to do your database queries?
Click to expand...
Click to collapse
I am using the AppWidgetProvider to carry on my database query, within the onUpdate method. I have posted my code in the link below, on a question I asked on SO.
crazyfool_1 said:
Using a remote view to change the text you could use something like this inside your onUpdate:
Code:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); //set your widget layout
remoteViews.setImageViewResource(R.id.btnToggle, R.drawable.toggle_off); //this changes the image in the imageview btnToggle, remoteViews lets you use setText and a couple of other to manipulate certain widget items
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
This is just a quick example pulled from one of my apps, you could put the database function above it to grab the line of text you want and then set the text in the remote view. The updateAppWidget will update all widgets with this view so if you have multitple different widgets then you'll need to pass the specific widgetId rather then the array.
If you want it to update with a button press on the widget, I would advice you set a pending intent which launches a service, does what you need it to do and then the service update the widget using remote views much like the above code.
Hope that helps
Click to expand...
Click to collapse
Since my last post I have actually done something similar to this, if not the exact same thing. I had to post a question to stack overflow because I was getting a 'process is bad' warning here is the link: http://stackoverflow.com/questions/...base-to-show-on-widget-not-getting-a-response
I chucked the code I've used in the link.
Maybe you could provide some input there? I have been given one answer that I will now look at.
Thanks for helping as well!
Edit: For what it's worth I'm happy to make this project fully opensource once it works for others who want to do the same thing.
I cannot see the link.
EDIT: Thanks.
RED_ said:
I am using the AppWidgetProvider to carry on my database query, within the onUpdate method. I have posted my code in the link below, on a question I asked on SO.
Since my last post I have actually done something similar to this, if not the exact same thing. I had to post a question to stack overflow because I was getting a 'process is bad' warning here is the link: http://stackoverflow.com/questions/...base-to-show-on-widget-not-getting-a-response
I chucked the code I've used in the link.
Maybe you could provide some input there? I have been given one answer that I will now look at.
Thanks for helping as well!
Edit: For what it's worth I'm happy to make this project fully opensource once it works for others who want to do the same thing.
Click to expand...
Click to collapse
Hmm, two things to try is first, uninstall, reboot, install. Sounds obvious but sometimes Eclipse/Android does weird things and a number of Google results suggest this fixes it. Secondly try adding android:label="@string/app_name" to you application tag in the manifest as per here.
If that doesn't work let us know, I think I have an idea of what else it could be but let's see..
crazyfool_1 said:
Hmm, two things to try is first, uninstall, reboot, install. Sounds obvious but sometimes Eclipse/Android does weird things and a number of Google results suggest this fixes it. Secondly try adding android:label="@string/app_name" to you application tag in the manifest as per here.
If that doesn't work let us know, I think I have an idea of what else it could be but let's see..
Click to expand...
Click to collapse
Weird, I'm getting a force close after uninstalling rebooting and installing. Here is the logcat:
Code:
05-01 18:07:02.480: E/AndroidRuntime(2546): FATAL EXCEPTION: main
05-01 18:07:02.480: E/AndroidRuntime(2546): java.lang.RuntimeException: Unable to start receiver com.test.application.TestWidget: java.lang.NullPointerException
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.app.ActivityThread.access$1500(ActivityThread.java:141)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.os.Looper.loop(Looper.java:137)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-01 18:07:02.480: E/AndroidRuntime(2546): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 18:07:02.480: E/AndroidRuntime(2546): at java.lang.reflect.Method.invoke(Method.java:511)
05-01 18:07:02.480: E/AndroidRuntime(2546): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-01 18:07:02.480: E/AndroidRuntime(2546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-01 18:07:02.480: E/AndroidRuntime(2546): at dalvik.system.NativeStart.main(Native Method)
05-01 18:07:02.480: E/AndroidRuntime(2546): Caused by: java.lang.NullPointerException
05-01 18:07:02.480: E/AndroidRuntime(2546): at com.test.application.TestWidget.updateWidgetContent(TestWidget.java:27)
05-01 18:07:02.480: E/AndroidRuntime(2546): at com.test.application.TestWidget.onUpdate(TestWidget.java:22)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:66)
05-01 18:07:02.480: E/AndroidRuntime(2546): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
05-01 18:07:02.480: E/AndroidRuntime(2546): ... 10 more
Edit: My manifest already has android:label="@string/app_name" in the application tag and the receiver tag.
RED_ said:
Weird, I'm getting a force close after uninstalling rebooting and installing. Here is the logcat:
...
Edit: My manifest already has android:label="@string/app_name" in the application tag and the receiver tag.
Click to expand...
Click to collapse
Your dbHelper is null. You have DBHelper dbhelper; but it's never initialized.
crazyfool_1 said:
Your dbHelper is null. You have DBHelper dbhelper; but it's never initialized.
Click to expand...
Click to collapse
You see I thought I fixed that by putting in the last method.
Code:
private static DBHelper getDatabaseHelper(Context context) { }
I might revert back to what I had before. I'll see what I can do.
RED_ said:
You see I thought I fixed that by putting in the last method.
Code:
private static DBHelper getDatabaseHelper(Context context) { }
I might revert back to what I had before. I'll see what I can do.
Click to expand...
Click to collapse
That might work but you haven't called it correctly.. It should be something like the following (untested):
Code:
public static void updateWidgetContent(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
dbhelper = getDatabaseHelper(context);
dbhelper.openDatabase();
String name = "basestring";
Cursor c = dbHelper.getReadableDatabase().rawQuery("SELECT * FROM websites ORDER BY RANDOM()", null);
name = c.getString(c.getColumnIndex("weburl"));
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.main);
remoteView.setTextViewText(R.id.TextView1, name);
dbhelper.close();
appWidgetManager.updateAppWidget(appWidgetIds, remoteView);
}
crazyfool_1 said:
That might work but you haven't called it correctly.. It should be something like the following (untested):
Code:
public static void updateWidgetContent(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
dbhelper = getDatabaseHelper(context);
dbhelper.openDatabase();
String name = "basestring";
Cursor c = dbHelper.getReadableDatabase().rawQuery("SELECT * FROM websites ORDER BY RANDOM()", null);
name = c.getString(c.getColumnIndex("weburl"));
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.main);
remoteView.setTextViewText(R.id.TextView1, name);
dbhelper.close();
appWidgetManager.updateAppWidget(appWidgetIds, remoteView);
}
Click to expand...
Click to collapse
i can't tell if this is progress or not. I have a new error. Cannot open the database.
Code:
05-01 18:33:57.510: E/AndroidRuntime(3440): FATAL EXCEPTION: main
05-01 18:33:57.510: E/AndroidRuntime(3440): java.lang.RuntimeException: Unable to start receiver com.test.application.TestWidget: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.app.ActivityThread.access$1500(ActivityThread.java:141)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.os.Looper.loop(Looper.java:137)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-01 18:33:57.510: E/AndroidRuntime(3440): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 18:33:57.510: E/AndroidRuntime(3440): at java.lang.reflect.Method.invoke(Method.java:511)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-01 18:33:57.510: E/AndroidRuntime(3440): at dalvik.system.NativeStart.main(Native Method)
05-01 18:33:57.510: E/AndroidRuntime(3440): Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.text.database.DBHelper.openDatabase(DBHelper.java:62)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.test.application.TestWidget.getDatabaseHelper(TestWidget.java:45)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.test.application.TestWidget.updateWidgetContent(TestWidget.java:26)
05-01 18:33:57.510: E/AndroidRuntime(3440): at com.test.application.TestWidget.onUpdate(TestWidget.java:21)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:66)
05-01 18:33:57.510: E/AndroidRuntime(3440): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
05-01 18:33:57.510: E/AndroidRuntime(3440): ... 10 more
I'm about to clean my project and do an uninstall reboot install.
RED_ said:
i can't tell if this is progress or not. I have a new error. Cannot open the database.
...
I'm about to clean my project and do an uninstall reboot install.
Click to expand...
Click to collapse
A new error is always progress ha ha
It looks like there's a problem with your openDatabase method, best bet would be to set some breakpoints and see where it falls over..
crazyfool_1 said:
A new error is always progress ha ha
It looks like there's a problem with your openDatabase method, best bet would be to set some breakpoints and see where it falls over..
Click to expand...
Click to collapse
I guess so! Thing is a copied the openDatabase method from another project of mine where it works just fine.
It's fairly straightforward in that sense.
Code:
public void openDatabase() throws SQLException {
String myPath = DB_PATH + DB_NAME;
myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
Edit: The crap thing is that there is not a single open source project out there that helps me with this, that I can find anyway. I'm definitely making this open source if I can get it to work.
Here is my DB class that I use. I stripped alot of my functions out but left some to show how I access the DB.
To Call from any activity:
Code:
DBAdapter db = new DBAdapter(this);
db.open();
db.AnyFunctionYouCreate();
db.close();
Code:
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "YourAppName";
private static final int DATABASE_VERSION = 4; //(increased 6/13)increase this when changing db layout
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
[user=439709]@override[/user]
public void onCreate(SQLiteDatabase db)
{
db.execSQL("SQL_TO_CREATE_TABLES_HERE");
}
[user=439709]@override[/user]
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS your_table");
onCreate(db);
}
}
public Cursor lastId() {
Cursor yCursor = db.rawQuery("SELECT last_insert_rowid();", null);
if (yCursor != null){
yCursor.moveToFirst();
}
return yCursor;
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
//---retrieves all responses---
public Cursor getCustomResponse(String number)
{
Cursor cur = db.rawQuery("SELECT " + REP_RESPONSE +
" from " + MY_REPLIES + " where " + REP_AUDIENCE + " = " + number ,new String [] {});
return cur;
/*return db.query(MY_REPLIES, new String[] {
KEY_ROWID,
REP_RESPONSE,
REP_AUDIENCE},
null,
null,
null,
null,
null);*/
}
public Cursor getSetting(String what_table, String what_item)
{
Cursor cur = db.rawQuery("SELECT " + what_item +
" from " + what_table ,new String [] {});
return cur;
}
/**
* Updates Settings Table
*
* [user=955119]@param[/user] long RowId
* [user=955119]@param[/user] String Response
* [user=955119]@param[/user] String LocationStatus
* [user=955119]@param[/user] String LocationPassword
* [user=955119]@param[/user] String TTSStatus
* [user=955119]@param[/user] String VoiceReply
* [user=955119]@param[/user] String AppendMsg
* [user=955119]@param[/user] String NoReplyTimer
* [user=2056652]@return[/user] boolean
*/
public boolean updateSetting(long rowId, String settingResponse,
String locatorStatus, String locatorPass, String tts, String reply, String msgAppend, String timeDelay,
String auto, String silent, String shake)
{
ContentValues initialValues = new ContentValues();
initialValues.put(BUT_RESPONSE, settingResponse);
initialValues.put(BUT_LOCATOR, locatorStatus);
initialValues.put(BUT_LOC_PASS, locatorPass);
initialValues.put(BUT_TTS, tts);
initialValues.put(BUT_VOICE, reply);
initialValues.put(BUT_APPEND, msgAppend);
initialValues.put(BUT_TIME, timeDelay);
initialValues.put(BUT_AUTO_OFF, auto);
initialValues.put(BUT_SILENT, silent);
initialValues.put(BUT_SHAKE, shake);
return db.update(BUTLER_SETTINGS, initialValues,
KEY_ROWID + "=" + rowId, null) > 0;
}
public void emptySmsLog(){
db.execSQL("DELETE FROM sms_log;");
}
}
zalez said:
Here is my DB class that I use. I stripped alot of my functions out but left some to show how I access the DB.
To Call from any activity:
Code:
DBAdapter db = new DBAdapter(this);
db.open();
db.AnyFunctionYouCreate();
db.close();
Code:
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "YourAppName";
private static final int DATABASE_VERSION = 4; //(increased 6/13)increase this when changing db layout
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
[user=439709]@override[/user]
public void onCreate(SQLiteDatabase db)
{
db.execSQL("SQL_TO_CREATE_TABLES_HERE");
}
[user=439709]@override[/user]
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS your_table");
onCreate(db);
}
}
public Cursor lastId() {
Cursor yCursor = db.rawQuery("SELECT last_insert_rowid();", null);
if (yCursor != null){
yCursor.moveToFirst();
}
return yCursor;
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
//---retrieves all responses---
public Cursor getCustomResponse(String number)
{
Cursor cur = db.rawQuery("SELECT " + REP_RESPONSE +
" from " + MY_REPLIES + " where " + REP_AUDIENCE + " = " + number ,new String [] {});
return cur;
/*return db.query(MY_REPLIES, new String[] {
KEY_ROWID,
REP_RESPONSE,
REP_AUDIENCE},
null,
null,
null,
null,
null);*/
}
public Cursor getSetting(String what_table, String what_item)
{
Cursor cur = db.rawQuery("SELECT " + what_item +
" from " + what_table ,new String [] {});
return cur;
}
/**
* Updates Settings Table
*
* [user=955119]@param[/user] long RowId
* [user=955119]@param[/user] String Response
* [user=955119]@param[/user] String LocationStatus
* [user=955119]@param[/user] String LocationPassword
* [user=955119]@param[/user] String TTSStatus
* [user=955119]@param[/user] String VoiceReply
* [user=955119]@param[/user] String AppendMsg
* [user=955119]@param[/user] String NoReplyTimer
* [user=2056652]@return[/user] boolean
*/
public boolean updateSetting(long rowId, String settingResponse,
String locatorStatus, String locatorPass, String tts, String reply, String msgAppend, String timeDelay,
String auto, String silent, String shake)
{
ContentValues initialValues = new ContentValues();
initialValues.put(BUT_RESPONSE, settingResponse);
initialValues.put(BUT_LOCATOR, locatorStatus);
initialValues.put(BUT_LOC_PASS, locatorPass);
initialValues.put(BUT_TTS, tts);
initialValues.put(BUT_VOICE, reply);
initialValues.put(BUT_APPEND, msgAppend);
initialValues.put(BUT_TIME, timeDelay);
initialValues.put(BUT_AUTO_OFF, auto);
initialValues.put(BUT_SILENT, silent);
initialValues.put(BUT_SHAKE, shake);
return db.update(BUTLER_SETTINGS, initialValues,
KEY_ROWID + "=" + rowId, null) > 0;
}
public void emptySmsLog(){
db.execSQL("DELETE FROM sms_log;");
}
}
Click to expand...
Click to collapse
Thanks, just got around to finding some time. Do you think I need to implement all of that for what I need? Obviously changing the actual calls to the database. Also DATABASE_NAME = "YourAppName" should be where your database name goes not your app name right? Or have I got that wrong?
You would be the only one to decide if you need all of that class. I reuse it in many apps for database purposes. That class is what I use with my widget provider. DATABASE_NAME is for your app name. Because when your app creates a database in the system/data area, it is stored by appname.
RED_ said:
Thanks, just got around to finding some time. Do you think I need to implement all of that for what I need? Obviously changing the actual calls to the database. Also DATABASE_NAME = "YourAppName" should be where your database name goes not your app name right? Or have I got that wrong?
Click to expand...
Click to collapse
zalez said:
You would be the only one to decide if you need all of that class. I reuse it in many apps for database purposes. That class is what I use with my widget provider. DATABASE_NAME is for your app name. Because when your app creates a database in the system/data area, it is stored by appname.
Click to expand...
Click to collapse
Ok, well it's telling me it can't find a table called "websites" in my database. I know for sure there it's there. This is annoying.
Here's the code I used from yours in my DBAdapter: http://pastebin.com/v0CWcr3t
and how I called it in my widget provider: http://pastebin.com/LDmvASdK
EDIT: I think the error is because I have my database in my assets folder and we are not copying it to the data/data folder.

[Q] Need help with my next update!

Right before i start, i have looked absolutely everywhere for the answer but there's only so much that people talk about so this is my last hope because I've tried and tried but simply can't do it!
Now i understand that to some this may be a very very easy thing to do and although i have learnt a hell of a lot since i started developing, I'm just not a pro (Just yet)
So basically ever since i started my music player, I've had one big problem and that's trying to list music albums and the songs, now, I have code that does work but it simply doesn't go with my apps data source so I'm trying to the code that i done but the code that I done doesn't show the list of songs, becauser it crashes
Here's the code so far:
Code:
public class AlbumsList extends ListActivity{
public ArrayList<HashMap<String,String>> albumsList = new ArrayList<HashMap<String, String>>();
ListView musiclist;
int songAlbum;
int count;
int songPath;
private Cursor cursor;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.albums);
ArrayList<HashMap<String, String>> albumListData = new ArrayList<HashMap<String, String>>();
final AlbumsList plm = new AlbumsList();
// get all songs from sdcard
this.albumsList = plm.getPlayList(this, count);
// looping through playlist
for (int i = 0; i < albumsList.size(); i++) {
// creating new HashMap
HashMap<String, String> album = albumsList.get(i);
// adding HashList to ArrayList
albumListData.add(album);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, albumListData,
android.R.layout.simple_list_item_1, new String[] { "songAlbum", "songTitle", "orderBy", "songPath", "where", "whereVal" }, new int[] {
android.R.id.text1});
setListAdapter(adapter);
}
public ArrayList<HashMap<String, String>> getPlayList(Context c, int position) {
final String[] columns = { BaseColumns._ID,
AlbumColumns.ALBUM };
final Cursor mCursor = c.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
columns, null, null, null);
String songAlbum = "";
if (mCursor.moveToFirst()) {
do {
mCursor.getString(mCursor.getColumnIndexOrThrow(BaseColumns._ID));
songAlbum = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));
HashMap<String, String> album = new HashMap<String, String>();
album.put("songAlbum", songAlbum);
albumsList.add(album);
} while (mCursor.moveToNext());
}
return albumsList;
}
@Override
protected void onListItemClick(ListView lv, View v, int position, long id) {
if(cursor.moveToPosition(position)){
cursor = getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaColumns.TITLE, MediaColumns.DATA, AudioColumns.ALBUM, BaseColumns._ID }, null, null,
"LOWER(" + MediaColumns.TITLE + ") ASC");
String where = AudioColumns.ALBUM
+ "=?";
String whereVal = cursor.getString(cursor.getColumnIndex(AlbumColumns.ALBUM));
String orderBy = MediaColumns.TITLE;
String songTitle = MediaColumns.TITLE;
String songPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA));
HashMap<String, String> album = new HashMap<String, String>();
album.put("songTitle", songTitle);
album.put("where", where);
album.put("whereVal", whereVal);
album.put("orderBy", orderBy);
album.put("songPath", songPath);
albumsList.add(album);
}else{
}
}
}
That Code successfully gets all the albums but it won't get the songs from the selected album
Here's the LogCat:
Code:
03-18 18:42:21.579: E/AndroidRuntime(10214): at dalvik.system.NativeStart.main(Native Method)
03-18 18:46:48.223: E/SpannableStringBuilder(12325): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-18 18:46:48.223: E/SpannableStringBuilder(12325): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-18 18:46:48.894: E/AndroidRuntime(12325): FATAL EXCEPTION: main
03-18 18:46:48.894: E/AndroidRuntime(12325): java.lang.NullPointerException
03-18 18:46:48.894: E/AndroidRuntime(12325): at com.simplistic.simplisticmusicfree.AlbumsList.onListItemClick(AlbumsList.java:93)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.widget.AbsListView.performItemClick(AbsListView.java:1519)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3291)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.widget.AbsListView$1.run(AbsListView.java:4340)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.os.Handler.handleCallback(Handler.java:725)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.os.Handler.dispatchMessage(Handler.java:92)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.os.Looper.loop(Looper.java:137)
03-18 18:46:48.894: E/AndroidRuntime(12325): at android.app.ActivityThread.main(ActivityThread.java:5328)
03-18 18:46:48.894: E/AndroidRuntime(12325): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 18:46:48.894: E/AndroidRuntime(12325): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 18:46:48.894: E/AndroidRuntime(12325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
03-18 18:46:48.894: E/AndroidRuntime(12325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
03-18 18:46:48.894: E/AndroidRuntime(12325): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
03-18 18:46:48.894: E/AndroidRuntime(12325): at dalvik.system.NativeStart.main(Native Method)
Also just in case your wondering, this is music player in question: https://play.google.com/store/apps/details?id=com.simplistic.simplisticmusicfree
So yeah please for the love of god, help!!!
Updated the Question!
AmatuerAppDeveloper said:
Updated the Question!
Click to expand...
Click to collapse
Sorry but there seems to be a few simple problems there, and the error tells you what it is. I would suspect that the tutorials you have followed have not done a great job, or that you skipped some quite basic things... maybe learn some Java 101 and android basics. BTW I don't mean to sound condescending, I'm actually an authorised Autodesk instructor and developer and artist/trainer so it's maybe the way I say things, it's often for the total benefit of the individual I'm talking to, and quite blunt sometimes.
Your problem is clear and outlined in that error,
Code:
03-18 18:46:48.894: E/AndroidRuntime(12325): java.lang.NullPointerException
03-18 18:46:48.894: E/AndroidRuntime(12325): at com.simplistic.simplisticmusicfree.AlbumsList.onListItemClick(AlbumsList.java:93)
so on line 93, you are asking an "Object" that is actually "NULL" to execute or reference data or method, I would guess that it is as simple as the
Code:
private Cursor cursor;
You never assign it anything, you just create a null reference there. But then you ask it (Being null at this point) to ".moveToPosition()"
BTW: Still not fully awake and only glimpsed at your post
deanwray said:
Sorry but there seems to be a few simple problems there, and the error tells you what it is. I would suspect that the tutorials you have followed have not done a great job, or that you skipped some quite basic things... maybe learn some Java 101 and android basics. BTW I don't mean to sound condescending, I'm actually an authorised Autodesk instructor and developer and artist/trainer so it's maybe the way I say things, it's often for the total benefit of the individual I'm talking to, and quite blunt sometimes.
Your problem is clear and outlined in that error,
Code:
03-18 18:46:48.894: E/AndroidRuntime(12325): java.lang.NullPointerException
03-18 18:46:48.894: E/AndroidRuntime(12325): at com.simplistic.simplisticmusicfree.AlbumsList.onListItemClick(AlbumsList.java:93)
so on line 93, you are asking an "Object" that is actually "NULL" to execute or reference data or method, I would guess that it is as simple as the
Code:
private Cursor cursor;
You never assign it anything, you just create a null reference there. But then you ask it (Being null at this point) to ".moveToPosition()"
BTW: Still not fully awake and only glimpsed at your post
Click to expand...
Click to collapse
Thanks for the reply, I'll have to re look the code and see what I can do, also I'd like to note that I downloaded your beta app and I have to say it certainly looks promising, so im looking forward to official release
AmatuerAppDeveloper said:
Thanks for the reply, I'll have to re look the code and see what I can do, also I'd like to note that I downloaded your beta app and I have to say it certainly looks promising, so im looking forward to official release
Click to expand...
Click to collapse
Thanks for the download Yeah well my 1st app, and still a number of months away from what I would call "releasable".. Need to get all the user in app theming ability in there

Categories

Resources