广播接收器在另一个应用程序打开特定活动时调用

时间:2015-02-09 09:25:34

标签: android google-maps navigation broadcastreceiver

当在android中打开特定Broadcast receiver的另一个应用程序时,我会调用activity调用。例如,在Navigation手机中安装的Map应用中的android页面,当打开并显示导航时,我想显示Toast显示“当前正在显示导航” 。那我怎么能实现呢?

2 个答案:

答案 0 :(得分:0)

以下代码将帮助您识别窗口更改事件

public class AccessibilityEventService
        extends AccessibilityService {

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
            Log.i("op",event.getPackageName());
    }

}

但必须由用户在设置下的辅助功能启用。 或者您可以使用以下代码检查时间间隔中的当前最高活动

 ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);

// get the info from the currently running task
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);

Log.d("topActivity", "CURRENT Activity ::"
        + taskInfo.get(0).topActivity.getClassName());

ComponentName componentInfo = taskInfo.get(0).topActivity;
    componentInfo.getPackageName();

答案 1 :(得分:-1)

据我所知,您需要在onReceive Function上显示祝酒词

Toast.makeText(context,"your text",2000).show();
//context is input parameter from onRecieve function