app操作底层硬件没权限的解决办法:
1.若机器已经root过,可直接在应用层中操作:
String apkRoot="chmod 777 "+getPackageCodePath();
SystemManager.RootCommand(apkRoot);
exeShell("chmod 777 /dev/snd/*");
public class SystemManager {
/**
* 应用程序运行命令获取 Root权限,设备必须已破解(获得ROOT权限)
* @param command 命令:String apkRoot="chmod 777 "+getPackageCodePath(); RootCommand(apkRoot);
* @return 应用程序是/否获取Root权限
*/
public static boolean RootCommand(String command)
{
Process process = null;
DataOutputStream os = null;
try
{
process = Runtime.getRuntime().exec("su");
//process.waitFor();
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
} catch (Exception e)
{
Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage());
return false;
} finally
{
try
{
if (os != null)
{
os.close();
}
process.destroy();
} catch (Exception e)
{
}
}
Log.d("*** DEBUG ***", "Root SUC ");
return true;
}
}
public void exeShell(String cmd){
DataOutputStream os = null;
try{
Process p = Runtime.getRuntime().exec("su");
/*p.getOutputStream().write(cmd.getBytes());
p.getOutputStream().flush();*/
os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
os.close();
p.waitFor();
/*BufferedReader in = new BufferedReader(
new InputStreamReader(
p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
Log.e("exeShell",line);
} */
Log.e("line", "line == null");
}
catch(Throwable t)
{
t.printStackTrace();
}
}
以上是针对已经root过的机器。
2.若机器无法root,但是可以自己编译此机器的android源码:
修改android源码 /system/core/rootdir 文件夹下ueventd.rc
/dev/snd/* 0777 system audio
重新编译烧录即可。
3.每次上电后,使用命令chmod 777 /dev/snd/* 。