Android的 - 在其他应用程序的顶部发射活动 [英] Android - Launching Activity on top of other Apps

查看:84
本文介绍了Android的 - 在其他应用程序的顶部发射活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我想建立一个启动器应用程序,将用户限制到一组唯一允许的应用程序,也不会允许他们访问设备的设置和放大器;任何其他然后允许的应用程序。

Background: I am trying to build a Launcher app that will restrict users to a set of permitted applications only and will not allow them to access device settings & anything other then the permitted apps.

为什么:这是一家私营公司派发的设备给员工使用限制使用项目

Why: This is a project for a private company to distribute devices to their employees with restricted usage.

问题:我能检测到启动其他应用程序,但我不能够覆盖我的活动在它们之上。下面是code,我收到不允许应用程序的播出后尝试。

Issue: I am able to detect launch of other apps, but i am not able to overlay my activity on top of them. Below is the code, i am trying after receiving broadcast of not allowed app.

private class BadAppReceiver extends BroadcastReceiver {

     @Override
     public void onReceive(Context arg0, Intent arg1) {
         Intent i = new Intent(HomePage.this,ErrorClass.class);
         wh.topAct = wh.bad_app;
         HomePage.this.startActivity(i);
         Toast.makeText(HomePage.this, "Access to " + wh.bad_app + " is not allowed.",Toast.LENGTH_LONG).show();
     }

}

有趣的事实:我能叠加,如果我只是推出,而不是试图从我的应用程序打开一个活动的另外一个应用程序。使用该解决方案将让我的应用程序依赖那种在其他应用程序,并冻结屏幕几秒钟。

Interesting Fact: I am able to overlay if I just launch another app instead of trying to open an Activity from my app. Using this solution will make my app dependent on another app and kind of freezes the screen for couple of seconds.

问:我在想什么或者可以做弹出我的活动比其他应用

Question: What am i missing or can do to pop my Activity over other apps.

在此先感谢您的帮助是非常AP preciated。 - Pratidhwani

Thanks in advance and your help is highly appreciated. - Pratidhwani

感谢乌默尔, 我已经使用您的解决方案,但是这是现在发生的事情,用户从托盘打开设置,我的应用程序获得的广播和拍摄ErrorClass活动,面包我在的地方出现,但ErrorClass活动不会出现。因此,用户能够访问设置,现在当用户presses后退按钮上的设置,ErrorClass出现。

Thanks Umer, I have used your solution, but this is what is happening now, user opens settings from tray, my app gets the broadcast and shoots ErrorClass Activity, the Toast I have in place appears but ErrorClass Activity do not appear. So user is able to access the settings, now when user presses back button on settings, ErrorClass appears.

这是我在ErrorClass的onCreate

this is what I have in ErrorClass onCreate

        super.onCreate(savedInstanceState);

         WindowManager.LayoutParams windowManagerParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY , 
                    WindowManager.LayoutParams. FLAG_DIM_BEHIND, PixelFormat.TRANSLUCENT);

         WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View myView = inflater.inflate(R.layout.error, null);

         wm.addView(myView, windowManagerParams);

        wh = ((Launcher) getApplication()).getvar();
        mHandlerReg.removeCallbacks(mUpdatereg);
        mHandlerReg.postDelayed(mUpdatereg,2000);   

谢谢! - Pratidhwani

Thanks!! - Pratidhwani

推荐答案

如果你想覆盖在其他应用程序之上的应用程序,添加以下code。

If you want to overlay an app on top of other apps, add the following code.

 WindowManager.LayoutParams windowManagerParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY , 
            WindowManager.LayoutParams. FLAG_DIM_BEHIND, PixelFormat.TRANSLUCENT);

 WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View myView = inflater.inflate(R.layout.youractivity, null);

 wm.addView(myView, windowManagerParams);

添加权限的Andr​​oid清单:

Add permission to Android Manifest:

SYSTEM_ALERT_WINDOW

这篇关于Android的 - 在其他应用程序的顶部发射活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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