NathanaelA / nativescript-permissions

Wraps up the entire Android 6 permissions system in a easy to use plugin.
MIT License
46 stars 22 forks source link

Issue with Manifest #18

Closed cfjedimaster closed 7 years ago

cfjedimaster commented 7 years ago

For some reason, android.Manifest does not exist. I'm testing like so:

    var permissions = require("nativescript-permissions");

console.log(JSON.stringify(android.Manifest));

    permissions.requestPermission(android.Manifest.permission.CAMERA, "I need access to your camera!")
    .then(function() {
        console.log("Woo Hoo, I have the power!");
        //todo - enable button
    })
    .catch(function() {
        console.log("Uh oh, no permissions - plan B time!");
    });

And I never get the request. This is in ngOnInit.

xLama commented 7 years ago

Same issue here.

Angular 2 final.

xLama commented 7 years ago

@cfjedimaster

I executed demo from this repository and It works nice. Check your Manifiest.xml. I have permissions in it but they don´t appear in settings -> apps -> your app -> permissions. They don´t in my case but they do in the demo.

So I think it is a Nativescript or Nativescript-angular issue,

cfjedimaster commented 7 years ago

So for me, it was a few things. Doing a proper build sorted me not getting prompted. But I still get undefined if I console.log(android.Manifest). Should it exist? Things seemed to work despite that, but it's like undefined in JavaScript.

xLama commented 7 years ago

@cfjedimaster

Show your AndroidManifest.xml from app/App_Resources/Android

I made a mistake because I edited AndroidManisfest from platformst and that Manifest is override in compilation. Now It works.

cfjedimaster commented 7 years ago

https://gist.github.com/cfjedimaster/c289e4f2798b5d648480d730dee25b48

xLama commented 7 years ago

Can you confirm your AndroidManifest.xml from platforms is override in compilation?

cfjedimaster commented 7 years ago

Yep

yazdkhasti commented 7 years ago

Same Issue I always get "Uh oh, no permissions - plan B time!".

permissions.requestPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) .then(function() { console.log("Woo Hoo, I have the power!"); }) .catch(function( ex ) { console.log("Uh oh, no permissions - plan B time!" ); });

NathanaelA commented 7 years ago

Ok, a couple things to verify:

  1. The Android manifest to change and add the permissions to is located in your /app/App_Resource/Android/AndroidManifest.xml
  2. I assume all three of you are having issues with NG (Angular2), correct? Are all of you using the ngOnInit in a NG app? I'll have to test; this might too early in the bootstrap. I've always put it in the onNavigatedTo event of the first or relevant window.
  3. If you are using TS; make sure you ARE not defining the "Android" variable; you can declare it so that TS knows its type; but you can NOT define it -- if you define it then it will be whatever value you set it to (including undefined) and then "android.Manifest" will fail... A declaration statement looks exactly like this: declare var android: any; at the top of the file. Anything else and you are asking for issues.
cfjedimaster commented 7 years ago

2) So... this kinda concerns me. From my Cordova experience, I know I have to wait for the deviceready event when doing 'hardware' stuff. I thought NS didn't have this issue? Is there a similar concept in NS that I'm just not aware of - if so - where is this documented?

xLama commented 7 years ago

@NathanaelA

I have no issues. It was my mistake. All work nice for me.

NathanaelA commented 7 years ago

@cfjedimaster - Actually it is just like an native android app; if you do somethings to early (i.e. no activity created yet) then it has issues, if it has to have an activity and/or context for the code to run under.

cfjedimaster commented 7 years ago

Ok.so I don't want to go OT on this bug thread, but is there a general doc page that discusses this?

On Mon, Oct 3, 2016 at 11:36 AM, Nathanael Anderson < notifications@github.com> wrote:

@cfjedimaster https://github.com/cfjedimaster - Actually it is just like an native android app; if you do somethings to early (i.e. no activity created yet) then it has issues, if it has to have an activity and/or context for the code to run under.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NathanaelA/nativescript-permissions/issues/18#issuecomment-251156317, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYBvBJRMcTBcWmw44z7oJeIEe5RlEusks5qwS7wgaJpZM4KJBwm .

Raymond Camden, Developer Advocate for StrongLoop at IBM

Email : raymondcamden@gmail.com Blog : www.raymondcamden.com Twitter: raymondcamden

pawelas commented 7 years ago

Hi, I have the same issue. I'm using typescript with angular2 and when i tried to use android.Manifest its undefined... I have included android17.d.ts

For plain js project its working...

yazdkhasti commented 7 years ago

@NathanaelA Thank you for your quick response, I changed the manifest and added the permission there, Then everything worked fine and i got the messege "Woo Hoo, I have the power!" in the console but no promt for asking permission I am using angular 2 with type script, android 6 on galaxy s7 edge

NathanaelA commented 7 years ago

@yazdkhasti - Some permissions you do not need to actually ask for permission; they are granted as long as they are in the manifest, only some permissions will require the user to accept the permission at runtime.

NathanaelA commented 7 years ago

For clarity for each of these issues:

  1. If you are using TypeScript; you need to have at the top of your file: declare var android: any; this fixes the typescript compile complaining about android not being defined: see my blog post for more info: http://fluentreports.com/blog/?p=308
  2. The request permission code is only needed on Android 6. On prior versions of Android the permissions are only granted via the manifest.So on any device before android 6 you will never see the permission dialogs. This is normal and expected.
  3. You need to declare any dangerous permissions you want both in the manifest and via the request permissions system (ie. this plugin) if you want them to work on Android 6+. Any non-dangerous permissions do NOT have to be asked for on Android 6+ via the permissions plugin, they are granted just like they were before from being in the manifest. So if you ask for a permission and get it granted without a dialog, odds are it is considered a non-dangerous permission. (See main readme for link to list of dangerous permissions)
  4. The android manifest you need to modify is located at /app/App_Resources/Android/AndroidManifest.xml