为什么mc出现13 permission deniedd咋弄

Terminal Permission Denied on OS X |
Terminal Permission Denied on OS X
by Ashley Poland
The Mac OS Terminal application requires use of keyboard commands but allows greater access to system tools. Stockbyte/Stockbyte/Getty Images
Related Articles
Apple's OS X operating system for Mac computers is based on Unix. Once of the benefits of a Unix-based system is the ability to modify files and run commands from a terminal -- not dissimilar from Linux terminals and commands. When your terminal commands return an error of &Permission Denied,& it's usually a very simple fix regarding user permissions.
Permission Denied Your most likely encounter with a &Permission Denied& error is if you try to install a program or modify a file that's locked -- either because you're not an administrator, or because the owner of the file used chmod to lock the file. If you have a warning before or after &Permission Denied,& read it to understand why you could not execute your command. You can check the permissions of a file by entering &ls -l file.ext& in the terminal, where &file.ext& represents the file and extension of the file you're trying to modify. You can try to force a command that requires administrator permission using &sudo,& though this shouldn't be your first step, nor will it work if your account has been restricted. Check for errors in your syntax and that you're trying to use the right command. If you're trying to run a program, make sure that the program command is valid and installed on your computer. Proceed with Caution Before trying to force a command to work you should consider the potential downside. When something is locked to administrators only, it should serve as a warning that making this change could accidentally mess up your system It's your system's way of warning you to understand the risks before proceeding. Make any copies of relevant files just in case you need a backup later, and double-check that you know exactly what your command is supposed to do. Using Sudo &Sudo& is a simple but powerful command that gives you the ability to run commands as an administrator briefly -- for approximately five minutes. Run your command again, but with &sudo& preceding the command. If your denied command was the last one you tried to run, you can simply enter &sudo !!&. When you first run a program using sudo, you will be prompted for your password. Once authorized, your command will execute as though you're running as the administrator or as root. If you still get a &Permission Denied& error, or are unable to use &sudo,& you may not have permission to do so labeled on your OS X account. Understanding OS X Commands The terminal window can be overwhelming the first couple times you use it -- Unix commands are not always what you would expect, and different from commands you may be familiar with if you ever used Window's command line prompt. SS64 offers a list of commands for OS X /osx, with descriptions as to what each command does and how it works. Additional, there's a page dedicated to the syntax of commands /osx/syntax.html. This also makes a handy reference when you're double-checking that using &sudo& won't break your system.
About the Author Ashley Poland has been writing since 2009. She has worked with local online businesses, supplying print and web content, and pursues an active interest in the computer, technology and gaming industries. In addition to content writing, Poland is also a fiction writer. She studied creative writing at Kansas State University.
Photo Credits
Stockbyte/Stockbyte/Getty ImagesAndroid 6.0版本以后运行时权限提醒
时间: 00:08:08
&&&& 阅读:83
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Android发布6.0以后对app运行所需要的权限提示进行了友好的提示,类似于苹果系统,比如在某个页面要用到打电话的权限,会弹出一个提示框,提示你是否需要同意这个权限,如果同意则app就有了打电话的权限,既可以拨打电话了,不同意则不能拨打电话,只能去设置中勾选,在6.0以前,权限配置都是在AndroidManifest.xml文件中添加例如:
&?xml version="1.0" encoding="utf-8"?&
&manifest xmlns:android="/apk/res/android"
package="com.example.ymx.dynamicpermissiondemo"&
&uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"&&/uses-permission&
&uses-permission android:name="android.permission.CALL_PHONE"&&/uses-permission&
&/manifest&
在配置文件中添加了两个权限,一个是网络状态,一个是打电话权限。
在代码中设置拨打电话:
public class MainActivity extends AppCompatActivity {
private Button mCallB
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCallButton = (Button) findViewById(R.id.call_button);
mCallButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent callIntent = new Intent();
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + "10086"));
startActivity(callIntent);
电话能够正常拨打出去
如果没有注册权限的话,就会报相关异常了:
FATAL EXCEPTION: main
Process: com.example.ymx.dynamicpermissiondemo, PID: 3147
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxx cmp=com.android.server.telecom/.CallActivity } from ProcessRecord{3d45b392 3147:com.example.ymx.dynamicpermissiondemo/u0a59} (pid=3147, uid=10059) requires android.permission.CALL_PHONE
at android.os.Parcel.readException(Parcel.java:1546)
现在来看看Android6.0版本是怎么实现运行时权限提醒的,首先在app的gradle中配置targetSdkVersion=25
package com.example.ymx.d
import android.M
import android.content.I
import android.content.pm.PackageM
import android.net.U
import android.support.annotation.NonN
import android.support.v4.app.ActivityC
import android.support.v4.content.ContextC
import android.support.v7.app.AppCompatA
import android.os.B
import android.view.V
import android.widget.B
import android.widget.T
public class MainActivity extends AppCompatActivity {
private Button callB
private static final int PERMISSION_REQUEST_CODE = 1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callButton = (Button) findViewById(R.id.call_button);
callButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
checkPermission();
//检测用户是否同意权限
private void checkPermission(){
//判断所申请的权限是不是已经通过,没通过返回false,通过返回true,则提示出来并拨打电话
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)!= PackageManager.PERMISSION_GRANTED){
//申请权限回调函数
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CALL_PHONE},PERMISSION_REQUEST_CODE);
Toast.makeText(this,"权限已被申请通过咯!",Toast.LENGTH_SHORT).show();
//打电话方法
private void call(){
Intent callIntent = new Intent();
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel://10086"));
startActivity(callIntent);
//权限申请回调方法
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode){
case PERMISSION_REQUEST_CODE:
//同意申请的权限
if (grantResults.length&0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){
Toast.makeText(this,"同意通过",Toast.LENGTH_SHORT).show();
//拒绝申请的权限
Toast.makeText(this,"拒绝通过",Toast.LENGTH_SHORT).show();
可以看出来,定义很简单,在activity中写了三个方法,分别是打电话,权限校验,权限申请的回调函数,校验权限方法主要是用到了ContextCompat.checkSelfPermission方法,里边接收两个参数,第一个是activity的实例,第二个是你要申请的权限名称,PackageManager.PERMISSION_GRANTED这个参数表示权限已经通过的意思,和ContextCompat.checkSelfPermission的返回结果进行比较,然后做相应处理,如果已经通过了就Toast出来,然后直接拨打电话??,如果没有通过,就请求回调申请权限方法,
方法是ActivityCompat.requestPermissions,里边接收三个参数,一个是activity的实例,第二个是多个权限名称数组,第三个是requestCode,这个requestCode是不是很眼熟,和startActivityForResult中的一样,区分不同权限处理。
在onRequestPermissionsResult中判断用户是不是通过了某个权限,使用的是int[] grantResults参数,先判断它的长度,角标为0表示通过,即PackageManager.PERMISSION_GRANTED,角标为1表示未通过,即PackageManager.PERMISSION_DENIED,来看一下运行效果吧~~~
最后还是别忘了在AndroidManifest.xml中注册相关的uses-permission,这个是不管哪个版本都需要注册的~~~????。
以上只是介绍了6.0版本设置动态权限提醒的基本用法,当要一下申请好多个权限的时候,得想想怎么修改这些逻辑了,
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&国之画&&&& &&&&chrome插件
版权所有 京ICP备号-2
迷上了代码!

我要回帖

更多关于 sh permission denied 的文章

 

随机推荐