我能否以线性布局打开第三方安装的应用程序 或者在框架布局中,单击按钮。我的意思是,我想要两个应用程序 同时。一个在顶部框架上,另一个在底部框架上。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mulititask.MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="some text" />
<Button
android:id="@+id/btnbrowser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_toLeftOf="@+id/btnpdbreader"
android:text="open browser" />
<Button
android:id="@+id/btnpdbreader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnbrowser"
android:layout_alignBottom="@+id/btnbrowser"
android:layout_alignParentRight="true"
android:text="open pdb reader" />
</RelativeLayout>
<TableLayout
android:id="@+id/tlayout"
android:layout_width="match_parent"
android:layout_height="265dp"
android:layout_gravity="bottom"
android:background="#991535" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp" >
<Button
android:id="@+id/btnhide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="hide this frame"
android:textColor="#ffffff" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Open browser or pdb file viewer within this frame on default button click" />
</TableRow>
</TableLayout>
</FrameLayout>
package com.mulititask;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
public class MainActivity extends ActionBarActivity {
Button btnbrowser, btncalc, btnhideframe;
TableLayout tlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnhideframe = (Button) findViewById(R.id.btnhide);
btnbrowser = (Button) findViewById(R.id.btnbrowser);
btncalc = (Button) findViewById(R.id.btnpdbreader);
tlayout = (TableLayout) findViewById(R.id.tlayout);
tlayout.setVisibility(View.GONE);
btnhideframe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tlayout.setVisibility(View.GONE);
}
});
btnbrowser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tlayout.setVisibility(View.VISIBLE);
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.browser.ucweb");//"com.browser.ucweb" is not correct and thats not a problem. So leave it
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
}
});
btncalc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tlayout.setVisibility(View.VISIBLE);
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.calculator.default");//"com.calculator.default" is not correct and thats not a problem. So leave it
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
}
});
}
}
在这个项目中,我可以在我的应用程序之外打开应用程序,但无法在我的表格布局中打开。是否有任何代码以这种方式打开应用程序?