(.NET MAUI) 앱 제거 – ANDROID

ANDROID에서 다른 앱을 제거하는 방법.
(Xamarin 그룹 창에서 누가 물어봐서 궁금해서 찾아봤는데 이미 누군가가 답변을 하더군요.)

MainActivity.cs

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Widget;

namespace Maui.DeleteApp;

(Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density))
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        try
        {
            var name = "com.test.app"; //this.ApplicationContext.PackageName;
            Intent intent = new Intent(Intent.ActionDelete);
            intent.SetData(Android.Net.Uri.Parse("package:" + name));
            StartActivity(intent);
        }
        catch (Exception ex)
        {
            Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
            Finish();
        }
    }
}

권한 부여
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
	<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
		
	</application>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.INTERNET" />
    
	<uses-permission android:name="android.permission.DELETE_PACKAGES" />
	<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
</manifest>

결과(테스트 앱 제거)


(원천)
https://github.com/kei-soft/Maui.DeleteApp

GitHub – kei-soft/Maui.DeleteApp

GitHub에서 계정을 생성하여 kei-soft/Maui.DeleteApp 개발에 기여하십시오.

github.com