0

我想在 android studio 中收到的新电子邮件上显示简单的祝酒词……我正在使用 Receiver,但它没有被解雇……

 <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>

在接收器中

 @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));
}
4

2 回答 2

0

我希望这就是你要找的。您也可以注册service而不是在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();
        } 
    }

}
于 2019-07-24T13:08:44.300 回答
0

由于接收电子邮件不是操作系统的一部分,因此您需要为特定应用注册触发器,例如Gmail. 为此,您需要在清单中编写以下内容:

<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>

然后接收这些电子邮件:

public class GmailReceiver extends BroadcastReceiver{

    Context context;
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Email Received!!", Toast.LENGTH_LONG).show();
    }
}
于 2019-07-24T13:23:32.320 回答