i want to show simple toast on new email came in android studio....i am using Receiver but that is not being fired...
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"/>
<data android:scheme="content"/>
</intent-filter>
</receiver>
And in Receiver
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Mail received ", Toast.LENGTH_SHORT).show();
Log.i("mail","mail received");
context.startActivity(new Intent(context,BottemNavigationActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
I hope this is what you were looking for. You can also register in the service
rather than doing it in manifest
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("com.example.app.START")) {
Toast.makeText(context, "your message", Toast.LENGTH_LONG).show();
}
}
}
Since receiving an email is not a part of the OS, you need to register the trigger for a specific app, like Gmail
. To do that, you need to write these in your manifest:
<receiver android:name="GmailReceiver">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"
android:priority="-10">
</action>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="content" android:host="gmail-ls"
android:pathPattern="/unread/.*">
</data>
</intent-filter>
</receiver>
And then to receive those emails:
public class GmailReceiver extends BroadcastReceiver{
Context context;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Email Received!!", Toast.LENGTH_LONG).show();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.