简体   繁体   English

Android将活动带到了前面

[英]Android bring activity to front

We have a requirement to have our application always be on top. 我们要求始终将我们的应用程序放在首位。 Effectively we need to create a kiosk mode for the device. 实际上,我们需要为设备创建信息亭模式。 These devices will be supplied to users so they are only using our application on the device. 这些设备将提供给用户,因此他们只在设备上使用我们的应用程序。

We have done some research into trapping all possible key events such as the user pressing Home and Search but this method seems quite difficult. 我们已经做了一些研究来捕获所有可能的关键事件,例如用户按Home和Search,但这种方法似乎很难。

We have decided to try creating a service with our application that will monitor what the topmost process is and if it is not our application to return ours to the top. 我们决定尝试使用我们的应用程序创建一个服务,该应用程序将监视最顶层的进程,以及我们的应用程序是否将我们的应用程序返回到顶部。 We are stuck on the part of bringing our application to the top. 我们坚持将我们的应用程序放在首位。 When attempting to use StartActivity(), nothing happens. 尝试使用StartActivity()时,没有任何反应。 We thought it would be possible to do this in the same way that the home launcher calls our activity. 我们认为有可能以家庭发射器调用我们的活动的方式执行此操作。

We have reviewed all posts related to this but haven't seen to found the right solution. 我们已审核了与此相关的所有帖子,但尚未找到合适的解决方案。 If there is a better way to go about it, please let me know! 如果有更好的方法,请告诉我!

many, many thanks. 非常感谢。

These devices will be supplied to users so they are only using our application on the device. 这些设备将提供给用户,因此他们只在设备上使用我们的应用程序。

The only way that will completely work is if you are manufacturing the device yourself. 完全有效的唯一方法是自己制造设备。

We have decided to try creating a service with our application that will monitor what the topmost process is and if it is not our application to return ours to the top. 我们决定尝试使用我们的应用程序创建一个服务,该应用程序将监视最顶层的进程,以及我们的应用程序是否将我们的应用程序返回到顶部。 We are stuck on the part of bringing our application to the top. 我们坚持将我们的应用程序放在首位。 When attempting to use StartActivity(), nothing happens. 尝试使用StartActivity()时,没有任何反应。 We thought it would be possible to do this in the same way that the home launcher calls our activity. 我们认为有可能以家庭发射器调用我们的活动的方式执行此操作。

Why don't you just make your application the home screen? 你为什么不把你的应用程序作为主屏幕? That way, anyone pressing HOME will go to your application. 这样,任何按HOME的人都会去你的申请。

Of course, users can reboot these devices into "safe mode" and remove your app, unless you are manufacturing the device yourself and can have yours be the firmware's home screen. 当然,用户可以将这些设备重新启动到“安全模式”并删除您的应用程序,除非您自己制造设备并且可以将您的设备作为固件的主屏幕。

Well I'm developing an application which has to be unexitable. 好吧,我正在开发一个必须无法使用的应用程序。 This is because this app is used by traffic wardens, not for daily phoning and we had to make sure that they don't exit our app and surf on the internet instead of working. 这是因为这个应用程序被交通管理员使用,而不是每天打电话,我们必须确保他们不退出我们的应用程序并在互联网上冲浪而不是工作。

So you have to put this into your mainfest: 所以你必须将它放入你的主要节日:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.droid"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" /> 

    <application 
        persistent="true"
        android:icon="@drawable/icon" 
        android:label="@string/app_name" 
        android:debuggable="true">
        <activity android:name=".YourActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:imeOptions="actionSend|flagNoEnterAction"
                  android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <receiver android:name="BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver> 
    </application>
</manifest> 

You have to put a boot receiver class in your app: 你必须在你的应用程序中放置一个启动接收器类:

(BootReceiver.java) (BootReceiver.java)

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent arg1) {
        Intent startupIntent = new Intent(context, YourActivity.class);
        startupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(startupIntent);
    }

}

After this you have to disable all buttons in your Activities: 在此之后,您必须禁用活动中的所有按钮:

/**
 * This method disables all buttons.   
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    return true;
}

/**
 * This method disables all buttons.
 */
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    return true;
}

Now you have the foundation of an application which cannot be exited (even the user presses the home button), and if he restarts the phone your application runs as soon as the boot is completed. 现在你拥有一个无法退出的应用程序的基础(即使用户按下主页按钮),如果他重新启动手机,你的应用程序会在启动完成后立即运行。 Now he can only wipe your app if he has adb (and you left usb debugging on), or if he hard resets the phone. 现在他只能擦拭你的应用程序,如果他有adb(并且你打开了usb调试),或者如果他硬重置手机。

Feel free to ask questions if it is not clear or if i left some mistakes in the code below. 如果不清楚或者我在下面的代码中遗漏了一些错误,请随意提问。 And by the way you have to replace the ...-s in with your own code. 顺便说一句,你必须用你自己的代码替换...。

Edit: corrected the xml. 编辑:更正了xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android,将已经开始的活动带回到最前面 - Android, bring already started activity back to front 有意识地将活动放在首位 - Bring activity to front with intent 在Android内,如何开始一项活动,或者如果该活动已经在堆栈中,那么该活动如何发挥作用? - Within Android, how do I start an activity or bring to front that activity if already on stack? Android正在进行呼叫前进? - Android Bring call in progress to front? android带到前面不能在卡片视图上工作 - android bring to front not working on card view 如果活动正在运行或者使用backpress创建新活动,请将活动放在前面 - Bring activity front if it is running or create new one with backpress Android createChooser出现在Activity的前面 - Android createChooser appear in front of Activity 如何在Android Studio中将小部件置于其他提升的小部件的前面 - How to bring a widget in-front of the other elevated widget in android studio Android:如何将 recyclerview 滚动条置于 RecyclerView.ItemDecoration 的前面? - Android: How to bring recyclerview scrollbar to front over RecyclerView.ItemDecoration? 如何调出Android活动堆栈中存在的活动? - how to bring up the activity that exists in the activity back-stack in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM