13

I have written a code in which I am allowing user to send order via email to vendor [ShopOwner] along with their personal and cart item details, but here I am getting an

error: Unfortunately App has Stopped

Logcat:

01-30 17:56:14.605: E/AndroidRuntime(951): FATAL EXCEPTION: main
01-30 17:56:14.605: E/AndroidRuntime(951): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/html flg=0x1 (has clip) (has extras) }
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivityForResult(Activity.java:3370)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivityForResult(Activity.java:3331)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivity(Activity.java:3566)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivity(Activity.java:3534)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.version.bajrang.january.menu.ArrowsActivity$1.onClick(ArrowsActivity.java:105)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.view.View.performClick(View.java:4202)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.view.View$PerformClick.run(View.java:17340)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Handler.handleCallback(Handler.java:725)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Looper.loop(Looper.java:137)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 17:56:14.605: E/AndroidRuntime(951):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 17:56:14.605: E/AndroidRuntime(951):  at java.lang.reflect.Method.invoke(Method.java:511)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 17:56:14.605: E/AndroidRuntime(951):  at dalvik.system.NativeStart.main(Native Method)

Code:

Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "rakesh@rocketmail.com" };   
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("text/html");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));
startActivity(messageIntent);

Finally with the Help of SahilMahajanMj, I have used this code with little change:

 Intent i = new Intent(Intent.ACTION_SEND);
 i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"rakesh@rocketmail.com"});
 i.putExtra(Intent.EXTRA_SUBJECT, subject);
 i.setType("message/rfc822");
 i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));

try {
    startActivity(Intent.createChooser(i, "Send email via :"));
    Toast.makeText(ArrowsActivity.this, "Email Sent.", Toast.LENGTH_SHORT).show();
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(ArrowsActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
}

In ViewCartActivity.java

public void onClick(View v) {
    // TODO Auto-generated method stub

        Intent mViewCartIntent = new Intent(ViewCartActivity.this, com.version.bajrang.january.menu.ArrowsActivity.class);
        mViewCartIntent.putExtra("name", myTextVeiwGrandTotal.getText().toString());
        startActivity(mViewCartIntent);

            }
        });

In ArrowsActivity.java:

TextView txtName = (TextView) findViewById(R.id.total);
Intent i = getIntent();
String name = i.getStringExtra("name");
txtName.setText(name);

I am using above code to get total number of products in cart and i am able to get and show as well, but here total number of items in cart i also want to show on cart tab like:

https://play.google.com/store/apps/details?id=com.queppelin.tastykhana

they have shown 2 in red...

Jonik
  • 80,077
  • 70
  • 264
  • 372
Babu
  • 957
  • 1
  • 9
  • 21

3 Answers3

20

The error message shows:

ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/html flg=0x1 (has clip) (has extras) }

It means that the android system doesnt found any email sending activity to handle the intent created by you. Make sure you have email application installed in your device.

Also use the following code to send email,

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail"));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
}
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
  • brother in my earlier version i have used same code to send email along with details, few days ago it was working fine and now i have seen i am getting same problem there big big trouble for me...please help – Babu Jan 31 '13 at 05:23
  • have you checked that whether you have email application installed in your device.? – Sahil Mahajan Mj Jan 31 '13 at 06:33
  • Thanks bhaiya i have replaced this i.putExtra(Intent.EXTRA_TEXT, body);with i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body.toString())); and it has worked... – Babu Jan 31 '13 at 06:43
  • please help me like you did earlier, i also want to number of items in cart on Tab like here they have show 2 in red color: https://play.google.com/store/apps/details?id=com.queppelin.tastykhana and i have posted my code and edited my code please check above... – Babu Jan 31 '13 at 09:15
  • @Rakesh I am not getting what the issue is. Can you please put it as a separate question and share the link here. – Sahil Mahajan Mj Jan 31 '13 at 10:13
  • brother please see this question http://stackoverflow.com/questions/14623595/way-to-badge-android-tab-view-at-runtime and if possible so this one also http://stackoverflow.com/questions/14621749/list-of-all-upcoming-facebook-friends-birthdays-in-android – Babu Jan 31 '13 at 10:32
6

Rakesh sorry for late reply, since 10 am i was trying to resolve your issue and i have tried several times and finally below code has worked:

i knew you got answer, but i have given many hours for my satisfaction i am placing my answer here, and brother i don't need points for this, because @SahilMahajanMj deserve this:

  Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"rakesh@rocketmail.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));

        try {
            startActivity(Intent.createChooser(i, "Send email via :"));
            } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(ArrowsActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
        }
ASMUIRTI
  • 1,332
  • 10
  • 20
  • thanks for support : God Bless You, i can't tick on right, but i wish to give you points what you deserve..thanks again.. – Babu Jan 31 '13 at 06:58
3

Seem problem with android.content which you passing with your putExtras .

try something like below:

public Intent sendMail1() {
        Intent messageIntent = new Intent(Intent.ACTION_SEND);

        String aEmailList[] = { "rakesh@rocketmail.com" };
        messageIntent.putExtra(Intent.EXTRA_EMAIL, aEmailList);

        messageIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

        messageIntent.setType("text/html");
        messageIntent.putExtra(Intent.EXTRA_TEXT,
                Html.fromHtml(body.toString()));

        return messageIntent;
    }

Fire your intent like:

startActivity(Intent.createChooser(sendMail1(), "send mail"));
RobinHood
  • 10,897
  • 4
  • 48
  • 97