Pass data between android application and adobe air application - actionscript-3

I have two applications say app1 and app2. App1 is a native android application and App2 is an android application build with adobe air. Now i am able to launch App2 from the App1 using the following intent and also able to pass parameters through URL from App1 to App2
Intent i = Intent.parseUri("App2://arg1=value&secondArgument=someValue", Intent.URI_INTENT_SCHEME);
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.setComponent(null);
startActivity(i);
When the App2 is closed i want to send some data to App1 and go back to App1. So how can i do this in action script?
Could anyone suggest me a method to solve the problem?

You'll need to use startActivityForResult in app 1.
Intent i = Intent.parseUri("App2://arg1=value&secondArgument=someValue", Intent.URI_INTENT_SCHEME);
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.setComponent(null);
startActivityForResult(i, REQUEST_CODE);
Then in the activity in app 2 perform your operation and when complete set the result:
Intent intent = new Intent();
intent.putExtra( "key", value );
setResult(Activity.RESULT_OK, intent);
finish();
This will trigger the onActivityResult in your first app and you can process the intent there:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
id = data.getExtras().getString("key");
}
}
}
If your second app is an AIR application you will probably need an ANE to handle this, eg through a custom activity.

Related

How To Create Test Facebook Ads || How to Get Android Advertisement ID (AAID) programmatically?

How to create Test Device to Facebook Ads >> To Create Test Device you need Enter a device ID (IDFA, AAID):
sometimes we need to get the android advertisement id AAID for android device, when we place google ads or Facebook ads to our Android app or any other functions we need to place the unique AAID for testing purpose.
For Kotlin code
Thread{
AdvertisingIdClient.getAdvertisingIdInfo(activity).id?.let {
Log.i("myId",it)
}
}.start()
The first Step, get AdvertisingIdClient
public class AdvertisingIdClient extends Object
Helper library for retrieval of advertising ID and related information such as the limit ad tracking setting.
It is intended that the advertising ID completely replace existing usage of other identifiers for ads purposes (such as use of ANDROID_ID in Settings.Secure) when Google Play Services is available. Cases, where Google Play Services is unavailable, are indicated by a GooglePlayServicesNotAvailableException being thrown by getAdvertisingIdInfo().
Code >>>
#SuppressLint("StaticFieldLeak")
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String token = null;
AdvertisingIdClient.Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
} catch (IOException | GooglePlayServicesRepairableException | GooglePlayServicesNotAv
// ...
MessageLog.setLogCat("DEVICE_ID",""+e);
}
String android_id = adInfo.getId();
MessageLog.setLogCat("DEVICE_ID",android_id);
return android_id;
}
#Override
protected void onPostExecute(String token) {
MessageLog.setLogCat("DEVICE_ID","DEVICE_ID Access token retrieved:" + token);
}
};
task.execute();
Open Your Logcate of android studio
you will get Result like it
2020-07-23 19:32:37.225 19041-19093/com.packagename.example I/DEVICE_ID :: 1aaf7707-22b5-4627-xxx-xxxxxxxx
2020-07-23 19:32:37.738 19041-19041/com.packagename.example I/DEVICE_ID :: DEVICE_ID Access token retrieved:1aaf7707-22b5-4627-xxx-xxxxxxxx
1aaf7707-22b5-4627-xxx-xxxxxxxx is your device ID
Second Step: Open your Facebook Monetization Manager
write your device id in a device ID (IDFA, AAID): EditText and Write Name Device like the image.
The following code snippet might help lot of you in current cases.
Add this method in your code:
fun getIdThread() {
var adInfo: AdvertisingIdClient.Info? = null
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(this)
} catch (e: IOException) {
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (e: GooglePlayServicesAvailabilityException) {
// Encountered a recoverable error connecting to Google Play services.
} catch (e: GooglePlayServicesNotAvailableException) {
// Google Play services is not available entirely.
}
val id: String = adInfo?.id.orEmpty()
val isLAT: Boolean = adInfo?.isLimitAdTrackingEnabled?.orFalse() == true
}
And call from separate thread as like below.
Thread{
getIdThread()
}.start()
This simple snippet will give you the AD ID. Even if the user resets the advertising ID.
Note: [Don't forget to declare ad ID permission in your manifest]

Xamarin Forms: ModernHttpClient errorhandling in PCL

My app connects to an api which requires an HTTPS-connection.
ModernHttpClients (NativeMessageHandler) works fine until an exception is thrown...
When there is no wifi available, an UnknownHostException is thrown on Android. Is it possible to make a catch that works on both Android and iOS? UnknownHostException is in the Java.Net library which can't be used in the iOS project.
You can use Xam.Plugin.Connectivity NuGet Package to Check Network Connectivity In Xamarin.Forms using following code
if (CrossConnectivity.Current.IsConnected) {
// your logic...
} else {
// write your code if there is no Internet available
}
OR
Refer http://www.c-sharpcorner.com/blogs/how-to-check-network-connectivity-in-xamarinforms
You can use the ConnectivityPlugin in your shared Xamarin Forms code to check for an internet connection before doing your request.
Personally I'm using a cross platform interface to handle network errors. You can for instance have something like (using MvvmCross in this example):
try
{
var client = new HttpClient();
var result = await client.GetAsync("http://some-url.com");
}
catch (Exception e)
{
var platformErrorChecker = Mvx.Resolve<IPlatformNetworkError>();
if (platformErrorChecker.IsNetworkError(e))
{
// Handle network error
}
else
{
// Other exception, just throw
throw;
}
}
And a service defined as:
public interface IPlatformNetworkError
{
bool IsNetworkError(Exception e);
}
Which you implement on each platform specifically, or only where needed. This is a simple example of course, you can have each platform provide more information about their specific network errors.

Protocol between parse.com and mobile app

*What is the protocol between parse.com backend and mobile app when using Android/IOS SDK?
For example in the following code how parseobject is returned? Over http as json(Rest), via socket , rpc etc..?
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.fromLocalDatastore();
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
} else {
// something went wrong
}
}
});
*If it is not rest what is the pros of method over REST?
It does use the Parse REST API, which sends JSON data over HTTPS.
The client SDKs provide a nice, native, helpful experience. For the platforms we don't support first-party, the REST API is available directly.

