【问题标题】:why PROVIDER_CHANGED not working in android studio?为什么 PROVIDER_CHANGED 不能在 android studio 中工作?
【发布时间】:2019-12-02 15:27:16
【问题描述】:

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

【问题讨论】:

    标签: android gmail provider incoming-mail


    【解决方案1】:

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

    【讨论】:

    • 对不起,我的问题是如何在收到新电子邮件时启动我自己的应用程序?
    【解决方案2】:

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

    【讨论】:

    • 对不起,我之前试过了,我发现这里没有用
    • 我也做了同样的事情,但接收器没有被解雇....还有什么额外的事情要做吗?当我有另一个意图时,即在 AirPlane_MODE 上,正在调用同一个接收器。
    猜你喜欢
    • 2021-07-19
    • 2016-07-17
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2016-10-05
    • 2020-12-22
    • 2014-02-21
    相关资源
    最近更新 更多