Basic Preview

Overview

This tutorial shows how to implement a PreviewFragment/CallFragment combination inside a template or skeleton Android application.

Requirements

This tutorial requires either that you use the public sandbox or have your own private sandbox or internal Jabber Guest server environment.  This document also assumes the reader is comfortable with Java for Android.

Purpose

This is a very quick tutorial on how quickly you can set up a new project to incorporate Jabber Guest video technology.  It intentionally eschews safety and error checking for speed so view it only as an example of the general steps to take to get Jabber Guest integrated into your application.

Steps

The following steps show how to piece together the application.

  1. Create an Android Application

    Create a default Android Application Project from the Eclipse wizard.


  2. Download and Include the library

    Create a default Android Application Project from the Eclipse wizard.


  3. Update the Manifest

    Add or modify the following entries within your application’s manifest AndroidManifest.xml file:

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="21" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
        
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.camera.front" />
    <uses-feature android:name="android.hardware.camera.back" />
    <uses-feature android:name="android.hardware.microphone" />
    <uses-feature android:name="android.hardware.audio.low_latency" />
    

  4. Add the CallFragment and PreviewFragment to the Activity

    Add import statements for the required components to the top of your MainActivity.java file.

    import com.cisco.jabber.guest.CallFragment;
    import com.cisco.jabber.guest.JabberGuestCall;
    import com.cisco.jabber.guest.PreviewFragment;
    import com.cisco.jabber.guest.JabberGuestCall.JabberGuestInvalidCertificateCallback;
    

    Add the following internal class and member variables to your MainActivity.java class.

    // Class to handle invalid certificate notifications
    class JabberGuestCertificateHandler implements JabberGuestInvalidCertificateCallback {
    
        @Override
        public void onInvalidCertificate(String certFingerprint,
        	String identifierToDisplay,
        	String certSubjectCN, String referenceID,
            List invalidReason, String subjectCertificateData,
            List intermediateCACertificateData,
            boolean allowUserToAccept) {
    
            // For this sample we are accepting all certificates
            JabberGuestCall.getInstance().acceptInvalidCertificate(referenceID, subjectCertificateData);
        }
    }
    	
    JabberGuestCertificateHandler mCertificateHandler = new JabberGuestCertificateHandler();
    
    public static class MyPreviewFragment extends PreviewFragment {
    
        public void setup() {
            Button btn = (Button)getView().findViewById(R.id.jgsdk_call_button);
    
            btn.setOnClickListener(
                new OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        getFragmentManager()
                        .beginTransaction()
                        .add(getId(), mCallFragment)
                        .show(mCallFragment)
                        .commit();
                    }
                });
        }
    };
    
    private static FrameLayout mFrameContainer;
    private static CallFragment mCallFragment;
    private static MyPreviewFragment mPreviewFragment;
    

  5. Add the view Holder for the Fragments

    Within your activity_main.xml file, add the FrameLayout to the layout as a holder for your Fragments.

    <FrameLayout
        android:id="@+id/frameContainer"
        android:background="#000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_margin="40dp">
    

  6. Create and use the JabberCall instance

    Add onPause() and replace onCreate with the following code to your MainActivity.java class. You will need to specify your own server and target in the JabberCall.createInstance() method.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            
        mFrameContainer = (FrameLayout) this.findViewById(R.id.frameContainer);
            
        mCallFragment = new CallFragment();
        mPreviewFragment = new MyPreviewFragment();
            
        JabberGuestCall instance = JabberGuestCall.createInstance(
                    this, 
                    JabberGuestCall.createUri("jabberguestsandbox.cisco.com", "5555", null));
        JabberGuestCall.registerInvalidCertificateHandler(mCertificateHandler);
        instance.registerContext(this);
        getFragmentManager()
        .beginTransaction()
        .add(mFrameContainer.getId(), mPreviewFragment)
        .show(mPreviewFragment)
        .commit();
    
    }
    
    @Override
    protected void onPause() {
        JabberGuestCall.unregisterInvalidCertificateHandler(mCertificateHandler);
        JabberGuestCall.getInstance().end();
        super.onPause();
    }
    

  7. Run the Application

    When you launch the application, a call should be made to your specified URI.