zoukankan      html  css  js  c++  java
  • Android 判定手机是否root

    Android获取手机root的状态

    package com.app.demo;
    
    import java.io.File;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class AndroiddemoActivity extends Activity {
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);  
    	}
    	public void onclick(View v) {
    		Button button = (Button)v;
    		if (isRootSystem()) {
    			button.setText("root");
    		} else {
    			button.setText("not");
    		}  
    	} 
    
    	private final static int kSystemRootStateUnknow=-1;
    	private final static int kSystemRootStateDisable=0;
    	private final static int kSystemRootStateEnable=1;
    	private static int systemRootState=kSystemRootStateUnknow;
    
    	public static boolean isRootSystem()
    	{
    		if(systemRootState==kSystemRootStateEnable)
    		{
    			return true;
    		}
    		else if(systemRootState==kSystemRootStateDisable)
    		{
    
    			return false;
    		}
    		File f=null;
    		final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"};
    		try{
    			for(int i=0;i<kSuSearchPaths.length;i++)
    			{
    				f=new File(kSuSearchPaths[i]+"su");
    				if(f!=null&&f.exists())
    				{
    					systemRootState=kSystemRootStateEnable;
    					return true;
    				}
    			}
    		}catch(Exception e)
    		{
    		}
    		systemRootState=kSystemRootStateDisable;
    		return false;
    	}
    }


  • 相关阅读:
    4. 归并排序
    3. 堆排序
    2. 希尔排序
    1. 选择排序、插入排序、冒泡排序
    1. 拓扑排序
    8. 最大堆
    7. B+树
    6. B树
    5. 二叉查找树、平衡二叉树、红黑树的效率比较
    4. 红黑二叉树
  • 原文地址:https://www.cnblogs.com/aikongmeng/p/3697374.html
Copyright © 2011-2022 走看看