Android Wear onPeerConnected not called with new Wear Intents - wear-os

I have been using the following intent-filter in my manifest and everything worked fine:
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
This has been deprecated so I am trying to use:
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.CHANNEL_EVENT" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/mypath" />
I can receive messages fine but onPeerConnected never gets called now.
public class WearListenerService extends WearableListenerService {
#Override
public void onPeerConnected(Node peer) {
Log.d("Wear Service", "Peer Connected");
}
#Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d("Wear Service", "Message Received");
}
}
Everything works perfect if I switch back to using the old BIND_LISTENER instead.

onPeerConnected was deprecated at the same time as BIND_LISTENER, so when you stop using the latter, you need to stop using the former as well.
For comparable functionality, use the Cabability API: CAPABILITY_CHANGED in your manifest, and a CapabilityListener in your Java code. More details here: https://developer.android.com/training/wearables/data-layer/messages.html#SendMessage

Related

Xamarin Forms how to share page and open app from my current app with parameters? [duplicate]

Im trying to launch an app that I've created from another app that Im working on right now. The thing is I've been searching throught the internet and found something but it did not work so Im seeking help in here.
This is what I've done on the app I want to launch from :
On my xaml.cs :
public async void GoToDigDitApp(object sender, EventArgs e)
{
var appname = "digdit://";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appname);
}
I created an Interface:
public interface IAppHandler
{
Task<bool> LaunchApp(string uri);
}
In the Android project:
[assembly: Dependency(typeof(OpenAppAndroid))]
namespace SupervisingApp.Droid
{
[Activity(Label = "OpenAppAndroid")]
public class OpenAppAndroid : Activity, IAppHandler
{
public Task<bool> LaunchApp(string uri)
{
bool result = false;
try
{
var aUri = Android.Net.Uri.Parse(uri.ToString());
var intent = new Intent(Intent.ActionView, aUri);
Android.App.Application.Context.StartActivity(intent);
result = true;
}
catch (ActivityNotFoundException)
{
result = false;
}
return Task.FromResult(result);
}
}
}
And This is the app I want to launch manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.Tab2" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:label="Dig Dit" android:icon="#drawable/ic_launcher">
<activity android:icon="#drawable/ic_launcher" android:label="Dig Dit" android:name="digdit.urlentryclass">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="digdit" />
</intent-filter>
</activity>
</application>
</manifest>
For now Im only intressted by the Android part and it doesn't seem to work. I hope you guys can help me out.
You could use PackageManager.GetLaunchIntentForPackage.
Try the code below. com.companyname.app2 is the package name of App2.
Intent intent = PackageManager.GetLaunchIntentForPackage("com.companyname.app2");
StartActivity(intent);
Updated:
Create a interface:
public interface IDpendencyService
{
Task<bool> Launch(string stringUri);
}
Implemention of Android:
public class DependencyImplementation : Activity, IDpendencyService
{
public Task<bool> Launch(string stringUri)
{
Intent intent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(stringUri);
if (intent != null)
{
intent.AddFlags(ActivityFlags.NewTask);
Forms.Context.StartActivity(intent);
return Task.FromResult(true);
}
else
{
return Task.FromResult(true);
}
}
}
Usage of MainPage:
<StackLayout>
<!-- Place new controls here -->
<Label
FontAttributes="Bold"
FontSize="Large"
HorizontalOptions="Center"
Text="Welcome to App1!"
VerticalOptions="CenterAndExpand" />
<Button x:Name="GotoApp2" Text="GotoApp2" Clicked="GotoApp2_Clicked"></Button>
</StackLayout>
private void GotoApp2_Clicked(object sender, EventArgs e)
{
DependencyService.Get<IDpendencyService>().Launch("com.companyname.app2");
}
I have upload on GitHub, you could download from the StartAnotherApp_Xamarin.forms/App1 folder for reference.
https://github.com/WendyZang/Test.git
You can open you app from xamarin.forms
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Device.OpenUri(new Uri("digdit://555-1111"));
});

