안드로이드로 어플 삭제하는 기능을 구현해보자. Intent.ACTION_DELETE 를 사용하면 되는데, 이벤트 상수명만 봐도 기능에 대한 내용을 알 수 있도록 네이밍되어 있다. 


 먼저 버튼을 구현한다. 


1
2
3
4
5
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="unInstall"
        android:text="앱제거" />
cs


 unIntall이라는 메서드명을 사용하기로 한다. 이제 MainActivity로 이동하여 Intent 코드를 작성하면 된다. 



1
2
3
4
5
    public void unInstall(View view){
        Uri uri=Uri.fromParts("package""삭제어플의 경로+어플명"null);
        Intent intent=new Intent(Intent.ACTION_DELETE, uri);
        startActivity(intent);
    }
cs


 앱을 삭제하려면 Uri로 삭제하고 싶은 파일의 경로를 적어줘야 한다. 패키지명을 먼저 작성하고 삭제할 어플의 경로와 어플명을 지정 한 뒤 Intent를 선언하면 된다. 


 Intent의 매개변수로 uri를 넣는다는 것을 꼭 알아두자. 

+ Recent posts