UWP - BackgroundTask and ContactManager - background

I am facing the problem that if I try to access the ContactManager from a BackgroundTask I get a System.IO.FileLoadException .
The same code works well when calling it from my main application:
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
test();
deferral.Complete();
}
private async void test()
{
ContactStore contactStore = await ContactManager.RequestStoreAsync();
}
The BackgroundTasks starts normally, but as soon as I call "test" the exception is thrown.

try to change your async void test to async Task test

Ok got it...
Reason was that I switched to VS2017 while developing and got a wrong dependency in the project.json of the backgroundtask:
While the main project had:
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
the background task got:
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
},
after editing to 5.0.0 all went perfect

Unfortunately I am now uninstalling VS2015 to install 2017 one so I can't test by my own but some of APIs are not available in Background Tasks so test the method I will mention :
1- Create a new Solution with type Class Library .
2- Put methods you want there .
3- Make the class library a reference for your background task solution .
3- Call your methods in this way classLib.className.FuncName();
4- See if it work or not.

Related

How to import node-java and use it correctly?

Now I am trying to call our APIs in our own Jar.
In VS Code extension example project, I tried to npm install java to install it in modules dir.
In my extension.ts it looks like below:
import * as vscode from "vscode";
import * as java from "java";
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log(
'Congratulations, your extension "test-ext" is now active!'
);
context.subscriptions.push(
vscode.commands.registerCommand("test-ext.callLocalJar", async () => {
console.log('test caller start.');
java.classpath.push("testapis.jar");
console.log('test caller start.');
}
)
);
}
// this method is called when your extension is deactivated
export function deactivate() {}
But now I got a failure in the very beginning when activating it...
error:
Activating extension 'boyka.test-ext' failed:
Cannot find module 'c:\Users\boyka\Workspaces\test-ext\build\Release\nodejavabridge_bindings.node'.
My package.json is like
"dependencies": {
"java": "^0.12.2"
}
I am not sure of the root cause, tried to research and add Java home to PATH but luck.
Anyone has this node-java usage experience that could help? Will appreciate that!
https://github.com/joeferner/node-java
Thanks
b.

Not able to add a custom command

I want to create a custom command in a typescript webdriverIO project. But no matter what I do, the command always ends up with the error :
TypeError: browser.waitAndClick is not a function.
Basically I wanted to add the same function they mentioned in webdriverIO doc. I am adding it from beforeAll() in my specs.
import { DEFAULT_TIMEOUT } from "../constants";
class CustomCommand {
private static alreadyAdded = false;
static addCommands(){
if(!this.alreadyAdded) {
browser.addCommand('waitAndClick', (el: WebdriverIO.Element) => {
el.waitForDisplayed({timeout: DEFAULT_TIMEOUT});
el.click();
}, true);
browser.addCommand('waitAndSetValue', (el: WebdriverIO.Element, text: string) => {
el.waitForDisplayed({timeout: DEFAULT_TIMEOUT});
el.setValue(text);
}, true);
this.alreadyAdded = true;
}
}
}
export default CustomCommand;
And I am calling this addCommands() function from beforeAll() of a spec. But no luck!
One nice person from slack channel helped me to find out the exact reason. Actually I overlooked something in doc : If you register a custom command to the browser scope, the command won’t be accessible for elements. Likewise, if you register a command to the element scope, it won’t be accessible in the browser scope. Turned out this is the reason. It is resolved now.
Passing false as third parameter in addCommand() fixed it.
Welcome to stack-overflow!
Please note that there is no 'beforeAll' hook in webdriverio as per the docs here.
It should work if you call this in before hook.
based on the webdriverio docs: https://webdriver.io/docs/api/browser/addCommand/
Note: don't forget to wrap inside before hook as ex bellow:
before: async function (capabilities, specs) {
browser.addCommand('waitAndClick', async function (selector) {
try {
await $(selector).waitForExist();
await $(selector).click();
} catch (error) {
throw new Error(`Could not click on selector: ${selector}`);
}
});
},

I'm trying to use react-call-detection to detect a missed call number but something is not working

