我已成功通过我的应用调用第三方应用
以下应用:Google云端硬盘和Google相册
代码:
btnL1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openApp(KioskActivity.this, "com.google.android.apps.docs");
}
});
btnL2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openApp(KioskActivity.this, "com.google.android.apps.photos");
}
});
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (Exception e) {
return false;
}
}
更新#1 以下是我从自己的应用中调用第三方应用活动的Code
在按钮上单击调用第三方应用程序的活动(如:上次调频)
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);
但总是让android.content.ActivityNotFoundException: Unable to find explicit activity class {fm.last.android/fm.last.android.LastFm}; have you declared this activity in your AndroidManifest.xml? And If I use try-catch blog or if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
避免ANF异常,然后它不显示异常,但仍然无法调用活动
我已经在我的设备上安装了上一个FM应用,那么原因可能是什么?
UPDATE#2 :我创建了Hello World应用并成功调用了该应用
截图
Screenshot 1
(仅启用自助终端模式)
Screenshot 2
(刚刚调用Hello World应用程序并按回退出Hello World)
问题:为什么会显示导航栏和底栏(我的意思是后退,主页和最近的键)
这是我的updated code
:
public class KioskActivity extends Activity {
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(flags);
getActionBar().hide();
setContentView(wenchao.kiosk.R.layout.activity_lock_activity);
DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName mDPM = new ComponentName(this, MyAdmin.class);
if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {
String[] packages = {this.getPackageName()};
startLockTask();
} else {
Toast.makeText(getApplicationContext(),"Not owner", Toast.LENGTH_LONG).show();
}
setVolumMax();
Button lock_btn = (Button)findViewById(wenchao.kiosk.R.id.lock_button);
Button unlock_btn = (Button)findViewById(wenchao.kiosk.R.id.unlock_button);
Button appButton = (Button) findViewById(R.id.appButton);
lock_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
startLockTask();
return false;
}
});
unlock_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
stopLockTask();
return false;
}
});
appButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("com.example.hello1","com.example.hello1.MainActivity"));
startActivity(intentDeviceTest);
}
});
}
答案 0 :(得分:0)
Kiosk模式正式名为任务锁定。这个名字包含一个线索。如果launch mode允许第三方活动启动到同一任务,您只能启动第三方活动。如果他们不这样做,您的选择是: