繁体   English   中英

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

[英]why PROVIDER_CHANGED not working in android studio?

我想在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));
}

我希望这是您想要的。 您也可以在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();
        } 
    }

}

由于接收电子邮件不是操作系统的一部分,因此您需要为特定应用(例如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();
    }
}

暂无
暂无

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

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