【问题标题】:Detect incoming email notification in android在android中检测传入的电子邮件通知
【发布时间】:2017-09-22 07:22:33
【问题描述】:

android 收到邮件时能否检测到通知?

有什么解决方案、教程或示例代码我可以尝试吗?

谢谢

【问题讨论】:

    标签: android email service notifications gmail


    【解决方案1】:

    【讨论】:

    • NotificationListenerService 可以检测到来自 gmail 应用程序的传入电子邮件吗?感谢您的链接
    • NotificationManager 没有完整的邮件内容,如果我想读出整个邮件内容怎么办?是否可以从 notificationmanager 获取完整的邮件内容?
    • 这将是一个严重的隐私问题。告诉我,您对真正阅读您电子邮件的应用程序感到满意吗?
    【解决方案2】:

    我认为您搜索的是BroadcastReceiver(仅当您自己管理电子邮件并且不是第三方电子邮件时。这种情况下,您可能无能为力):

    http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html

    【讨论】:

      【解决方案3】:

      你想要下面的 api Jelly bean 你应该使用无障碍服务

      参考以下课程

      accessibility class

      【讨论】:

        【解决方案4】:

        gor 的回答有效(我编辑了一下)!!!谢谢。

        所以将它添加到您的清单中。 这是我用来向我的应用添加通知的接收器类:

        public class GmailReceiver extends BroadcastReceiver{
        
        Context cntxt;
        
        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Email Received", Toast.LENGTH_LONG).show();
           showNotification(context);
        }
        
        private void showNotification(Context context) {
        
            Intent notificationIntent = new Intent(context, YOUR_ACTIVITY_HERE.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context,
                    0, notificationIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
        
            NotificationManager nm = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
        
            Resources res = context.getResources();
            Notification.Builder builder = new Notification.Builder(context);
        
            builder.setContentIntent(contentIntent)
                    .setSmallIcon(R.drawable.YOUR_APP_icon)
                    .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.YOUR_APP_icon))
                    .setTicker(res.getString(R.string.app_name))
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(true)
                    .setContentTitle(res.getString(R.string.app_name))
                    .setContentText(res.getString(R.string.app_name));
            Notification n = builder.getNotification();
            nm.notify(1, n);
        }
        } 
        

        【讨论】:

          【解决方案5】:

          你应该实现一个广播接收器并监听“android.intent.action.PROVIDER_CHANGED”意图

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-01-05
            • 2011-09-05
            • 2011-12-16
            • 2015-11-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多