How to log every web api request in Insights with .NET 4.6.1

I have a .NET Framework 4.6.1 solution which has this global.asax.cs:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{ Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = EnvironmentHelper.InstrumentationKey;
HttpConfiguration config = GlobalConfiguration.Configuration;
GlobalConfiguration.Configure(WebApiConfig.Register);
}
protected void Application_Error(Object sender, EventArgs e)
{
_telemetry.TrackException(Server.GetLastError());
}
}
This WebApiConfig.cs:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Services.Add(typeof(IExceptionLogger), new InsightsExceptionLogger());
}
}
This logger class:
public class InsightsExceptionLogger : ExceptionLogger
{
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null)
{
var ai = new TelemetryClient();
ai.TrackException(context.Exception);
}
base.Log(context);
}
}
And this is an example of a controller and method:
public class SomeController : ApiController
{
[HttpPost, Route("api/v1/Something")]
public async Task<IHttpActionResult> Something()
{
The problem is I'm not getting any requests logged in Insights at all.
What do I need to do to get these API calls logged in Insights? (Assuming that simply adding .TrackRequest() is not necessary.)
Create a Request Telemetry initializer class and add the below code. On request Telemetry property you can select which property u want to add in a application insights.
After the Request Telemetry initializer class created add
<Add Type="webapptostoreloginappinsights.ReqTelemetryInitializer,webapptostoreloginappinsights"/>
in a applicationinsights.config file under telemetry processors
Make sure to call the request Telemetry initializer class in a global.asax.cs
Try to run the code now able to view the api request in a Application Insights
What I ended up doing was this....
Add packages:
<package id="Microsoft.ApplicationInsights" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Web" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.18.0" targetFramework="net472" />
<package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.8" targetFramework="net472" />
Ensure web.config <system.web> contains this:
<httpModules>
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
During the process the ApplicationInsights.config file was created and once deployed the application started logging Reuqest entries in Insights.

IBM: Add a workflow extension in TIM/SIM

I make my first workflow extension today, and the result isn't really good ! :)
I have this error :
CTGIMA411E The sendResult( workflow extension method in the com.orange.tiger.itim.extension.workflow.ResultCallback class cannot be processed.
And the trace.log file:
java.lang.ClassNotFoundException: com.orange.tiger.itim.extension.workflow.ResultCallback
Here this my java code :
package com.orange.tiger.itim.extension.workflow;
//my import
public class ResultCallback implements WorkflowApplication {
private WorkflowExecutionContext context;
private WorkflowProcessEntity processEntity;
public void setContext() {
this.context = null;
}
#Override
public void setContext(WorkflowExecutionContext context) {
//code
}
}
I modify the xml file:
<ACTIVITY ACTIVITYID="sendResult" LIMIT="600000">
<IMPLEMENTATION_TYPE>
<APPLICATION CLASS_NAME="com.orange.tiger.itim.extension.workflow.ResultCallback" METHOD_NAME="sendResult" />
</IMPLEMENTATION_TYPE>
<TRANSITION_RESTRICTION SPLIT="XOR" />
<PARAMETERS>
<IN_PARAMETERS PARAM_ID="summary" TYPE="String" />
<IN_PARAMETERS PARAM_ID="description" TYPE="String" />
</PARAMETERS>
<SCRIPT EVENT="onComplete">
<![CDATA[WorkflowRuntimeContext.setProcessResult(WorkflowRuntimeContext.getActivityResult());
WorkflowRuntimeContext.setProcessResultDetail(WorkflowRuntimeContext.getActivityResultDetail()); ]]>
</SCRIPT>
</ACTIVITY>
I add my jar in /opt/application/tgrtim/products/itim/lib/.
And finally I restart TIM via NDM console.
Maybe I missed something ? Or I did something wrong?
Thanks
I finally found, I forgot to modify a xml file :
/opt/websphere/7.0/profiles/Dmgr01/config/cells/udgis116Cell01/libraries.xml
And add this line : < classPath>${ITIM_HOME}/lib/result-callback.jar< /classPath>
You can also add result-callback.jar directly on Websphere under Environment -> Shared Libraries -> ITIM_LIB -> ${ITIM_HOME}/lib/result-callback.jar

Using both GCM push Notification service and Parse push notification service in android app

I am using GCM push notification service in my android app. Now, I have to Use both parse and GCM push notification in my android app. But, I am not getting notification from both GCM and Parse (may be due to conflict). I can reach both GCM and Parse individually but never together, My implementation looks this way;
I have registered Receivers for both GCM and Parse as fallows;
The following receiver is for GCM;
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.test" />
</intent-filter>
</receiver>
The receiver and service for Parse is as fallows;
<service android:name="com.parse.PushService"></service>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter android:priority="0">
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.test" />
</intent-filter>
</receiver>
I have called Parse Initialization in Application class as;
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, "APPLICATION_ID", "CLIENT_KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
I have implemented GCMIntentService for GCM as fallows;
public class GCMIntentService extends GCMBaseIntentService {
private static final String TAG = "GCMIntentService";
GCMManager gcmManager;
public GCMIntentService() {
super(Config.SENDER_ID);
}
/**
* Method called on device registered
*/
#Override
protected void onRegistered(Context context, String registrationId) {
gcmManager = new GCMManager(context);
Log.i(TAG, "Device registered: regId = " + registrationId);
displayMessage(context, "Your device registred with GCM");
ServerUtilities.register(context, registrationId);
gcmManager.saveGcmRegistrationId(registrationId);
}
/**
* Method called on device un registred
*/
#Override
protected void onUnregistered(Context context, String registrationId) {
Log.i(TAG, "Device unregistered");
displayMessage(context, getString(R.string.gcm_unregistered));
ServerUtilities.unregister(context, registrationId);
}
/**
* Method called on Receiving a new message
*/
#Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
// displayMessage(context, message);
try {
String message = intent.getExtras().getString(Constant.TAG_MESSAGE);
String id = intent.getExtras().getString(Constant.TAG_ID);
String title = intent.getExtras().getString(Constant.TAG_TITLE);
String type = intent.getExtras().getString(Constant.TAG_NOTIFICATION_TYPE);
Log.e("Message : ", message);
Log.e("Title : ", title);
Log.e("ID : ", id);
Log.e("Type : ", type);
// notifies user
generateNotification(context, message, title, id, type);
} catch (Exception e) {
}
}
}

The method setDefaultPushCallback(Context, Class<? extends Activity>) from the type PushService is deprecated

The whole problem i have been facing is with this line of code
PushService.setDefaultPushCallback(this, MainActivity.class);
on importing PushService the setDefaultPushCallback|() got deprecated. Why is this happening. I receiving the notifications but on tap app is being crashed. Also not receiving when the app isn't running.
I have found the solution and it is quite simple.
I found the same question
https://stackoverflow.com/a/26180181/3904085
"
After spending few hours. Found a solution: Implement your receiver and extends ParsePushBroadcastReceiver class.
Receiver.java
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, HomeActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Use it in manifest, (Instead of using ParsePushBroadcastReceiver)
Code for project's manifest:
<receiver
android:name="your.package.name.Receiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
"
Credits to #Ahmad Raza
From Parse documentation on onPushOpen():
Called when the push notification is opened by the user. Sends analytics info back to Parse that the application was opened from this push notification. By default, this will navigate to the Activity returned by ParsePushBroadcastReceiver.getActivity(Context, Intent). If the push contains a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by ParsePushBroadcastReceiver.getActivity(android.content.Context, android.content.Intent) in the back stack.
So if you override onPushOpen() like that, no analytics will be sent.
So here is my code:
public class Receiver extends ParsePushBroadcastReceiver {
#Override
protected Class<? extends Activity> getActivity(Context context, Intent intent) {
return HomeActivity.class;
}
}
You need to register the receiver like in the above post.
Tested with Parse 1.10.3

Resources