我正在使用这个请求权限使其在API 23上运行,但这会产生一个问题,即代码不希望通过API 21发送信息。
public void sendGetRequest(View v)
{
int version = Build.VERSION.SDK_INT;
if (version >= 23)
{
if(checkAndRequestPermissions())
{ //EXECUTE JSON
new GetClass(this).execute();
}
}
else
{
new GetClass(this).execute();
}
}
如果我删除此权限,API 21将再次完美运行。
05-02 15:02:41.830 12952-13251/com.sandro.openalprsample E/Volley: [9140] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at libcore.net.UriCodec.encode(UriCodec.java:132)
at java.net.URLEncoder.encode(URLEncoder.java:57)
at com.android.volley.Request.encodeParameters(Request.java:480)
at com.android.volley.Request.getBody(Request.java:466)
at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:236)
at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
05-02 15:02:41.860 12952-12952/com.sandro.openalprsample E/ViewRootImpl: sendUserActionEvent() mView == null
使用API 21打开时的堆栈跟踪:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
权限:
module Categorizable
def after_save
# Get the base class. Please note, this will work on 1 level deep STI
klass = self.type.blank? ? self.class : self.class.superclass
siblings = klass.where(category: self.category)
# ...
end
end
如果需要更多信息,我可以更新。