Hey there to everyone!
I'm posting my first question so I'll try to be as clear as possible!
I'm building a native android app using react-native(0.61.5), I'm using setState hook instead of the classic state and I want to use the react-native-call-detection library(1.8.2).
What is the problem?
function startListenerTapped() {
console.log('start');
callDetector = new CallDetectorManager((event, number) => {
console.log(event);
console.log('inside call detector');
if (event === 'Missed') {
console.log(event);
console.log(number);
setMissedCaller(number);
}
},
true,
() => { console.error('access denied') },
{
title: 'Phone State Permission',
message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
}
)
}
I run this function when my component mounts, callDetector is set as undefined, I get the 'start' log but when I simulate a call on my AVD nothing happens.
From what I understood the CallDetectorManager works like an event listener, right?
Or do I need to start it every time a call happens?
Another thing I've had a problem with was when I was trying to run a build for the app. I have Gradle 6.0 and I had an error with the react-native-call-detection:
Attribute application#allowBackup value=(false) from AndroidManifest.xml:13:7-34
is also present at [:react-native-call-detection] AndroidManifest.xml:21:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at
AndroidManifest.xml:7:5-117 to override.
I couldn't really understand what this meant, and the only thing that I've found that solved it was to create a react-native.config.js file with this line of code in it:
module.exports = { dependencies: { 'react-native-call-detection': { platforms: { android: null, }, }, }, };
Another thing that I've only noticed now is that I have a problem with the module of the library.
Could not find a declaration file for module 'react-native-call-detection'.
'c:/folders/projectName/node_modules/react-native-call-detection/index.js' implicitly has an 'any' type.
Try `npm install #types/react-native-call-detection` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-call-detection';`
Does anybody knows what that means?!
I think I start to think that it means that I need to find an alternative to this library... AHAHA!
Any kind of help or solution would be more than welcome!
Thanks in advance for everything!

Change IntelliJ Run Configuration Environment Variables with Plugin

I am trying to build a plugin for IntelliJ that when pressing a button, it will load env vars from the web to the current Run Configuration.
I couldn't find a way to reach the current Run Configuration, let alone to edit the env vars.
When trying to create new Action all I get as a parameter is a AnActionEvent and I couldn't find anything useful there
public class HelloAction extends AnAction {
public HelloAction() {
super("Hello");
}
#Override
public void actionPerformed(AnActionEvent event) {
Project project = event.getProject();
}
}
I would be happy for any clue here
To get the current run configuration, use RunManager.getInstance(project).getSelectedConfiguration().getConfiguration(). Then check if the returned object implements CommonProgramRunConfigurationParameters, and if it does, call the setEnvs method of this interface to change the environment variables.

How to initilaze react-native on the view of window manager from android

I'm searching the way to implement running react-native application on both of activity and service in single package.
Running RN app on activity is usual, but can't find the right way to execute another react-native application on the service. The latter app should be run on the foreground service and view on the window manager.
My code roughly looks like:
// ReactNativeWindowService.kt
fun startNewReactWindow(
reactContext: ReactContext,
jsMainModuleName: String?,
bundleAssetName: String?,
module: String
) {
Toast.makeText(reactContext, "START()", Toast.LENGTH_SHORT).show()
val headLayout = createHeadLayout(reactContext)
headsManager.addLayout(headLayout)
launch(UI) {
reactInstanceManager = createReactInstanceManager(reactContext, jsMainModuleName, bundleAssetName)
reactRootView = ReactRootView(reactContext)
reactRootView?.startReactApplication(reactInstanceManager, module, null)
headsManager.addHeadView(bubbleLayout.apply { addView(reactRootView) })
}
}
But, this code produce:
07-10 01:05:07.662 26269-26380/Sample E/ReactNativeJS: Error while starting app: TypeError: undefined is not an object (evaluating 'NativeReactModule.startApp')
07-10 01:05:07.674 26269-26380/Sample I/ReactNativeJS: Running application "index" with appParams: {"rootTag":21}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
07-10 01:05:07.674 26269-26380/Sample E/ReactNativeJS: Application index has not been registered.
Hint: This error often happens when you're running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.
If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run 'npm start').
This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.
I'm sure that code passed right parameters such as jsMainModuleName to create ReactInstanceManager. (I got same parameters as activity's params)
What do I miss in my code? or any other reference/docs/advice that would be helpful to me. Thanks in advance. :)
You have to make sure that your file MainAcitivity.java has a function
protected String getMainComponentName() {
return "your file name for example abc";
}
But in your index.android.js file you register other component
AppRegistry.registerComponent('123', () => 143);
Where it must be like this e.g.
AppRegistry.registerComponent('abc', () => abc);
Try to fix it.