beginner question.

by Honest » Thu, 04 Dec 2008 00:59:51 GMT


Sponsored Links
 I am just learning android. I was reading API documentation. I found
the following line of code which i cannot understand so can some one
explain me what is wrong in it ?


String path = intent.getStringExtra("com.example.android.apis.Path");

Can some one tell me what this method getStringExtra() will do ? and
the String "com.example.android.apis.path") means ?



--~--~---------~--~----~------------~-------~--~----~



beginner question.

by Mark Murphy » Thu, 04 Dec 2008 01:30:37 GMT


 


Intents can be packaged with "extras", which more or less amount to a 
Map of additional bits of data. While the "extras" aren't used in 
routing Intents to applications that can handle them, they can package 
information that the recipients could use to better handle the request.

Since "extras" are keyed by Strings, the core Android team recommends 
you use a namespaced-qualified key (e.g., 
"com.example.android.apis.Path") rather than something short (e.g., 
"Path"), to make sure there aren't any collisions on naming.

In terms of what, exactly, "com.example.android.apis.Path" should hold, 
you would have to ask the author of the code where you got that sample 
from. It is up to the Intent recipient to document what extras are 
available and what they should hold if used.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Looking for UML for Android

I've spent the last couple hours looking for the "right" Eclipse
plugin to provide UML for Andorid and have not had any real luck.  Can
someone point me in the right direction please?   free licensing of
course.

Thanks,
Wes
--~--~---------~--~----~------------~-------~--~----~

2. Camera Preview onto SurfaceView using xml

ugh, it seems that the 1st post i made never actually appeared,
so....  what i am trying to do is make a simple camera application,
one with a surfaceview and a button which are defined in the layout
xml, to preview the camera and then take an image, but every time i
try to map the preview onto the surfaceview i get a
nullpointerexception. which is very annoying. i have basically just
used the camerapreview from the api demos, and extended it so the
content view isnt directly into the surfaceview, so now i get the
chance to add a button to the interface.
if anyone knows any way to do this, or has any sample code, i would
appreciate it very much. code is below, sans imports.


////////////////////////////////////////////////////

public class Camera extends Activity {
  private TabHost myTabHost;
 private Preview mPreview;


  @Override
        protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //SurfaceHolder  mHolder;
        // Hide the window title.
      // requestWindowFeature(Window.FEATURE_NO_TITLE);




        setContentView(R.layout.tabs);
        mPreview = new Preview(this);

        this.myTabHost = (TabHost)this.findViewById(R.id.tabhost);
        this.myTabHost.setup();

        TabSpec ts1 = myTabHost.newTabSpec("TAB1");
        ts1.setIndicator("Take Photo",
getResources().getDrawable(R.drawable.cameraphoto));
        ts1.setContent(R.id.grid_set_menu_page1);
        this.myTabHost.addTab(ts1);

        TabSpec ts2 = myTabHost.newTabSpec("TAB2");
        ts2.setIndicator("Album",
getResources().getDrawable(R.drawable.driveharddisk));
        ts2.setContent(R.id.grid_set_menu_page2);
        this.myTabHost.addTab(ts2);

        TabSpec ts3 = myTabHost.newTabSpec("TAB3");
        ts3.setIndicator("Upload",
getResources().getDrawable(R.drawable.networkwireless));
        ts3.setContent(R.id.grid_set_menu_page3);
        this.myTabHost.addTab(ts3);

        this.myTabHost.setCurrentTab(0);


//mPreview = (Preview) findViewById(R.id.photo_surface);

}


    @Override
  protected void onResume() {
  // Because the CameraDevice object is not a shared resource,
  // it's very important to release it when the activity is paused.
  super.onResume();
  mPreview.resume();
}

@Override
  protected void onPause() {
  // Start Preview again when we resume.
  super.onPause();
  mPreview.pause();
}


}



class Preview extends SurfaceView implements SurfaceHolder.Callback {
    SurfaceHolder  mHolder;
    private PreviewThread mPreviewThread;
    private boolean mHasSurface;
SurfaceView Sview;
    Preview(Context context) {
        super(context);

        // Install a SurfaceHolder.Callback so we get notified when
the
        // underlying surface is created and destroyed.
        Sview=(SurfaceView) findViewById(R.id.photo_surface);
        mHolder = Sview.getHolder();

        mHolder.addCallback(this);
        mHasSurface = false;

        // In this example, we hardcode the size of the preview. In a
real
        // application this should be more dynamic. This guarantees
that
        // the uderlying surface will never change size.
        mHolder.setFixedSize(320, 240);
    }

    public void resume() {
        // We do the actual acquisition in a separate thread. Create
it now.
        if (mPreviewThread == null) {
            mPreviewThread = new PreviewThread();
            // If we already have a surface, just start the thread now
too.
            if (mHasSurface == true) {
                mPreviewThread.start();
            }
        }
    }

    public void pause() {
        // Stop Preview.
        if (mPreviewThread != null) {
            mPreviewThread.requestExitAndWait();
            mPreviewThread = null;
        }
    }

    public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, start our main acquisition
thread.
        mHasSurface = true;
        if (mPreviewThread != null) {
            mPreviewThread.start();
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        // Surface will be destroyed when we return. Stop the preview.
        mHasSurface = false;
        pause();
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
        // Surface size or format has changed. This should not happen
in this
        // example.
    }

    //
----------------------------------------------------------------------

    class PreviewThread extends Thread {
        private boolean mDone;

        PreviewThread() {
            super();
            mDone = false;
        }

        @Override
                public void run() {
            // We first open the CameraDevice and configure it.
            CameraDevice camera = CameraDevice.open();
            if (camera != null) {
                CameraDevice.CaptureParams param = new
CameraDevice.CaptureParams();
                    param.type = 1; // preview
                    param.srcWidth      = 1280;
                    param.srcHeight     = 960;
                    param.leftPixel     = 0;
                    param.topPixel      = 0;
                    param.outputWidth   = 320;
                    param.outputHeight  = 240;
                    param.dataFormat    = 2; // RGB_565
                camera.setCaptureParams(param);
            }

            // This is our main acquisition thread's loop, we go until
            // asked to quit.
            SurfaceHolder holder = mHolder;
            while (!mDone) {
                // Lock the surface, this returns a Canvas that can
                // be used to render into.
                Canvas canvas = holder.lockCanvas();

                // Capture directly into the Surface
                if (camera != null) {
                    camera.capture(canvas);
                }

                // And finally unlock and post the surface.
                holder.unlockCanvasAndPost(canvas);
            }

            // Make sure to release the CameraDevice
            if (camera != null) {
                                camera.close();
                        }
        }

        public void requestExitAndWait() {
            // don't call this from PreviewThread thread or it a
guaranteed
            // deadlock!
            mDone = true;
            try {
                join();
            } catch (InterruptedException ex) { }
        }
    }
}

///////////////////////////////////////////////////

--~--~---------~--~----~------------~-------~--~----~

3. WindowsLIve - Google needs to step up

4. how can I open an application using my code

5. how to 'grep' for a file in the android file system?

6. USSD API ?

7. Golfzilla