HTTP request inside override GrabBegin not calling - oculusquest

I override GrabBegin function and try to make a Post request whenever user grab an object. But it looks like the Request was never called. No error or warning issue from the condole. I also tried to print to console by using Debug.Log("Grab Begin") but it was never printed to the console. I am not sure what I am missing. I was still able to grab an object through the VR
public class AromaShooterGrabbable : OVRGrabbable
{
override public void GrabBegin(OVRGrabber hand, Collider grabPoint) {
base.GrabBegin(hand, grabPoint);
RestClient.Post<AromaShooterResponse>(url, new Post {
duration = 3000,
channel = 1,
intensity = 100
}).Then(response => {
Debug.Log(response.status);
}).Catch(error => {
Debug.Log(error.Message);
});
}
}

Answering my own question.
In AndroidManifest.OVRSubmission.xml add:
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:networkSecurityConfig="#network_sec_config"
>
</manifest>
In network_sec_config.xml add:
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">*</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true"></base-config>

Related

How to wire up an Share intent in MAUI for Android?

I'm trying to work out how to wire up a Share intent in Android using MAUI.
Am I running into preview bugs, or am I not doing it correctly?
I'm running MAUI Preview 10, with Visual Studio 17.1.0 Preview 1.0.
Version 1
I've added the share intent to the AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true">
<activity android:name="SomeLongName.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
And then by adding a Name property to the MainActivity class:
[Activity(Name = "SomeLongName.MainActivity", Theme = "#style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if (Intent.Type == "text/plain")
{
}
}
}
When I debug the application in MAUI, the app builds correctly and the Output says that the app has deployed. However, in Visual Studio, the debugger fails to run, and there is no evidence of the app on the emulator.
Version 2
In version 2, I've tried to create a separate activity for the Share intent:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true">
<activity android:name="SomeLongName.ShareActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
[Activity(Name = "SomeLongName.ShareActivity")]
public class ShareActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
if (Intent.Type == "text/plain" && Intent.Action == "android.intent.action.SEND")
{
//handleSendUrl();
}
base.OnCreate(savedInstanceState);
}
I can now successfully debug the application, but when I try to share to the application, I get an exception on the base.OnCreate call:
Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'
Seems the issue centres around themes. The solution is in the original question, apply Version 2. With some minor updates. In the MainApplication class add an attribute defining the theme (same as in MainActivity class but could be different).
[Application(Theme = "#style/Maui.SplashTheme")]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
This both works without error and enables debugging.
Without the MainApplication theme setting, when sharing to the android app (incoming), an error thrown:
Java.Lang.IllegalArgumentException: 'The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).'
In my secondary activity, the Activity attribute sets the Theme, but is ignored and error still shown, hence the Application level needed. Not sure why.
[Activity(Theme = "#android:style/Theme.MaterialComponents.Light", Name = "com.somename.receiveurlactivity", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class ReceiveUrlActivity : MauiAppCompatActivity
{
//.... etc

Creating a admin controller using adminhtml id

I'm trying to add a controller accessible on admin menu through url:
https://dev.m2t2.com/admin_k1tgag/admin/helloWorld/index/key/0195fab99cc865bb756a77e8fe5ceedb6f8eee97de91d569398d383cef4f0d81/
Generated by the XML code inserted below. But it keeps returning
Invalid security or form key. Please refresh the page.
Router.xml :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="adminhtml">
<module name="Study_Admin" before="Magento_Backend"/>
</route>
</router>
</config>
In menu i inserted:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Study_Admin::greetings" title="Greetings" translate="title" module="Study_Admin" parent="Magento_Backend::content" sortOrder="50" dependsOnModule="Study_Admin" resource="Study_Admin::greetings"/>
<add id="Study_Admin::greetings_helloworld" title="Hello World" translate="title" module="Study_Admin" parent="Study_Admin::greetings" sortOrder="10" dependsOnModule="Study_Admin" action="adminhtml/helloWorld" resource="Study_Admin::greetings"/>
</menu>
</config>
But when i access the controller through the menu i have no success. I started debugging and i checked that non-custom controllers extends \Magento\Backend\App\Action class to pass validations inside magento routing core flow. I did the same but i still have no success.
Below my controller class:
<?php
namespace Study\Controller\Adminhtml\HelloWorld;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\App\Action\Context;
use ‌Magento\Framework\App\ActionInterface;
class Index extends \Magento\Backend\App\Action
{
const MENU_Id = "Study_Admin::greetings_helloworld";
protected $resultPageFActory;
public function __construct(Context $context, PageFactory $resultPageFActory)
{
parent::__construct($context);
$this->resultPageFActory = $resultPageFActory;
}
public function execute()
{
$resultPage = $this->resultPageFActory->create();
$resultPage->setActiveMenu(static::MENU_Id);
$resultPage->getConfig()->getTitle()->prepend(__('Hello World'));
return $resultPage;
// TODO: Implement execute() method.
}
}
The file structure is :
Thanx in advance, and take care.
It works... was just my namespace in Controller's class that had an error
'namespace Study\Admin\Controller\Adminhtml\Helloworld;'

Calling my azure bot service using websocket fails

I have an Azure bot service which runs perfectly when tested on webchat.
Now I tried to open a websocket and test the bot.
I first send a POST request (with all required headers) to https://directline.botframework.com/v3/directline/conversations
I get a response with
{
"conversationId": "7FY18sO6FCT9OVi0pW7WBY",
"token": "my_token_here",
"expires_in": 1800,
"streamUrl":
"wss://directline.botframework.com/v3/directline/conversations/7FY18sO6FCT9OVi0pW7WBY/stream?watermark=-&t=token_value_here",
"referenceGrammarId": "c1c290dd-f896-5857-b328-cdc10298e440"
}
Now I try to use the streamUrl to send/receive data using web socket.
I got an error: Undefined
I tried to test the streamUrl on different online websocket testing tool. I still got the undefined error.
How can I test whether there is a problem in the streamUrl?
How can I test the web socket?
Firstly, as Eric Dahlvang mentioned, it enables us to receive activities via WebSocket stream, but not send activities.
Besides, I do a test with the following steps and sample, the activities can be received as expected via WebSocket stream, you can refer to it.
Step1: make a request to start a conversation
Step2: start client app (a console application) to wait for receiving acitivities
class Program
{
private static string botId = "fehanbasicbot";
static void Main(string[] args)
{
var url = Console.ReadLine();
StartReceivingActivities(url).Wait();
Console.ReadLine();
}
private static async Task StartReceivingActivities(string url)
{
var webSocketClient = new WebSocket(url);
webSocketClient.OnMessage += WebSocketClient_OnMessage;
webSocketClient.Connect();
}
private static void WebSocketClient_OnMessage(object sender, MessageEventArgs e)
{
// Occasionally, the Direct Line service sends an empty message as a liveness ping. Ignore these messages.
if (string.IsNullOrWhiteSpace(e.Data))
{
return;
}
var activitySet = JsonConvert.DeserializeObject<ActivitySet>(e.Data);
var activities = from x in activitySet.Activities
where x.From.Id == botId
select x;
foreach (Activity activity in activities)
{
Console.WriteLine(activity.Text);
}
}
}
packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bot.Connector.DirectLine" version="3.0.2" targetFramework="net461" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net461" />
<package id="WebSocketSharp" version="1.0.3-rc11" targetFramework="net461" />
</packages>
Step3: make a request to send an activity to the bot
Step4: check the console app output, I can find the activities are received

how to delete a scenario in atg through API methods

I have created a scenario by creating a myScenario.sdl in my local config folder /atg/registry/data/scenarios/myScenario.sdl
myScenario.sdl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE process SYSTEM "dynamosystemresource:/atg/dtds/pdl/pdl_1.0.dtd">
<process author="admin" creation-time="1413804041263" enabled="false" last-modified-by="admin" modification-time="1413804191188">
<segment migrate-subjects="true">
<segment-name>ItemAddedToOrder</segment-name>
<!--================================-->
<!--== Item added to order Quantity with fraction is defined -->
<!--================================-->
<event id="1">
<event-name>atg.commerce.order.ItemAddedToOrder</event-name>
<filter construct="event-property-filter" operator="isNotNull">
<event-property construct="event-property">
<property-name>quantityWithFraction</property-name>
</event-property>
</filter>
</event>
<!--================================-->
<!--== Log a message message: Quantity With Fraction is Defines logTriggeringEvent: true -->
<!--================================-->
<action id="2">
<action-name>Log a message</action-name>
<action-param name="message">
<constant>Quantity With Fraction is Defines</constant>
</action-param>
<action-param name="logTriggeringEvent">
<constant type="java.lang.Boolean">true</constant>
</action-param>
</action>
</segment>
</process>
And enabled the scenario:
Registry scenarioRegistry = scenarioManager.getScenarioRegistry();
byte[] data = (byte[]) scenarioRegistry.getItem(pScenarioPath);
String xml = null;
if (data != null) {
xml = new String(data, "UTF-8");
} else {
Assert.fail("No scenario is existed to enable/disable");
}
String updatedXml;
if (scenarioState && xml != null) {
updatedXml = xml.replaceAll("enabled=\"false\"", "enabled=\"true\"");
} else {
updatedXml = xml.replaceAll("enabled=\"true\"", "enabled=\"false\"");
}
scenarioRegistry.putItem(pScenarioPath, updatedXml.getBytes("UTF-8"));
Now with this above written code, I can both disable or enable the scenario by changing the state as false and true respectively. But I want to delete the scenario(please remember, my requirement is DELETE not DISABLE SCENARIO). I know using scenarioManager.updateScenario() deleted the scenario. Is my understanding right?
One more thing, I know I can delete the scenario directly from ACC. But I need to code via code not manually from ACC.
Please share your thoughts!
Did you try scenarioRegistry.removeItem(path);

Magento getEvent()->getOrder empty

I'm trying to get an Observer working to see if a payment has been made via check/cheque, I know the Observer is being used as I have a log record to show. However when I try to access the Order it is either empty or will not print to the log file.
app/etc/modules/Foo_Bar.xml
<?xml version="1.0"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
<events>
<sales_order_payment_place_end> <!-- event -->
<observers>
<foo_bar> <!-- unique for event -->
<!-- type: singleton | disable | model -->
<class>foo_bar/observer</class>
<method>SalesOrderPaymentPlaceEnd</method>
</foo_bar>
</observers>
</sales_order_payment_place_end>
</events>
</global>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer
{
public function SalesOrderPaymentPlaceEnd(Varien_Event_Observer $observer)
{
Mage::log('Location: SalesOrderPaymentPlaceEnd');
$order = $observer->getEvent()->getOrder();
Mage::log('order: '.$order);
}
}
The first log works as expected, however I'm sure getOrder() isn't working as my second log entry just prints 'order: '.
Thanks
#James has already commented this..I am explaning
The event "sales_order_payment_place_end" located in "app\code\core\Mage\Sales\Model\Order\Payment.php" .
The event have only one parameter that is Payment. So
$order = $observer->getEvent()->getOrder();
will not work. You need to use
$orderPayment = $observer->getEvent()->getPayment();
What worked for me was below:
public function autoInvoiceForOfflinePayment(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getPayment()->getOrder();
// In my case I was trying to get the payment method code, e.g.
$order->getPayment()->getMethodInstance()->getCode()
}
I hope this helps (Magento EE 1.14.2)
What I discovered, which I forget and often discover again when creating a hook is to look at the line in the file dispatching the event:
e.g. "app\code\core\Mage\Sales\Model\Order\Payment.php"
Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
So you want to get the event first, then in the array the payment variable:
$order = $observer->getEvent()->getPayment();
From there you can get any public functions in that file, the same principle seems to apply throughout.