標籤:
My Phone管家(20) 應用管理 介紹PopupWindow中點擊事件
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); }
My Phone管家(20) 應用管理 介紹PopupWindow中點擊事件