android-sdk-2.1

BroadcastReceiver or Messenger via Handler

我们两清 提交于 2019-11-30 04:56:01
I have an IntentService which need to pass a message to an Activity . I know two ways of doing so. use sendBroadcast() at the Service side while registering a broadcastReciever at the Activity side which will receiver the message. passing a Messenger to the Service side , which will point to a Handler at the Activity side, which will be ready to receive that message from the service. Which one is good for which purpose? Or both of them do the same? If your IntentService does not know whether the activity will exist (e.g., might have been destroyed), or if there are multiple activities that

How to do custom ListView with colorful items' backgrounds?

≡放荡痞女 提交于 2019-11-30 04:25:19
问题 I have created an ArrayList<HashMap<String, String>> collection to hold my data for ListView . I'm using SimpleAdapter . Is it possible to change background of list item when list item's ID % 10 == 0? Here is the code (method generating layout): private void fillData() { Cursor c = this.mDbManager.getNgOrderDetailByOrderNumber(this.mNumber); ArrayList<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>(); if (!c.isAfterLast()) { do { // ... filling HashMap and putting it

how to limit seekbar

左心房为你撑大大i 提交于 2019-11-30 04:15:08
I'd like to set max and minimum limits of SeekBar to 50 and 20 respectively. SeekBar has a direct option top provide max value, but how to set its minimum value to 20 rather than 0? Paresh Mayani In SeekBar you can set only max value. <SeekBar android:id="@+id/SeekBar01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="50"/> And, You cannot directly set the minimum value to the seekbar. SeekBar mSeekbar = (SeekBar) findViewById(R.id.SeekBar01); mSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar,

Pick songs from SD card on Android and play it

﹥>﹥吖頭↗ 提交于 2019-11-29 23:29:04
问题 I have songs in the Music folder on the SD card. And in my app I want to pick a song from SD card from the list of music files, and when I choose any song, then using the Play button it should be played. How can I do that? I have already done it using content resolver and got a list of songs. Is there a way to do this using intents to pick from stored songs the SD card ? I have done this by both the ways. Just check it. 回答1: Check these to get an Idea, http://androidgenuine.com/?tag=play

How to wrap text to next line in an Android TextView?

断了今生、忘了曾经 提交于 2019-11-29 16:04:46
问题 I am using following TextView to display some data in it: <TextView android:id="@+id/notificationText" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="18sp" android:inputType="textMultiLine" android:maxLines="2" android:layout_paddingRight="20dip" android:textColor="#ffffff"/> I want to wrap text to next line. How can I do this? 回答1: you must set android:scrollHorizontally="false" in your xml. 回答2: You could also try android:inputType="textMultiLine"

How do I add contact to a group on Android?

℡╲_俬逩灬. 提交于 2019-11-29 08:49:52
I read about ContactsContract.CommonDataKinds.GroupMembership , but I can't figure out what URI use to insert to. I have prepared this method: public static Uri addToGroup(ContentResolver resolver, long personId, long groupId) { ContentValues values = new ContentValues(); values.put(ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID, personId); values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId); return resolver.insert(uri, values);//URI is not known } Can someone tell me what URI to use in SDK 2.0+? I found the resolution and I post it here: public Uri

BroadcastReceiver or Messenger via Handler

半腔热情 提交于 2019-11-29 02:30:22
问题 I have an IntentService which need to pass a message to an Activity . I know two ways of doing so. use sendBroadcast() at the Service side while registering a broadcastReciever at the Activity side which will receiver the message. passing a Messenger to the Service side , which will point to a Handler at the Activity side, which will be ready to receive that message from the service. Which one is good for which purpose? Or both of them do the same? 回答1: If your IntentService does not know

Reason for 5 sec delay to show an activity on pressing the home button?

时光怂恿深爱的人放手 提交于 2019-11-28 05:41:57
问题 I am facing delay of 5 sec to show an Activity after pressing the HOME key. I had gone through some post and found that after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds. Q1. Can anyone please let me know the reason to happening this delay ? Q2. When I modified the ActivityManagerService::checkAppSwitchAllowedLocked() to always return true, it avoids checking lock and hence Activity gets shown without any delay. Would it

How do I use PackageManager.addPreferredActivity()?

感情迁移 提交于 2019-11-28 05:02:05
In SDK 1.5 I was using the PackageManager class to set the preferred home screen to be my app using PackageManager.addPackageToPreferred(). In the new SDK (using 2.1) this has been deprecated so I'm trying to use addPreferredActivity() for the same result but it's not working as expected. Some necessary background. I'm writing a lock screen replacement app so I want the home key to launch my app (which will already be running, hence having the effect of disabling the key). When the user "unlocks" the screen I intend to restore the mapping so everything works as normal. In my AndroidManifest

How to use Front Facing Camera on Samsung Galaxy S

▼魔方 西西 提交于 2019-11-27 13:46:53
I've tried several answer I've found across the web, such as: Camera.Parameters parameters = mCamera.getParameters(); parameters.set("camera-id", 2); mCamera.setParameters(parameters); or mMediaRecorder.setVideoSource(2); But it doesn't work. I've also set permissions on the manifest file: <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> Am i missing out on something? I've searched StackOverflow and I know this has been asked before but there seem to be no confirmed solution on this, any kind of help would be appreciated. Note