三星s8和s9

时间:2018-05-14 09:36:49

标签: java android sdk android-permissions

我的应用程序中有一个下载程序类,用于处理从服务器下载新apk到用户安卓设备,以更新应用程序。  整个模块运行良好,授予读写权限,下载和安装apk没有问题。唯一的问题是Galaxy s9和版本8.0.0的Galaxy s8,我遇到了外部存储的权限被拒绝异常。 我已经使用多个设备和SDK,nexus,nexus 5x,zte,sony Xperia进行了测试。但它看起来只影响Galaxy S8和S9。

错误

  

无权写入/storage/emulated/0/Download/app-release.apk:用户10390和当前进程都没有android.permission.WRITE_EXTERNAL_STORAGE。

更新活动代码

    void downloadOrCancel() {

        if (downloader != null && downloader.isDownloading()) {
             cancel();
         } else {
            download();
         }
        //  updateUi();
    }

    private void cancel() {
        if(downloader != null)
                  downloader.cancel();
    }

    private void download() {
        //   Uri uri = Uri.parse(url);
        downloader = Downloader.newInstance(this);
        downloader.download(URL_APK);
    }


    private void checkPErmissions(){
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                && ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    12);
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    13);

        } else {
            downloadOrCancel();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case 12:
            case 13: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] ==
                        PackageManager.PERMISSION_GRANTED) {
                    // get locations
                    checkPErmissions();
                } else {
                    //Close it
                    finish();
                }
            }
            break;
        }
    }

清单权限

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permissionandroid:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.ACCESS_ALL_DOWNLOADS" />

1 个答案:

答案 0 :(得分:0)

我在你的代码上查了一些东西,但是对我来说一切似乎都很好。我发布这个作为答案,因为评论太长了。

我可以建议的最后一件事是因为它只发生在三星S8和S9上,可能与安装/下载来自未知来源的文件的权限有关。在你的三星去:

TASK [Add File to var] ********************************************************************************************************* ok: [localhost] => (item=--- type: taskWindows actions: abortActions: [] emailNotifications: [] setVariableActions: [] snmpNotifications: [] systemOperations: [] agent: test name: "Test" summary: "Test") TASK [test vars] *************************************************************************************************************** ok: [localhost] => { "msg": "---\ntype: taskWindows\nactions:\n abortActions: []\n emailNotifications: []\n setVariableActions: []\n snmpNotifications: []\n systemOperations: []\nagent: test\nname: \"Test\"\nsummary: \"Test\"" } - &GT; myfiles = sorted(glob.glob('blanks/Day01/Batch02/*.csv')) mypath = 'blanks/Day01/Batch02/' files = [f for f in listdir(mypath) if isfile(join(mypath, f))] # all files in a folder for m in range(len(files)): df = pd.read_csv(mypath + files[m], skiprows=1, delimiter= ',') wl = df['Wavelength (nm)'] A = df['Abs'] - &GT; Settings

并尝试为您的应用启用它。