Android 6.0 = PERMISSION_NOT_GRANTED (Issue with CONTACTS and LOCATION permission) -
i have issue android 6.0 = permission_not_granted
p.s. found problem contacts , location permission, know how fix it?
i can data json , can't send information database because of permission_not_granted exception.
public class dvlaresult extends appcompatactivity implements activitycompat.onrequestpermissionsresultcallback{ private progressdialog progress; gpstracker gps; requestqueue requestqueue; string inserturl = "http://zonec.net/project/insertdetails.php"; double latituded; double longituded; string postcode; private dvlainformation dvlainfo = null; //dvla plate number string dvlaplatenumber; /** * attention: auto-generated implement app indexing api. * see https://g.co/appindexing/androidstudio more information. */ private googleapiclient client; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_dvlaresult); //intent dvla index class intent intent = getintent(); dvlaplatenumber = intent.getstringextra("dvlanumber"); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. client = new googleapiclient.builder(this).addapi(appindex.api).build(); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.menu_my_contacts, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { intent intenturl = new intent(intent.action_view); //set url similar car, based on retrieved information current car string url = ("http://www.autotrader.co.uk/search/used/cars/" + dvlainfo.getmake() + "/postcode/" + postcode + "/radius/5/sort/default/onesearchad/used%2cnearlynew%2cnew/page/1/searchcontext/default/colour/" + dvlainfo.getcolour().tolowercase() + "/fuel-type/" + dvlainfo.getfueltype().tolowercase() + ""); intenturl.setdata(uri.parse(url)); switch (item.getitemid()) { //panel button redirect website similar car yser looking for. case r.id.action_check_similar: startactivity(intenturl); return true; //panel button, redirect report application or other issue case r.id.action_report: startactivity(new intent(this, report.class)); return true; //panel button, redirect subscribe web-page case r.id.action_subscribe: startactivity(new intent(this, subscribe.class)); return true; } return super.onoptionsitemselected(item); } public void sendgetrequest(view v) { //execute json new getclass(this).execute(); } @override public void onstart() { super.onstart(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. client.connect(); action viewaction = action.newaction( action.type_view, // todo: choose action type. "dvlaresult page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app url correct. uri.parse("android-app://com.sandro.openalprsample/http/host/path") ); appindex.appindexapi.start(client, viewaction); } @override public void onstop() { super.onstop(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. action viewaction = action.newaction( action.type_view, // todo: choose action type. "dvlaresult page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app url correct. uri.parse("android-app://com.sandro.openalprsample/http/host/path") ); appindex.appindexapi.end(client, viewaction); client.disconnect(); } private class getclass extends asynctask<string, void, dvlainformation> { private final context context; public getclass(context c) { this.context = c; } protected void onpreexecute() { progress = new progressdialog(this.context); progress.setmessage(getstring(r.string.loadmethod)); progress.show(); } //[start] dvla information website database using url. @override protected dvlainformation doinbackground(string... params) { try { //url information retrieved. final url url = new url("https://dvlasearch.appspot.com/dvlasearch?licenceplate=" + dvlaplatenumber + "&apikey=d47oe2wb4nqgpqn6"); httpurlconnection connection = (httpurlconnection) url.openconnection(); //set connection connection.setrequestmethod("get"); connection.setrequestproperty("user-agent", "mozilla/5.0"); connection.setrequestproperty("accept-language", "en-us,en;0.5"); bufferedreader br = new bufferedreader(new inputstreamreader(connection.getinputstream())); string line; stringbuilder responseoutput = new stringbuilder(); while ((line = br.readline()) != null) { responseoutput.append(line); } br.close(); //read , parse json , responce string dvlainformation obj = new dvlainformation(url.tostring()); obj.readandparsejson(responseoutput.tostring()); return obj; } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; } //[end] dvla information website database using url. @override protected void onpostexecute(final dvlainformation obj) { dvlainfo = obj; final textview outputview = (textview) findviewbyid(r.id.showoutput); outputview.settext(obj.tostring()); progress.dismiss(); //[start] dvla information json final stringbuilder output = new stringbuilder(obj.geturl()); output.append(system.getproperty("line.separator")); output.append("\n").append(system.getproperty("line.separator")); output.append("make : ").append(obj.getmake()); output.append("\nmodel : ").append(obj.getmodel()); output.append("\nsix month rate : ").append(obj.getsixmonthrate()); output.append("\ntwelve month rate : ").append(obj.gettwelvemonthrate()); output.append("\ndate of first registration : ").append(obj.getdateoffirstregistrationegistration()); output.append("\nyear of manufacture : ").append(obj.getyearofmanufacture()); output.append("\ncylinder capacity : ").append(obj.getcylindercapacity()); output.append("\nco2 emmissions : ").append(obj.getco2emissions()); output.append("\nvin number : ").append(obj.getvin()); output.append("\ntransmission type : ").append(obj.gettransmission()); output.append("\nfuel type : ").append(obj.getfueltype()); output.append("\ntax status : ").append(obj.gettaxstatus()); output.append("\ncolour : ").append(obj.getcolour()); output.append("\ntype approval : ").append(obj.gettypeapproval()); output.append("\nwheel plan : ").append(obj.getwheelplan()); output.append("\nrevenue weight : ").append(obj.getrevenueweight()); output.append("\ntax details : ").append(obj.gettaxdetails()); output.append("\nmot details : ").append(obj.getmotdetails()); output.append("\ntaxed : ").append(obj.gettaxed()); output.append("\nmot : ").append(obj.getmot()); //[end] dvla information json //[start] gps location. gps = new gpstracker(dvlaresult.this); latituded = gps.getlatitude(); longituded = gps.getlongitude(); gps.stopusinggps(); geocoder geocoder = new geocoder(getapplicationcontext(), locale.getdefault()); list<address> address = null; try { address = geocoder.getfromlocation(latituded, longituded, 1); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } assert address != null; if (address.size() > 0) { postcode = address.get(0).getpostalcode(); } //[end] gps location //[start] send values database requestqueue = volley.newrequestqueue(getapplicationcontext()); stringrequest request = new stringrequest(request.method.post, inserturl, new response.listener<string>() { @override public void onresponse(string response) { system.out.println(response); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { } }) { // [start] send values database @override protected map<string, string> getparams() throws authfailureerror { //get values index activity intent intent = getintent(); //radio button choice string radiochoice = intent.getstringextra("radiochosen"); //recognition confidence of plate string confidence = intent.getstringextra("confidenceresult"); //unchanged recognised plate number string platenumberun = intent.getstringextra("platenumberresult"); //google user details (id, name, email) intent intentg = getintent(); string useridg = intentg.getstringextra("useridgresult"); string usernameg = intentg.getstringextra("usernamegresult"); string useremailg = intentg.getstringextra("useremailgresult"); //values used insert database map<string, string> parameters = new hashmap<>(); parameters.put("useridg", useridg); parameters.put("usernameg", usernameg); parameters.put("useremailg", useremailg); parameters.put("latitude", string.valueof(latituded)); parameters.put("longitude", string.valueof(longituded)); parameters.put("postcode", postcode); parameters.put("dowithcar", radiochoice); parameters.put("platenumber", dvlaplatenumber); parameters.put("confidenceplate", confidence); parameters.put("platenumberun", platenumberun); parameters.put("make", dvlainfo.getmake()); parameters.put("model", dvlainfo.getmodel()); parameters.put("twelvemonthrate", dvlainfo.gettwelvemonthrate()); parameters.put("yearofmanufacture", dvlainfo.getyearofmanufacture()); parameters.put("cylindercapacity", dvlainfo.getcylindercapacity()); parameters.put("dateoffirstregistration", dvlainfo.getdateoffirstregistrationegistration()); parameters.put("co2emissions", dvlainfo.getco2emissions()); parameters.put("fueltype", dvlainfo.getfueltype()); parameters.put("colour", dvlainfo.getcolour()); parameters.put("mot", dvlainfo.getmot()); parameters.put("motdetails", dvlainfo.getmotdetails()); parameters.put("vin", dvlainfo.getvin()); parameters.put("transmission", dvlainfo.gettransmission()); parameters.put("sixmonthrate", dvlainfo.getsixmonthrate()); parameters.put("taxstatus", dvlainfo.gettaxstatus()); parameters.put("wheelplan", dvlainfo.getwheelplan()); parameters.put("revenueweight", dvlainfo.getrevenueweight()); parameters.put("typeapproval", dvlainfo.gettypeapproval()); parameters.put("taxed", dvlainfo.gettaxed()); parameters.put("taxdetails", dvlainfo.gettaxdetails()); return parameters; } }; //[end] send values database requestqueue.add(request); dvlaresult.this.runonuithread(new runnable() { @override public void run() { outputview.settext(output); progress.dismiss(); } }); } } }
i thought issue permissions android not asking permission while trying sending information database.
i have internet permissions:
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.change_wifi_state" /> <uses-permission android:name="android.permission.change_network_state" /> <uses-permission android:name="android.permission.access_network_state" />
error looks this:
04-25 03:01:25.611 29073-29808/com.sandro.openalprsample e/volley: [615] networkdispatcher.run: unhandled exception java.lang.nullpointerexception: attempt invoke virtual method 'int java.lang.string.length()' on null object reference java.lang.nullpointerexception: attempt invoke virtual method 'int java.lang.string.length()' on null object reference @ libcore.net.uricodec.encode(uricodec.java:132) @ java.net.urlencoder.encode(urlencoder.java:57) @ com.android.volley.request.encodeparameters(request.java:480) @ com.android.volley.request.getbody(request.java:466) @ com.android.volley.toolbox.hurlstack.addbodyifexists(hurlstack.java:236) @ com.android.volley.toolbox.hurlstack.setconnectionparametersforrequest(hurlstack.java:210) @ com.android.volley.toolbox.hurlstack.performrequest(hurlstack.java:106) @ com.android.volley.toolbox.basicnetwork.performrequest(basicnetwork.java:96) @ com.android.volley.networkdispatcher.run(networkdispatcher.java:112)
i have tried 1 , not work:
public boolean isstoragepermissiongranted() { if (build.version.sdk_int >= 23) { if (checkselfpermission(android.manifest.permission.write_external_storage) == packagemanager.permission_granted) { log.v(tag,"permission granted"); return true; } else { log.v(tag,"permission revoked"); activitycompat.requestpermissions(this, new string[]{manifest.permission.write_external_storage}, 1); return false; } } else { //permission automatically granted on sdk<23 upon installation log.v(tag,"permission granted"); return true; } } @override public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) { super.onrequestpermissionsresult(requestcode, permissions, grantresults); if(grantresults[0]== packagemanager.permission_granted){ log.v(tag,"permission: "+permissions[0]+ "was "+grantresults[0]); //resume tasks needing permission } }
obviously. targetsdkversion targeting 23 , need use runtime permission android.permission.write_external_storage
android 6.0 include runtime permission feature. permissions considered dangerous permissions , need request @ run time. android.permission.write_external_storage
1 of them.
you can learn permissions dangerous , permissions normal here normal , dangerous permissions.
and can learn how use android runtime permission here: requesting permissions @ run time.
Comments
Post a Comment