PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to send email from broadcastreceiver?

 November 08, 2022     android, email     No comments   

Issue

I am implementing one application.

Based on my application i am created class named "RepeatingAlarm.java"

My RepeatingAlarm class extends broadcastrecevers.

I am calling the above class in every one hour.

My requirement is,when this class is called

I want to get a file from sdcard and send this file through email.

How to do this?


Solution

Add these inside onReceive method in your BroadcastReceiver.

   File file= new File(Environment.getExternalStorageDirectory()
                    + "/filefolder/"+"filename");
Uri u1  =   null;
u1  =   Uri.fromFile(file);

Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sending a file");
 sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
        {"me@gmail.com"}); 
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/html");
context.startActivity(Intent.createChooser(sendIntent , "Send mail..."));


Answered By - Manikandan
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing