android隐藏某apk主菜单 (二)

这是接上一篇写的。

上一篇文章,只限你能看到launcher的源码才能这样改,但有时候平台用的是第三方的launcher,这样改是不起作用的。

下面还有一种修改方法:

路径为:packages/apps/Provision/src/com/android/provision

若什么都不改,此文件的内容:

/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.provision;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Settings;
/**
 * Application that sets the provisioned bit, like SetupWizard does.
 */
public class DefaultActivity extends Activity {
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        // Add a persistent setting to allow other apps to know the device has been provisioned.
        Settings.Secure.putInt(getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 1);

        // remove this activity from the package manager.
        PackageManager pm = getPackageManager();                 
        ComponentName name = new ComponentName(this, DefaultActivity.class);
        pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

        // terminate the activity.
        finish();
    }
    
}


只需要略作修改即可满足需求:

/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.provision;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
/**
 * Application that sets the provisioned bit, like SetupWizard does.
 */
public class DefaultActivity extends Activity {
	int isATVExist = 0; 
    boolean is_atv_exist = false;
    private static final String TAG = "DefaultActivity";
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        // Add a persistent setting to allow other apps to know the device has been provisioned.
        Settings.Secure.putInt(getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 1);

        // remove this activity from the package manager.
        PackageManager pm = getPackageManager();
                try {
            if (IfExistFile("/sys/class/atv/nmi/dev")) {
                is_atv_exist = true;
                Log.v(TAG, "is_atv_exist11111111 = " + is_atv_exist);
            } else {
                is_atv_exist = false;
                Log.v(TAG, "is_atv_exist111111111 = " + is_atv_exist);
            }
            }catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                is_atv_exist = false;
                Log.v(TAG, "the atv is not  exist");
            }  
        if(!is_atv_exist){
        try{
        	//ComponentName[] set = new ComponentName[1];
        	//set[0] = new ComponentName("com.nmi.test", "com.nmi.test.test");
        	ComponentName atv = new ComponentName("com.nmi.test", "com.nmi.test.test");
//        	IntentFilter filter = new IntentFilter();
//        	filter.addAction(Intent.ACTION_MAIN);
//        	filter.addCategory(Intent.CATEGORY_DEFAULT);
				pm.setComponentEnabledSetting(atv,
						PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
						PackageManager.DONT_KILL_APP);
				//pm.clearPackagePreferredActivities(atv.getPackageName());
			} catch (SecurityException e) {
				Log.v(TAG, "the atv is not  exist");
			}
        }
        
        
        ComponentName name = new ComponentName(this, DefaultActivity.class);
        pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

        // terminate the activity.
        finish();
    }
    
    private boolean IfExistFile(String fileName) throws FileNotFoundException {
        // TODO Auto-generated method stub
        File file = new File(fileName);
        if (file.exists()) {
            return true;
        } else {
            return false;
        }

    }
}

其实也没改什么:只是
加一个判断文件是否存在的函数,这个函数用来判断硬件是否支持ATV,如果不支持,就将ATV菜单隐藏。

先得到包名和类名:ComponentName atv = new ComponentName("com.nmi.test", "com.nmi.test.test");

然后再设置

pm.setComponentEnabledSetting(atv,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);

即可。

运行试试看吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值