Skip to content

Instantly share code, notes, and snippets.

@operando
Created October 4, 2014 08:13
Show Gist options
  • Save operando/ef173040a421e1fd41ba to your computer and use it in GitHub Desktop.
Save operando/ef173040a421e1fd41ba to your computer and use it in GitHub Desktop.
【Android】悪用厳禁!アンインストールのIntentについて ref: http://qiita.com/operandoOS/items/dda8bb3b7677250af9ee
// String packageName = アンインストールするアプリのPackage名
Uri uri = Uri.fromParts("package", packageName, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
context.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>
// String packageName = アンインストールするアプリのPackage名
// requestCode = 1
Uri uri = Uri.fromParts("package", packageName, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
activity.startActivityForResult(intent, requestCode);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("onActivityResult", "requestCode : " + requestCode);
Log.d("onActivityResult", "resultCode : " + (RESULT_OK == resultCode));
Log.d("onActivityResult", "resultCode : " + resultCode);
Log.d("onActivityResult", "onActivityResult");
}
D/onActivityResult(24263): requestCode : 1
D/onActivityResult(24263): resultCode : false
D/onActivityResult(24263): resultCode : 0
// resultCode = 0 = RESULT_CANCELED??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment