title: How to open a jpg resource using a button within activity
body: <p>I am trying to open a jpg file from res/raw folder using a button in the activity.  However when launching and testing the app I get an error saying:</p>
  
  <pre><code>11-09 10:20:51.654: E/AndroidRuntime(3247): android.content.ActivityNotFoundException: 
  No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///android.resource:/com.image.imagetest/2131034112 typ=application/jpg flg=0x4000000 }`  
  </code></pre>
  
  <p>This is my code: </p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.fragment_image, container, false);
  
      Button button = (Button) rootView.findViewById(R.id.Image1);
      button.setOnClickListener(new OnClickListener() {
  
          public void onClick(final View v) {
  
              File jpgFile = new File("android.resource://com.image.imagetest/" + R.raw.mainimage);
              Uri path = Uri.fromFile(jpgFile);
              Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              intent.setDataAndType(path, "application/jpg");
  
              startActivity(intent);    
  
          }
      });
      return rootView;
  }
  </code></pre>
  
  <p>Am I missing something here :-) ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have now done this but now when launching app to test i get a message saying "unable to find item" from clicking the button.  Here is my code:</p>
  
  <pre><code>public void onClick(final View v) {
      File jpgFile = new File("android.resource://com.image.imagetest/" + R.raw.mainimage);
      Uri path = Uri.fromFile(jpgFile);
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      intent.setDataAndType(path, "image/jpeg");
      startActivity(intent);  
  }
  </code></pre>