android:drawableTop="@drawable/img2"//Textview中显示图片
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/tv_lanuch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/img2" android:text="启动" /> <TextView android:id="@+id/tv_uninstall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/img1" android:text="卸载" /> <TextView android:id="@+id/tv_share" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/img3" android:text="分享" /> </LinearLayout>
三者的相应点击事件:
(1)应用程序的启动需要使用PackageManager根据指定的packageName
来启动相应的应用程序 pm.getLaunchIntentForPackage(packageName);
(2) 应用程序的卸载, 卸载完成后,重写刷新界面, 使用带回传值的启动activity
到相应的卸载界面,
Intent intent = new Intent(Intent.ACTION_DELETE); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse("package:"+packageName));
/** * 启动应用 */ public void launch(String packageName){ PackageManager pm = getPackageManager(); //获得app启动界面的intent Intent intent = pm.getLaunchIntentForPackage(packageName); startActivity(intent); } /** * 卸载应用 */ public void uninstall(String packageName){ //跳转到卸载界面 Intent intent = new Intent(Intent.ACTION_DELETE); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse("package:"+packageName)); startActivityForResult(intent, 0); } /** * 分享应用 */ public void share(String packageName){ Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain");//发送文本 intent.putExtra(Intent.EXTRA_TEXT, packageName); startActivity(intent); } public void startActivityForResult(Intent intent, int requestCode) { initAppData();//卸载完成后,重写刷新界面 super.startActivityForResult(intent, requestCode); }
时间: 2024-10-11 16:24:12