我对 android 6 的权限有问题。我正在尝试将文件从设备上传到服务器。如果我尝试使用 android 模拟器没有问题。该应用程序请求许可并将文件上传到服务器上。相反,如果我尝试从华为 p8 lite 上传文件,应用程序会崩溃并出现以下错误:
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)
功能:
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;
}
}
}
最后是 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" />