[英]Launching another activity from a 'screen pinned' activity
http://florent-dupont.blogspot.ro/2015/02/android-5-screen-pinning.html
從固定應用程序,您無法啟動輔助應用程序,除非此應用程序具有相同的共享用戶ID(這意味着在AndroidManifest.xml中設置了sharedUserIdis,而第二個應用程序使用相同的證書打包)。 其他應用程序的活動將不被允許啟動,這樣做(通過使用Context.startActivity())將被忽略。
我已經完成了上述兩件事但是startActivity()
仍然被忽略了。
來自https://developer.android.com/reference/android/R.attr.html#lockTaskMode :
如果系統已處於lockTask模式,則啟動以此活動為根的新任務,該任務將啟動或不啟動,具體取決於此活動的包是否已列入白名單。
看起來我已采取必要的步驟來實現這一目標。
有人在那里工作嗎?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (!mDpm.isAdminActive(deviceAdmin)) {
Toast.makeText(this, getString(R.string.not_device_admin), Toast.LENGTH_SHORT).show();
}
if (mDpm.isDeviceOwnerApp(getPackageName()))
{
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName(), "com.that.other.package"});
try
{
enableKioskMode(true);
PackageManager pm = this.getPackageManager();
Intent it = pm.getLaunchIntentForPackage("com.that.other.package");
if (null != it) {
this.startActivity(it);
Log.d(_TAG, "Started activity for com.that.other.package");
}
}
catch (Exception e)
{
Log.e(_TAG, e.getMessage());
finish();
}
} else {
Toast.makeText(this, getString(R.string.not_device_owner), Toast.LENGTH_SHORT).show();
}
}
private void enableKioskMode(boolean enabled) throws Exception
{
if (enabled)
{
if (mDpm.isLockTaskPermitted(this.getPackageName()))
{
startLockTask();
mIsKioskEnabled = true;
mButton.setText(getString(R.string.exit_kiosk_mode));
} else {
Toast.makeText(this, getString(R.string.kiosk_not_permitted), Toast.LENGTH_SHORT).show();
}
} else {
stopLockTask();
mIsKioskEnabled = false;
mButton.setText(getString(R.string.enter_kiosk_mode));
}
}
原來我錯過了android:taskAffinity
標簽。 將它指向兩個包中的相同字符串, startActivity()
應該開始表現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.