0

I am developing android app in which we take some user information and capture signature and when we click on share button it will store it into database and send an email....but my application is stopping after store operation and does not send a mail....thanks in advance

  String TO []= {Email.getText().toString(),"sourabhkabra960@gmail.com"};
   File filePath = getFileStreamPath(current);  //optional //internal    storage
             //Intent shareIntent = new Intent();

             Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
             //shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL,TO);
             shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Name.getText().toString()");
             shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"AmtRec.getText().toString()");
             //shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(mypath));  //optional//use this when you want to send an image
             shareIntent.setType("image/png");

             shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
             startActivity(Intent.createChooser(shareIntent, "send"));
        Bitmap icon = mBitmap;
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/png");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.PNG, 100, bytes);
        File f = new File(Environment.getExternalStorageDirectory() + "/" + getResources().getString(R.string.external_dir) + "/" +current);
        try {
            mypath.createNewFile();
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
        } catch (IOException e) {                       
                e.printStackTrace();
        }
        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
        startActivity(Intent.createChooser(share, "Share Image"));

LOGCAT:

  02-04 04:25:49.442: E/MediaStore(1269): Failed to insert image
  02-04 04:25:49.442: E/MediaStore(1269): java.io.FileNotFoundException: No such file or directory
  02-04 04:25:49.442: E/MediaStore(1269):   at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:577)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:673)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.content.ContentResolver.openOutputStream(ContentResolver.java:537)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.content.ContentResolver.openOutputStream(ContentResolver.java:513)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:891)
  02-04 04:25:49.442: E/MediaStore(1269):   at com.example.digitalsign.CaptureSignature$signature.save(CaptureSignature.java:437)
  02-04 04:25:49.442: E/MediaStore(1269):   at com.example.digitalsign.CaptureSignature$2.onClick(CaptureSignature.java:139)
  02-04 04:25:49.442: E/MediaStore(1269):   at and roid.view.View.performClick(View.java:4240)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.view.View$PerformClick.run(View.java:17721)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.os.Handler.handleCallback(Handler.java:730)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.os.Handler.dispatchMessage(Handler.java:92)
  02-04 04:25:49.442: E/MediaStore(1269):   at      android.os.Looper.loop(Looper.java:137)
  02-04 04:25:49.442: E/MediaStore(1269):   at android.app.ActivityThread.main(ActivityThread.java:5103)
  02-04 04:25:49.442: E/MediaStore(1269):   at java.lang.reflect.Method.invokeNative(Native Method)
  02-04 04:25:49.442: E/MediaStore(1269):   at java.lang.reflect.Method.invoke(Method.java:525)
ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
Sourabh
  • 3
  • 3
  • 2
    What error you are actually getting , See the catLogs there it will show the exception and errors for stopping the app. – smali Jan 31 '15 at 09:51
  • can you post logcat? – sandeepmaaram Jan 31 '15 at 10:28
  • 1
    possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) –  Jan 31 '15 at 10:57
  • Which of those is line 141? Look at it and scratch your head., it could help. NullPointerException happens when you try to access some fields or methods of a null object. – Vlasec Feb 02 '15 at 11:38
  • where i have to change...plz explain? – Sourabh Feb 02 '15 at 13:07
  • in this i also have file doesn't insert in mail...and app stopped plz reply – Sourabh Feb 03 '15 at 13:37

1 Answers1

0

Don't assume the user is using Gmail. Let them choose.

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"foo@bar.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT   , "Body");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
bryan
  • 798
  • 7
  • 18
  • i used this code but image is not attached with mail...i want in mail png image is also attached....... – Sourabh Feb 04 '15 at 10:50