如何启动一个活动和通知点击两个服务 [英] How to Start one Activity and two service on notification click

查看:159
本文介绍了如何启动一个活动和通知点击两个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击通知我要开始一个活动和两个意向服务。

When user click on notification I want to start an Activity and two Intent Service.

是否有可能呢?如果是的话请任何一个可以给我的想法做到这一点?

Is it possible to do ? If yes Please can any one give me the idea to do this ?

假设我有活动无法控制。活动所属的第三方应用程序。

Suppose I have no control on Activity. The Activity belongs to third party app.

请不要告诉我,从你开始的活动意图服务。我知道这个。

Please don't tell me that start intent service from your Activity . I know this.

推荐答案

按照以下步骤希望这可以帮助你。

Follow the steps Hope this helps you

1)创建一个BroadcastReceiver

1) Create a BroadCastReceiver

public class MyBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        // Start Activity
        // Start Services
    }

}

2)就消防广播通知上点击。

2) Just Fire Broadcast on notification click.

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(context, MyBroadcastReceiver.class);
        PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
        Notification notification = new Notification(icon, ticker, when);
        notification.setLatestEventInfo(mSmartAndroidActivity, title, message, contentIntent);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);

使用 PendingIntent.getBroadcast 而不是 PendingIntent.getActivity

3)在广播接收器的的onReceive()方法。

3) In BroadcastReceiver's onReceive() method

- >打电话给你的第三方活动

-> call your third party activity

- >启动服务

这篇关于如何启动一个活动和通知点击两个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