Is 'worklight.db' used for Android apps for persisting cookies? - ibm-mobilefirst

In a MobileFirst app I can see from JS code inside "worklight.js" that my app is using a SQLite file to store cookies.
However, from Chrome inspector I cannot find this file.
I am using IBM MobileFirst for Android and iOS apps.
// The database file is in the application storage
// directory
var folder = air.File.applicationStorageDirectory;
var dbFile = folder.resolvePath("worklight.db");
try {
this.conn.open(dbFile);
} catch (e) {
WL.Logger.error("Error opening cookies DB: " + e.message + ", Details: " + e.details);
return;
}
However, this code is inside object called AirCookiePersister
I want to encrypt the SQLite file on Android devices.
Code is found at:
worklight.js

The code you point to is only applicable for Adobe Air apps and not for Android & iOS. So, cookies won't be stored in worklight.db.

Related

Running html only if running in Electron.js [duplicate]

I'm trying to serve real react app on electron app. It doesn't mean I'm developing electron app with react. I've created a react app and injected it into electron app. (Like slack, it will serve as a web application and desktop application.) But I'm confused that send desktop notifications.
Now the main question is:
How can I get the application type. I mean, is user using my app on web or on desktop. How can I get this?
Thank you :)
There are many ways to detect whether you are running in a desktop environment or not.
You can check the User-Agent and you can set the userAgent value in Electron when you call loadURL.
Another way is declaring a global variable using a preload script.
// main process
new BrowserWindow({
webPreferences: {
preload: "preload.js",
},
});
// preload.js
// you don't need to use contextBridge if contextIsolation is false
// but it's true by default in Electron 12
const { contextBridge } = require("electron");
contextBridge.exposeInMainWorld("IN_DESKTOP_ENV", true);
// renderer process (your React world)
if (globalThis.IN_DESKTOP_ENV) {
// do something...
}

Export whatsapp messages to react-native app

I'm trying to access whatsapp messages from my device with react-native. Accessing them directly seems impossible so I was looking into the possibility of exporting the messages and importing them in my app. The options which are currently provided by whatsapp sharing menu lack any direct download option.
Is there a way to add my app to the whatsapp sharing menu? Or is there an easy way to import these messages?
You can use https://github.com/meedan/react-native-share-menu this library for exporting chat from Whatsapp. When you export chat file from WhatsApp, your app will show on the share dialog. After that, you can open that file from your app like below
ShareMenu.getSharedText((text :string) => {
if (text && text.length) {
if (text.startsWith('content://media/')) {
//this will be a media
} else {
content = this.readFile(text)
}
}
})
Then you can read the content of that file using RNFS library
readFile = async (path) => {
try {
const contents = await RNFS.readFile(path, "utf8");
return("" + contents);
} catch (e) {
alert("" + e);
}
};
After getting the content of the chat, you can parse that chats.
We had the same issue when building a Website to analyze WhatsApp chats, as with android you can not save the exported chat on the device.
Our solution was to use a PWA (Progressive Web App) and listen share Events.
When somebody now installs the PWA, they can share the export with the App directly. (Currently, this is only supported for Android with Chrome, as Apple is heavily against PWAs)
Our implementation:
if (workbox) {
workbox.addEventListener("message", (m) => {
// eslint-disable-next-line no-prototype-builtins
if (_this.$route.query.hasOwnProperty("receiving-file-share")) {
let files = m.data.file;
// currently only the first file, but ultimately we want to pass all files
_this.$refs.filehandler.processFileList(files, true);
}
});
workbox.messageSW("SHARE_READY");
}

React Native: How to open a Bitcoin URL?

How do you open a Bitcoin URL in a react native app? I am using React Native Linking to detect if there are any apps on the phone that can open a Bitcoin URL formatted according to BIP21. I have 3 apps installed that should handle it:
1) Coinbase
2) Breadwallet
3) Blockchain.info wallet
But it's not opening. Here's the code:
async _openWallet() {
const coinURL = 'bitcoin:15bMc6sQTiQ5jSqoRX3JzatAbQqJaffqup';
try {
const supported = await Linking.canOpenURL(coinURL);
if (supported) {
Linking.openURL(coinURL);
} else {
console.log('Could not find a compatible wallet on this device.');
}
} catch (error) {
console.log(error);
}
}
supported keeps returning false, which causes "Could not find a compatible wallet..." to execute. The weird thing is if I click on a Bitcoin URL on any random website via the Chrome / Safari browser, I get a popup that asks me if I want to open the URL in one of the above apps. So only URLs on websites are opening, but not URLs from inside react native code.
Any ideas?
Looks like every URI scheme you want to use at runtime must be defined up-front in Info.plist. Found the answer here: React Native: Linking API not discovering Uber app

Share json file to dropbox / one drive / google drive on an ios react-native app

I am writing an react-native ios application which generates text file. The file is stored at /var/mobile/Containers/Data/Application/76C594FD-282D-41B2-9BE6-B6B1C785BDE6/Documents/backup.json using react-native-fs.
I want to share this file to google drive/dropbox/microsoft one drive so I use the ActionSheetIOS.showShareActionSheetWithOptions API to share the file:
ActionSheetIOS.showShareActionSheetWithOptions({
url: '/var/mobile/Containers/Data/Application/76C594FD-282D-41B2-9BE6-B6B1C785BDE6/Documents/backup.json'
},
(error) => console.warn(error.message),
(success, method) => {
var text;
if (success) {
text = 'Shared';
} else {
text = 'Not shared';
}
console.warn(text)
})
but the share actions do not include either of google drive/onedrive/dropbox when I test on the device (screenshot available here).
Am I doing something wrong?
Looks like the device doesn't actually have google drive or dropbox installed. If those apps aren't installed, they won't be options for you to share to.

Get device Id from Mobile First

I added the above code in main.js inside the wlCommonInit function.
var options = {
onSuccess: succ,
onFailure: fail
};
WL.Device.getID(options);
function succ(data) {
alert('succ ' + JSON.stringify(data));
}
function fail() {
alert('fail');
}
But I am getting Uncaught TypeError: WL.Device.getID is not a function error in desktop web console.
Is it possible to add this code in other js files?
Please suggest!!
Per the documentation, this API method is not available in Desktop browsers. It is available only for mobile devices: http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.Device.html%23getID
Supported environments: Android, iOS, WindowsPhone8, Blackberry, Blackberry10.
Since you see it in Desktop web console, I take it you are trying out Desktop Browser environment/ Mobile Web app.
This API is not applicable in either case. It works only on Android, iOS, WindowsPhone8, Blackberry, Blackberry10. For more details refer to KnowledgeCenter.