简体   繁体   English

Android-自动启动应用程序并限制对其他应用程序的访问

[英]Android - Autostart app and restrict access to other apps

I'm fairly new in Android development and I have an app that I'm working on for kids. 我在Android开发领域还很陌生,我有一个正在为孩子们开发的应用程序。 I would like the app to start itself when the device starts up. 我希望该应用在设备启动时自行启动。 When the app is running, I want it to prevent access to any other screens. 当应用程序运行时,我希望它阻止访问任何其他屏幕。 Disable home buttons, prevent access to browser, settings etc. 禁用主页按钮,禁止访问浏览器,设置等。

Is this possible to do? 这可能吗? I stumbled across this link http://www.androidsnippets.com/autostart-an-application-at-bootup , but a few people think it's not a good approach to allow activities to start automatically. 我偶然发现了该链接http://www.androidsnippets.com/autostart-an-application-at-bootup ,但是有些人认为让活动自动开始并不是一种好方法。

Thank you :-) 谢谢 :-)

Sounds like you need your own launcher, because only launcher can prevent access to unnecessary screens and Home button will be "blocked" with your launcher. 听起来您需要自己的启动器,因为只有启动器才能阻止访问不必要的屏幕,并且启动器会“阻止”“主页”按钮。
It will also solve the "start-up" problem. 它还将解决“启动”问题。

All you need to do is to declare Activity in your AndroidManifest like this: 您需要做的就是在AndroidManifest声明Activity ,如下所示:

<activity
android:name="your.package.ActivityName
android:launchMode="singleTask">
<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>

Activate your creativity, and build launcher for your needs. 激活您的创造力,并根据需要构建启动器。
Good luck! 祝好运!

This is to set the app as the startup application in your device Create a Class extends BroadCast Reciever 这是将应用程序设置为设备中的启动应用程序。创建一个类扩展BroadCast Reciever

public class BootUpReciever extends BroadcastReceiver
{

@Override
public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, ServerPreferenceActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
}
}

Add permissions to manifest file to excess bootup receiver 向清单文件添加权限到多余的启动接收器

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Register your receiver which extended the Broadcast receiver in manifest.xml 在manifest.xml中注册扩展了广播接收器的接收器

<receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
    <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

Note: Create the receiver class in a separate package in the src folder to acheive the working implementation. 注意:在src文件夹中的单独程序包中创建接收器类,以实现有效的实现。

Regarding your question: 关于您的问题:

  1. "I would like the app to start itself when the device starts up." “我希望该应用在设备启动时启动。”

    You can implement a BroadcastReceiver for catching the RECEIVE_BOOT_COMPLETED event. 您可以实现一个BroadcastReceiver来捕获RECEIVE_BOOT_COMPLETED事件。 See this post . 看到这篇文章

  2. "When the app is running, I want it to prevent access to any other screens." “当应用程序运行时,我希望它阻止访问任何其他屏幕。”

    You could restart your activity whenever it got destroyed or paused. 每当活动遭到破坏或暂停时,您都可以重新开始活动。 You could check this in a background Service . 您可以在后台服务中进行检查。 Check this post for more. 检查这个职位更多。

  3. "Disable home buttons" “禁用主页按钮”

    Simply not possible. 根本不可能。 You have to rely on the result of 2. here. 您必须在这里依靠2.的结果。

  4. "prevent access to browser, settings etc." “防止访问浏览器,设置等。”

    Similar to 3. - you can't really avoid this. 与3类似-您无法避免这种情况。 However, you can check if your app is on top and restart it, if not. 但是,您可以检查您的应用程序是否位于顶部,然后重新启动。

Hope this helps ... Cheers! 希望这可以帮助...干杯!

You can build a Home App that will be the device interface with the user, by doing so you can manage the user experience. 您可以构建家庭应用程序 ,将其作为与用户的设备界面,从而可以管理用户体验。 take a look here : SO Question 在这里看看:所以问题

But building a Launcher/Home app includes a lot of responsibilities. 但是构建启动器/家庭应用程序需要承担很多责任。 you will be responsible for all user access: 您将负责所有用户的访问:

  • settings 设定
  • Telephony 电话技术
  • Other apps 其他应用
  • Basic smartphone apps (Mail , calendar ...). 基本的智能手机应用程序(邮件,日历...)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM