StartActivity from broadcastreceiver
<p>Onreceive method will crash app at   context.startActivity(Intent.createChooser(sendIntent, "Send"));
It works fine in oncreate method but do not work in broadcastreceiver class.
 Can anybody knows reason. I am new android programmer.
Thanks in advance.</p>

<pre><code>public class SMSReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {

    takePictureNoPreview(context);    
                String imagePath="test.jpeg";
                Intent sendIntent = new Intent(Intent.ACTION_SEND);
            //    sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
                sendIntent.putExtra("sms_body", "I Send you pic.");

                sendIntent.putExtra("address", phoneNumber);
                sendIntent.setType("image/png");
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dataFile));
       //         context.startActivityForResult(sendIntent, 1);
                context.startActivity(Intent.createChooser(sendIntent, "Send"));
      //          context.startActivity(sendIntent);


            }       
        }
}        

        public void takePictureNoPreview(Context context){
            // open back facing camera by default
            Camera myCamera= Camera.open();//openFrontFacingCameraGingerbread();

            if(myCamera!=null){
              try{
                //set camera parameters if you want to
                //...

                // here, the unused surface view and holder
                SurfaceView dummy=new SurfaceView(context);
                myCamera.setPreviewDisplay(dummy.getHolder());    
                myCamera.startPreview(); 

                myCamera.takePicture(null, null, photoCallback);


              } catch (IOException e) {

                e.printStackTrace();
            }finally{
       //         myCamera.close();
              }      

            }else{
                 Toast toast = Toast.makeText(context, "No front Facing camera", Toast.LENGTH_LONG);
                 toast.show();
            }
        }

        Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
            public void onPictureTaken(byte[] data, Camera camera) {
                // Save the image JPEG data to the SD card
                FileOutputStream fos = null;        
            //    camera.startPreview();

                bmp = BitmapFactory.decodeByteArray(data, 0, data.length);  
                StudentDemo.iView.setImageBitmap(bmp);
                 try {
                     fos = new FileOutputStream(dataFile,true);              
                     fos.write(data);
                     fos.close();

                } catch (FileNotFoundException e) {             
                    e.printStackTrace();
                } catch (IOException e) {           
                    e.printStackTrace();
                }

                /*new SavePhotoTask().execute(data);
                camera.startPreview();*/
            }
        };
</code></pre>

<p>}</p>

<p>Android manifest file is </p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.gen.stud"
      android:versionCode="1"
      android:versionName="1.0"&gt;

    &lt;uses-sdk android:minSdkVersion="9"
        android:targetSdkVersion="9" 
        /&gt;

    &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt;
    &lt;uses-permission android:name="android.permission.SEND_SMS"&gt;&lt;/uses-permission&gt;

    &lt;uses-permission android:name="android.permission.CAMERA"&gt;&lt;/uses-permission&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;

    &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
   &lt;uses-feature android:name="android.hardware.camera" /&gt;
&lt;uses-feature android:name="android.hardware.camera.front" /&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
        &lt;activity android:name=".Demo"
                  android:label="@string/app_name"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

        &lt;activity android:name=".StudentDemo"
                  android:label="@string/app_name"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.StudentDemo" /&gt;
                &lt;category android:name="android.intent.category.DEFAULT" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

    &lt;/application&gt;


&lt;/manifest&gt; 
</code></pre>