How can I manually handle any subscribed to message type in NServiceBus?

I'm trying to build a layer over NServiceBus to make it simpler for other developers to use.
I'm trying to do without the config file and managed to get the publisher to work:
public class NServiceBusPublisher
{
private IBus _Bus { get; set; }
public void NServiceBusPublisher(string argInputQueue, string argErrorQueue)
{
Configure configure = NServiceBus.Configure.With().DefaultBuilder();
var transport = configure.Configurer.ConfigureComponent<MsmqTransport>(ComponentCallModelEnum.Singleton);
transport.ConfigureProperty(t => t.InputQueue, argInputQueue);
transport.ConfigureProperty(t => t.ErrorQueue, argErrorQueue);
transport.ConfigureProperty(t => t.NumberOfWorkerThreads, 1);
transport.ConfigureProperty(t => t.MaxRetries, 5);
_Bus =
configure
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.MsmqSubscriptionStorage()
.UnicastBus()
.ImpersonateSender(false)
.CreateBus()
.Start();
}
public void Publish(NServiceBus.IMessage argMessage)
{
_Bus.Publish(argMessage);
}
}
I also want to have an NServiceBus Subscriber and make it possible for developers to subscribe to any number of message types as long as the message inherits from NServiceBus.IMessage:
public class NServiceBusSubscriber
{
private IBus _Bus { get; set; }
public void NServiceBusSubscriber(string argInputQueue, string argOutputQueue, string argErrorQueue, string messagesAssembly)
{
Configure configure = NServiceBus.Configure.With().DefaultBuilder();
var transport = configure.Configurer.ConfigureComponent<MsmqTransport>(ComponentCallModelEnum.Singleton);
transport.ConfigureProperty(t => t.InputQueue, argInputQueue);
transport.ConfigureProperty(t => t.ErrorQueue, argErrorQueue);
transport.ConfigureProperty(t => t.NumberOfWorkerThreads, 1);
transport.ConfigureProperty(t => t.MaxRetries, 5);
var ucb = configure.Configurer.ConfigureComponent<NServiceBus.Unicast.UnicastBus>(ComponentCallModelEnum.Singleton);
ucb.ConfigureProperty(u => u.MessageOwners, new Dictionary<string,string>()
{
{messagesAssembly, argOutputQueue}
});
_Bus =
configure
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.MsmqSubscriptionStorage()
.UnicastBus()
.ImpersonateSender(false)
.DoNotAutoSubscribe()
.CreateBus()
.Start();
}
public void Subscribe<T>() where T : NServiceBus.IMessage
{
_Bus.Subscribe<T>();
}
}
The problem is that I couldn't find any way to attach an event handler to a particular message type.
Could you please help me figure this out?
Its been a while since the question has been asked, so I am not sure if the problem has been solved, but here's one way you can do it using Bus.Subscribe (although as has been said by other respondents this is not the prescribed way of doing it NServiceBus)
Subscribe the to the message type using the subscribe overload
void Subscribe(Type messageType, Predicate<IMessage> condition);
Then you can handle the message in the delegate
private bool Handle(NServiceBus.IMessage nsbMsg)
{
//you get the message instance that you can handle
//return true
}
So, your code would then be
class MySubscriber
{
public IBus Bus {get; set;}
public void Subscribe()
{
Bus.Subscribe(typeof(MyMessage), Handle);
}
public void Handle(NServiceBus.IMessage nsbMsg)
{
var msg = nsbMsg as MyMessage;
//your code
return true;
}
}
However please note that by doing this you have to manage the lifetime of the handler yourself, which otherwise would have been managed for you by NServiceBus using the IOC framework of your choice.
You will also have to pass the reference to IBus explicitly which would be injected for you automatically if you were just implementing the IHandleMessage interface.
An architectural point here is that NSB is a full fledged 'ESB', its not just a messaging layer. Adding another layer over your ESB is IMHO an abstraction too many.
I think you are missing the concept behind NServiceBus.
Based on the code you show I get the impression that you envision services that publish messages and others that process those messages. In my experience most processes do both: they subscribe to events or process incoming commands and in result publish new events and send new commands.
In your setup you would need to have publisher and subscriber instances for each of these message types.
NServiceBus is built for the situation I describe. You configure and start 1 bus instance and that orchestrates the complete application.
If you want to make it easier for developers to use NServiceBus I would concentrate on the configuration part only. In our company I have created a ServicebusConfigurator class that configures NServiceBus according our company standards and extracted that in a framework and a simple extension method for the .NET Core generic host. The only code our developers need to write to create a Windows Service that hosts an NServiceBus endpoint is something like this:
internal static class Program
{
private static int Main(string[] args)
{
return (int)Host.CreateDefaultBuilder(args) //.NET Core generic host
.WithNServiceBus() //configure NServiceBus according to our standards and start it.
.UseTopshelf<Worker>() // use Worker as the actual service doing the work.
.EnableNsbInstallersDuringInstall() // Execute any NServiceBus transport specific installation code during install of the service.
.Run(); // Run the thing.
}
}
Since you are not auto-subscribing the first thing you will need to do is subscribe to the message type via Bus.Subscribe(). Others could do this at the IWantToRunAtStartUp extension point(implement the interface in a class somewhere). From there, each subscriber will implement the IHandleMessages<T> interface. Implementing this interface wires you to a message where "T" is the message type.
When NSB starts up it will scan the local bin dir and find all your interface implementations and wire them up on your behalf internally. From there it will dispatch to the correct handler when a message of that type arrives.
NServiceBus automatically handles the subscription of messages. When you invoke Configure.With()....Start(); NServiceBus will scan to determine which assemblies implement IHandleMessages(SomeMessage) and it will send a subscription request to the publisher.
When you add "DoNotAutoSubscribe", you've got to manually get all messages being handled and do a Bus.Subscribe() for each of them.
Beyond that, NServiceBus will automatically handle the routing of an incoming message to the appropriate handler. In your subscriber code above, are you receiving an error message or are the messages disappearing from the queue?

NServiceBus without input queue

Is it possible to use NServiceBus in an application without having any input queues?
Reason is, I have an ASP.NET MVC application that sends messages to other applications when something happens (e.g. a new user registers). The web application never recieves any responses or other messages and therefore I would like not to bog the app. with the msmq peeking which throws an exception every second.
That is supported, just remove the msmstranport config section and all should be fine. This works against 2.0.1281.0 (net4) version of NServiceBus with no app.config present
using NServiceBus;
namespace SendOnlyEndpoint.Custom
{
public class Program
{
static void Main(string[] args)
{
var bus = Configure.With()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.UnicastBus()
.CreateBus()
.Start();
bus.Send("SendOnlyDestination",new TestMessage());
}
}
public class TestMessage : IMessage
{
}
}
More info on send only endpoints here
I would try not configuring an input queue. Bus.Send will use an internal outbound queue to send messages.