Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the secure settings of the android phone with my ionic 2 app?

I'm using Ionic 2 and the secureStorage plugin. The problem is that with Android, the device has to be secured with a code to use secure storage.

In the documentation it has:

var ss;
var _init = function () {
    ss = new cordova.plugins.SecureStorage(
        function () {
            console.log('OK');
        },
        function () {
            navigator.notification.alert(
                'Please enable the screen lock on your device. This app cannot operate securely without it.',
                function () {
                    ss.secureDevice(
                        function () {
                            _init();
                        },
                        function () {
                            _init();
                        }
                    );
                },
                'Screen lock is disabled'
            );
        },
        'my_app');
};
_init();

But I'm not using ionic 1 but ionic 2. How to call the secureDevice method?

I do anything like:

this.secureStorage.create('myStorage')
                .then((storage: SecureStorageObject) => {
                    storage.set('var', 'toto')
                        .then(
                        () => console.log('ok),
                        (e) => console.log('error');
                        );
                }).catch((err) => {
                    console.error('The device is not secured');
                })

I can detect in the catch that the device is not secured. But how can I add next to my console.err a call to the secureDevice method?

The documentation: https://ionicframework.com/docs/native/secure-storage/

like image 871
anubis Avatar asked May 24 '17 11:05

anubis


People also ask

How can I use ionic app in Mobile?

To run your app, all you have to do is enable USB debugging and Developer Mode on your Android device, then run ionic cordova run android --device from the command line. Enabling USB debugging and Developer Mode can vary between devices, but is easy to look up with a Google search.

Is ionic secure storage free?

Don't have a Secure Storage subscription? Try it free now.

What is Ionic framework in Android?

Ionic is an HTML5 mobile app development framework targeted at building hybrid mobile apps. Hybrid apps are essentially small websites running in a browser shell in an app that have access to the native platform layer.


1 Answers

This issue was raised and fixed so you can use the latest version of @ionic-native/SecureStorage.

If you are unable to update the ionic-native wrapper, read further.

secureDevice function doesnt seem to be added in the ionic-native wrapper though its available in the cordova plugin.

You could think of using the cordova plugin without the wrapper.

ionic cordova plugin add cordova-plugin-secure-storage --save

Immediately after the imports and before the class, declare the object .

declare var cordova:any;

And use the plugin api within platform ready().

this.platform.ready().then(() =>{
   this.ss =  new cordova.plugins.SecureStorage(
() => { console.log('Success')},
(error) => { 
   console.log('Error ' + error);
   //call here..
   this.ss.secureDevice(()=>{},()=>{});
 },
'myStorage');
});
like image 171
Suraj Rao Avatar answered Oct 16 '22 04:10

Suraj Rao