当在android中打开另一个应用程序(特定的activity
)时,我会调用Broadcast receiver
。例如,当android
手机中安装的Map
应用程序中的Navigation
页面打开并显示导航时,我想显示一个显示"当前显示导航"的Toast
。那么我该如何做到这一点呢?
下面的代码将帮助您识别windo更改事件
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();
据我所知,您需要在onRecieve Fuunction 上展示祝酒词
Toast.makeText(context,"your text",2000).show();
//context is input parameter from onRecieve function