我正在使用 EasyPermissions 检查是否在我的 android 中授予了某些权限,如果没有,则请求它们。很酷的库,效果很好,但我仍然没有弄清楚如何处理某些权限被拒绝的情况。
所以基本上你在创建时运行这样的代码来检查
if (EasyPermissions.hasPermissions(Splash.this, perms )) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
String SimSimSerial = telephonyManager.getSimSerialNumber();
Toast.makeText(Splash.this, "IMEI: " + IMEI + " SimSerial: " + SimSimSerial, Toast.LENGTH_SHORT).show();
} else {
EasyPermissions.requestPermissions(Splash.this, "Without these permissions, the app is unable to successfully complete authentication. Please allow us to access your device so that we can better serve you. " ,PERMS_REQUEST_CODE, perms );
}
Run Code Online (Sandbox Code Playgroud)
代码分解:如果存在权限,则继续其他请求,这很好。我的问题是,如果在请求期间有人单击从不询问按钮会怎样。EasyPermissions 的人有一个功能,它的
EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)
Run Code Online (Sandbox Code Playgroud)
我的困境是在哪里调用此函数,因为请求权限方法不返回任何内容(无效)。我试过类似的东西
if (EasyPermissions.hasPermissions(Splash.this, perms )) {... …Run Code Online (Sandbox Code Playgroud) 这可能是最简单的事情,但对于我的生活,我还没有想到它.
我有一个方法来设置布局的背景颜色,但我想将颜色作为参数传递,就像我们使用可绘制资源一样.例如
public void setIcon (Drawable icon){
this.icon = context.getResources().getDrawable(icon);
}
setIcon(R.drawable.tuborg);
Run Code Online (Sandbox Code Playgroud)
我希望能够做类似的事情color (R.color.id).我试过了
public void setColor (Color color){
layout.setBackgroundColor(context.getResources().getColor(color));
}
Run Code Online (Sandbox Code Playgroud)
和
public void setColor (Color color){
layout.setBackgroundColor(ContextCompat.getColor(color));
}
Run Code Online (Sandbox Code Playgroud)
两者都要求int,甚至(int color)不起作用.另外,我试图避免使用Color.parse().
这就是我使用该功能的方式
setColor(R.color.colorAccent);
Run Code Online (Sandbox Code Playgroud)
我有一个带有各种颜色代码的xml.我希望能够调用此函数并获得背景颜色更改.
我有一个函数可以检查字符串(参数)是否与数组中的值匹配并返回可能性键的数组
function find_possible_match( $criteria ) {
$possible_match = array();
$possibilities = array(
"a"=>".-",
"b"=>"-...",
"c"=>"-.-.",
"d"=>"-..",
"e"=>".",
"f"=>"..-.",
"g"=>"--.",
"h"=>"....",
"i"=>"..",
"j"=>".---",
"k"=>"-.-",
"l"=>".-..",
"m"=>"--",
"n"=>"-.",
"o"=>"---",
"p"=>".--.",
"q"=>"--.-",
"r"=>".-.",
"s"=>"...",
"t"=>"-",
"u"=>"..-",
"v"=>"...-",
"w"=>".--",
"x"=>"-..-",
"y"=>"-.--",
"z"=>"--..",
"0"=>"-----",
"1"=>".----",
"2"=>"..---",
"3"=>"...--",
"4"=>"....-",
"5"=>".....",
"6"=>"-....",
"7"=>"--...",
"8"=>"---..",
"9"=>"----.",
"."=>".-.-.-",
","=>"--..--",
"?"=>"..--..",
"/"=>"-..-.",
" "=>" ");
foreach ( $possibilities as $key => $value ) {
if( $value == $criteria ){
array_push( $possible_match , $key );
}
}
return $possible_match;
}
Run Code Online (Sandbox Code Playgroud)
这是非常标准的,是所有字符串的标准 …