简体   繁体   English

为什么PROVIDER_CHANGED无法在android studio中工作?

[英]why PROVIDER_CHANGED not working in android studio?

i want to show simple toast on new email came in android studio....i am using Receiver but that is not being fired... 我想在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>

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 您也可以在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();
        } 
    }

}

Since receiving an email is not a part of the OS, you need to register the trigger for a specific app, like Gmail . 由于接收电子邮件不是操作系统的一部分,因此您需要为特定应用(例如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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM