我们如何以编程方式隐藏android中的应用程序?

nwnhqdif  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(301)

我想在android studio中隐藏一个应用程序。
我已经创建了一个deviceadminreceiver,它在应用程序被授予管理权限时侦听。


# MyDevicePolicyReceiver.java

public class MyDevicePolicyReceiver extends DeviceAdminReceiver {
    @Override
    public void onDisabled(Context context, Intent intent) {
        Toast.makeText(context, "Truiton's Device Admin Disabled",
                Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onEnabled(Context context, Intent intent) {
        Toast.makeText(context, "Truiton's Device Admin is now enabled",
                Toast.LENGTH_SHORT).show();
    }
    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        CharSequence disableRequestedSeq = "Requesting to disable Device Admin";
        return disableRequestedSeq;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        Log.i("qwerty", "MyDevicePolicyReciever Received: " + intent.getAction());
    }
    public static void enableApp(Context ctx, String pk){
        try {
            DevicePolicyManager dpm = (DevicePolicyManager) ctx.getSystemService(Context.DEVICE_POLICY_SERVICE);
            ComponentName localComponent = getComponentName(ctx);
            dpm.setApplicationHidden(localComponent, pk, false);
        }
        catch(Exception e){
            e.printStackTrace();
            Log.d("qwerty",e.toString());
            Log.d("qwerty",e.getMessage());
        }
    }
}

我正在使用devicepolicymanager的setapplicationhidden从应用程序菜单中隐藏应用程序(在disableapp方法中)。
我收到以下错误 dpm.setApplicationHidden(localComponent, pk, false); :

java.lang.SecurityException: Admin ComponentInfo{com.example.applocker/com.example.applocker.broadcast.MyDevicePolicyReceiver} does not own the profile.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题