android - Flutter LockTask
问题描述
我想用 android locktask 锁定一个颤动的应用程序。我尝试了几种方法,但 setLockTaskPackages 方法似乎没有做任何事情。一开始我尝试调用MainActivity的onCreate函数中的方法。然后我尝试通过方法通道调用它,但两种方法都不起作用。这是我的带有方法通道的 onCreate 函数:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
mDevicePolicyManager = (DevicePolicyManager) this.getSystemService(Context.DEVICE_POLICY_SERVICE);
mAdminName = new ComponentName(this, Receiver_Admin.class);
new MethodChannel(getFlutterView(), "com.packagename/kiosk").setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
mDevicePolicyManager.setLockTaskPackages(
mAdminName,
new String[]{"com.packagename"}
);
result.success(null);
}
}
);
}
我的 AndroidMainifest.xml:
<receiver
android:name=".receiver.Receiver_Admin"
android:label="Sehne"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
任何想法为什么什么都没有发生?
提前致谢
解决方案
推荐阅读
- html - 如何使用超脚本助手创建导航?
- python - 将 pd.series 与差异长度进行比较并仅显示差异值
- reactjs - React 项目在 Heroku 上因许多分配失败而崩溃,但在本地开发人员上运行
- javascript - 我们如何以角度向 DOM 元素(来自 ts 文件)注入属性指令
- javascript - 在 Vue.js 中使用 $state 的最佳方式是什么?
- python - Azure Durable 函数 python DurableOrchestrationContext get_input 返回 null
- java - 将数组打印到控制台时是否可以隐藏数组中的元素?
- python - 在python中使用plotly的地震jsondata的Scattergeo
- javascript - 在 Mongoose 分页时更新 Javascript 函数
- html - 可见性属性在 html 文件中不起作用