在线媒体播放

摘自http://arm9.org.ru/archiver/?tid-554.html

 

Develop an IMS SIP client on Android

Develop an IMS SIP client on Android. Part 1
This is a series of 3 post samples how to develop for Android using ImsInnovation.com as the IMS SIP provider. The samples has been developed using Eclipse on Mac and Windows. The other platform that should work equally well but without testing on it is Linux.
Preparation
First of all to develop on Android one needs the SDK.
Android Download instructions.
Android Installation Instructions.
If you already have an Eclipse installation such as for example the SDS (Service Developer Studio)
Or else one can be fetched here:
SDS Download site.
or just eclipse
[url=http://www.eclipse.org/downloads/]http://www.eclipse.org/downloads/[/url]
Start the eclipse and install the ADT (Android Development Tools)
The smoothest way is to add it as a remote site for software updates in Eclipse
Point the IDE to search for the latest ADT under:
[url=https://dl-ssl.google.com/android/eclipse/]https://dl-ssl.google.com/android/eclipse/[/url]
The other thing that is required is to sign up for a SIP IMS account.
If you do not have this already then it can be done here:
IMS User provisioning page.
Follow the link to registration.
Sample1
The first sample will demonstrate how to build a simple chat client for SIP instant messages over IMS. Except of showing the communication framework provided by Ericsson the sample will also demonstrate power management and waking up the screen and releasing screen locks in Android.
At the same time for people not accustomed with Android development it will also show the event driven style of programming for true multithreaded devices.
The first step is to download the sample bundle. Unpack it and import it into Eclipse. (File/Import [existing project]).
Download the sample zip.
Under the lib directory the file containing the ImsInnovation API should be located there after unpacking the zip file.
There is also a bin directory with the .apk file that can be used to install the sample without compilation.
If you just want to try out the sample and you have followed the installation instructions from the Android SDK you should now have the adb command in your path. Start the emulator from the SDK or plug in a real phone with the USB cable. (Windows users will have to install a drive that is provided as part of the SDK). Now to control that everything is correct an adb command can be used to verify that adb can talk to the emulator or the phone.
$> adb devices
List of devices attached
HT845GZ53016 device
Now by typing “adb install imsLabsSample.apk” the application will be uploaded to the device.
The primary network device is the Wireless LAN driver for the real phone and the secondary the APN with the 3G mobile access. Now a good test is to open the built in Web browser and make sure that it has Internet connection and fetching pages in a correct way. If that is the case then there is a fairly good chance that the sample will work too. Now tap the arrow to expand the file view in the Android device and locate the IMS Android Sample with the nice Ericsson icon.
Since we are developers we want to know what is happening. One good command to see what the device is doing is to type “adb logcat”. It should attach to the device and start typing a lot of information. If this command was ran prior to starting the sample the SIP registration to the IMS system should be logged on the screen. The sequence is terminated by a 200 OK message on the register at the same time that the sample GUI will display a message {IMS Connected}.
In case of error there will be no message that it failed to connect, the way it informs the user is when an IM is to be sent then an error message that there is no message service to utilize.
Now the binary is provisioned with a demo user so there might be other running and getting clashes. So the best thing to do is to compile your own version with a unique user ID registered to the imsinnovation.com domain. But to just get a quick feedback and a feeling what the code does .
So a simple test is to send an instant message to yourself. Just type some message and press the send button. The SIP message will be sent to an Ericsson basement in Sweden and hopefully come back. Now having two clients is much more fun. But for that we need first to recompile. Since if both uses the same user login ID the testing will not be so much fun. (But it should work too due to SIP forking. Both the terminal that sent the message and the other terminal that just registered will receive the message.)
Now lets look at the code and how to compile the example.
A graphical user interface element in Android is usually extending the android.app.Activity
To also include the IMS SIP communication framework we have developed an extended version of the Activity class. Instead of extending the Activity class you should extend the
com.ericsson.labs.android.ImsActivity class.
For more info look at the javadoc.
So in the sample here is how the chat service is defined:
public class ImsChat extends ImsActivity {

while the ImsActivity is defined as:
public class ImsActivity extends Activity {

Now one interesting event in the Android application life-cycle is the onCreate() function call.
It is important to understand the life cycle:
[url=http://developer.android.com/reference/android/app/Activity.html]http://developer.android.com/reference/android/app/Activity.html[/url]
In order for the IMS SIP connection to be established in the right way the ImsActivity onCreate should be overridden.
@Override
        public void onCreate(Bundle savedInstanceState) {
                //Call super to initialize the network and IMS connection
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                //Hook up the send button generated by main.xml
                sendButton = (Button) findViewById(R.id.SendButton);
                sendButton.setOnClickListener(sendListener);

                //Hook up the two EditText fields generated by main.xml
                textMessage = (EditText) findViewById(R.id.EditMessage);
                textToURI = (EditText) findViewById(R.id.EditTextToURI);
                textToURI.setText("sip:[email protected]");
        }

First there is a call to the base class ImsActivity, super.onCreate().
Then the R.layout is pointing out the “main” as the graphical layout to show.
It is located in the sample in the res/layout directory.

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   
        
        
   

   
        
        
   

   

你可能感兴趣的:(Android)