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