Android 颤振锁定任务
我想用android locktask锁定颤振应用程序。我尝试了几种方法,但setLockTaskPackages方法似乎没有任何作用。首先,我尝试在MainActivity的onCreate函数中调用该方法。然后我尝试通过方法通道调用它,但两种方法都不起作用。以下是我的方法通道onCreate功能:Android 颤振锁定任务,android,flutter,Android,Flutter,我想用android locktask锁定颤振应用程序。我尝试了几种方法,但setLockTaskPackages方法似乎没有任何作用。首先,我尝试在MainActivity的onCreate函数中调用该方法。然后我尝试通过方法通道调用它,但两种方法都不起作用。以下是我的方法通道onCreate功能: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState
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);
}
}
);
}
My 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>
知道为什么什么都没发生吗
提前感谢您能解决这个问题吗?我忘了调用
startocktask()
方法。现在一切都好了。