I have a problem with permission on android 6. I'm trying to upload a file from the device to the server. If I try with the android emulator there is no problem. The app asks for permission and the uploads the file on the server. Instead if I try to upload the file from my Huawei p8 lite, the app crashs with the error:
java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=3472, uid=10019 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10019 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
at android.os.Parcel.readException(Parcel.java:1602)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.content.ContentProviderClient.call(ContentProviderClient.java:437)
at com.huawei.keyguard.support.LauncherInteractiveUtil$Caller.run(LauncherInteractiveUtil.java:59)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
The function:
FloatingActionButton add=(FloatingActionButton)findViewById(R.id.fab_send_content);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
EditText ed1 = (EditText) findViewById(R.id.edit_insertTitle);
EditText ed2 = (EditText) findViewById(R.id.edit_insertDescr);
String titolo= ed1.getText().toString();
String descrizione= ed2.getText().toString();
if (fileAdded) {
String path=ed4.getText().toString();
String nome=getLastToken(path,"/");
String []params1= {path,titolo};
String[] s = {titolo, descrizione,nome};
new InsertContentMetaData().execute(s);
new InsertFile().execute(params1);
Intent intent1=new Intent(NewContentActivity.this,Main2Activity.class);
finish();
}else{
Toast toast = Toast.makeText(getApplicationContext(), "No file uploaded", Toast.LENGTH_LONG);
toast.show();
}
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
openPDF();
String path=ed4.getText().toString();
if (path!= null) {
Log.d("Sono entrato","ciao");
Log.d("DOPO OPEN PDF",path);
fileAdded=true;
}
}
}
And finally the permission on Android Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- To retrieve the account name (email) as part of sign-in: -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS"/>
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />