hypery2k / cordova-barcodescanner-plugin

barcode scanner plugin for PhoneGap
51 stars 39 forks source link

Support Android 6.0 runtime permissions #12

Closed thomwiggers closed 6 years ago

thomwiggers commented 8 years ago

This plugin should request the camera permissions, otherwise it won't work on Android 6.0 if you're targeting sdk level 23

https://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html

hypery2k commented 8 years ago

If I find time I will try to update it

nalroff commented 8 years ago

+1. This is a huge problem for me because I published a new Android app to the store that was built with SDK 23, and now I cannot downgrade. So anyone who installs the app with Android 6 will have a broken app.

hypery2k commented 7 years ago

could you try with the latest master?

hypery2k commented 7 years ago

you can try to install the latest preview via

cordova plugin add  cordova-plugin-barcodescanner@next
peterholcomb commented 7 years ago

Also interested in this fix. I installed the @next version of the plugin and am now getting an error when i run scan():

write settings:false``

hypery2k commented 7 years ago

you can try again. Having not much time to verify it

arsenk01 commented 7 years ago

Still not working for me (((

hypery2k commented 7 years ago

you used cordova-plugin-barcodescanner@next?

arsenk01 commented 7 years ago

yes, and version I saw in config.xml was 0.8

hypery2k commented 7 years ago

could you try

cordova plugin add cordova-plugin-barcodescanner@next

?

lionelhe commented 7 years ago

Hi,

I tried and still have "write settings:false" on @next version

arsenk01 commented 7 years ago

Ok cool

On Thu, Apr 13, 2017 at 6:05 PM, lionelhe notifications@github.com wrote:

Hi,

I tried and still have "write settings:false" on @next https://github.com/next version

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hypery2k/cordova-barcodescanner-plugin/issues/12#issuecomment-293905099, or mute the thread https://github.com/notifications/unsubscribe-auth/ADekRv8F7wnLIaSs2V9prnJpz6RLpDrUks5rviungaJpZM4IwNum .

lionelhe commented 7 years ago

As seen in https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/139

I used the https://github.com/NeoLSN/cordova-plugin-android-permission to handle the problem.

When trying to use QR Code I just call

let permissions = cordova.plugins.permissions;
permissions.checkPermission(permissions.CAMERA, (status) => {
 if (!status.hasPermission) {
    permissions.requestPermission(
      permissions.CAMERA,
      (status) => {
        if (!status.hasPermission) {
          errorCallback();
        } else {
          this.launchQRCodeScan();
        }
      },
      errorCallback);
  } else {
    this.launchQRCodeScan();
  }
}, errorCallback);
KitchenLiang commented 6 years ago

it won't work on Android 6.0. I try again and again, still have "write settings:false"

qiaojiange commented 6 years ago

I have meet this problem and it won't work on Android 6.0.1. it is similar to jb12467. still have "write settings:false"; my cordova version is 7.0.1

qiaojiange commented 6 years ago

I have solve this problem,you can follow this; 1.add cordova-plugin-android-permission,then request permission ,however, it doesn't work; don't give up; why add this plugin? because it will add <uses-permission android:name="android.permission.WRITE_SETTINGS"/> in AndroidManifest.xml If it doesn't work ,you can add by hand;

  1. add this code in MainActivity.java; `

    private void requestWriteSetting(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if(Settings.System.canWrite(MainActivity.this)){ // Do stuff here }else{ Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:"+ getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } } }

`

and then call this method in onCreate method; like this: `

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    // enable Cordova apps to be started in the background
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
        moveTaskToBack(true);
    }

    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    requestWriteSetting();
}

`

it work in my project,and my phone is samsung android 6.0.1.

ekbel commented 6 years ago

@qiaojiange hello and thank you , but this methode return, an error while building the app ! unsafe method , what can i do ? thank you again

lionelhe commented 6 years ago

The write settings rights are presents on the plugin until 0.7.0 The 0.7.1 version only remove this right, so I use 0.7.0 version on my application and I don't have problems.

fabianglace commented 6 years ago

I've been pulling my hair out and I have no hair. This 0.7.0 version is the answer...thanks a great deal...

Drum998 commented 6 years ago

After a day an a half trying to track down this same error I finally also fixed it by reverting to 0.7.0

qiaojiange commented 6 years ago

yes,you can revering to 0.7.0 successful,however, i have try my project with this method but it doesn't work! you can try per method until save you problem due to every person will meet different situation.

hypery2k commented 6 years ago

I reverted the changes and published 0.7.2