软件管理器-分享和卸载
分享应用: 系统定义:\packages\apps\Mms\AndroidManifest.xml <activity android:name=".ui.ComposeMessageActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateHidden|adjustResize"
android:theme="@style/MmsHoloTheme"
android:parentActivityName=".ui.ConversationList"
android:launchMode="singleTop" > <intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter> </activity> 标准分享地址地址: https://play.google.com/store/apps/details?id=com.tencent.mobileqq 分享应用核心代码: /**
* 7、分享软件
*/
public void shareApplication() {
/*
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
*/
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);//Deliver some data to someone else
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
// Optional standard extras, which may be interpreted by some recipients
// as appropriate,are: EXTRA_EMAIL, EXTRA_CC, EXTRA_BCC, EXTRA_SUBJECT.
intent.putExtra(Intent.EXTRA_TEXT, "给你推荐了一款好的应用:"+clickAppInfo.getAppName()
+",下载地址:https://play.google.com/store/apps/details?id=com.tencent.mobileqq");
startActivity(intent);
}
|
卸载应用: 系统定义: <activity android:name=".UninstallerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.DeviceDefault.Dialog.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.DELETE" />
<action android:name="android.intent.action.UNINSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity> 卸载应用核心代码: private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
ll_app_data.setVisibility(LinearLayout.INVISIBLE);
if (appManageAdapter == null) {// 第一次
appManageAdapter = new AppManageAdapter();
lv_app_manage.setAdapter(appManageAdapter);
} else {// 以后,全部更新界面
appManageAdapter.notifyDataSetChanged();
}
}
}; // 接收卸载后的数据
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
fillData();
}
/**
* 8、卸载软件
*/
public void uninstallApplication(){
/*<intent-filter>
<action android:name="android.intent.action.DELETE" />
<action android:name="android.intent.action.UNINSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>*/
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DELETE);//Input: getData is URI of data to be deleted.
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + clickAppInfo.getAppPackageName()));
startActivityForResult(intent, 0);
}
|
问题1:卸载后,没有更新界面,再次卸载会报错 |
优化2:在卸载软件后,更新ListView界面时,可以注册一个广播接收者,接收卸载成功的广播事件,然后来更新ListView内容操作 最好的做法是:软件卸载时,会有一个广播事件,可以接收这个广播,然后更新ListView界面内容 |