Invoke native android activity in Titanium - titanium-mobile

For my Titanium applications, i am writing a custom native android module that includes an android jar consisting few android activities that i want to reuse.How can i invoke those activities from my application.

This comes straight from the Titanium Android Module Development Guide https://wiki.appcelerator.org/display/guides/Android+Module+Development+Guide
To use your module in a Titanium Mobile app, follow these steps:
Copy the module zip to the root of the Titanium app, or to the root of
the system Titanium installation In the application's tiapp.xml, add
the following XML inside :
<!-- $MODULE_VERSION should be the same as "version" in the module manifest -->
<modules>
<module version="$MODULE_VERSION">$MODULE_ID</module>
<!-- For example, if we were adding the calc module: -->
<module version="0.1">org.appcelerator.calc</module>
</modules>
Use the require function to load the module in the app's code,
Example:
var Module = require('$MODULE_ID');
// For example, to load the calc module:
var Calc = require('org.appcelerator.calc');
The next time the app is Launched or built, the module should be
included with the application

Related

NativeScript: use custom objective-c imported class into Xcode project in NativeScript

basically I have some Objective-c class already existing and I want to use them in my NativeScript projet. Currently I have added those files to the Xcode project target and I want to be able to call my objective-c code from nativeScript js. I've read the doc but I don't understand it. It seems so complicated. basically currently all I want to do is be able to present my custom view controller by calling probably something along
const vc = MyCustomViewController.alloc.initWithNibName("xib file")
page.frame.ios.controller.present(vc,true, nil)
Am I obligated to create a plugin for that? Am I obligated to use my objective-c class to build a framework in Xcode and then import the framework?
So I found out.
Actually what you need to do is first to compile your native iOS code into a framework. As per the documentation all your classes must inherit NSObject and all your function must be marked with #objc to be exposed to the objective-c Nativescript side if you write in swift. You will notice as well that in a framework your bundle is not the main bundle. In this example you can see how you can retrieve the bundle from the framework and load a xib from it.
Then you need to add your framework file to a Nativescript plugin. For that, you want to add the framework to the plugin's iOS folder yourPlugin/platform/iOS/yourFramework.framework.
then, you need to add your plugin to your app. You can add your local plugin by using the next command line. Notice the path end with the /src folder.
tns plugin add /path/to/yourplugin/src
Now, you can then call your native functions and classes without even importing them. Of course this works only on iOS. If you run your app on android, calling those methods will crash.
To show this viewController on your Nativescript side you will need to call the following code. By the way You can find documentation elsewhere to get a reference to the current page or frame object.
const controller = page.frame.ios.controller
const vc = IOMediaViewController.create()
vc.modalPresentationStyle = UIModalPresentationFullScreen
controller.presentViewControllerAnimatedCompletion(vc,true,null)

Xamarin Android Layout Resources in library project not included in Application

I have a Xamarin Android library project which is referenced by an Android application project.
The library project has layout files which need to be used by a library project component. The Resource.designer.cs file seems to be generated properly. The layouts are marked as Android Resources. Yet at runtime the resources are not there. Trying to access them just returns 0.
After reading all the SO questions on the topic, I am convinced this should work, but so far it doesn't. Ideas?
Create the Android Class Library.
Create a layout folder in this class library and create a layout in this folder.
Add the code in your xamarin android app.
var btn_Load = FindViewById<Button>(Resource.Id.btn_LoadLibraryLayout);
btn_Load.Click += delegate
{
SetContentView(ClassLibrary1.Resource.Layout.library_layout);
};
I create a button to open the layout in class library.
Result:
You could download from the ClassLibrary_layout folder of GitHub for reference.
https://github.com/WendyZang/Test.git
Updated:
If you want to get the resource identifier, you need the package name of this class library. First, we could not get the package name in AndroidManifest.xml file or properties, because the class library does not have it.
You could get it from the steps below.
Create a activity in class library. And get the package name with the code.
var PackageNname = Application.Context.PackageName;
You could also get the resource identifier in this activity.
var resId2 = Resources.GetIdentifier("library_layout", "layout", PackageNname);
Result:
The paskage name is same to the app1 I provided.
Package Name: com.companyname.app1
You could also use the code directly in app1 activity.
int resId2 = Resources.GetIdentifier("library_layout", "layout", "com.companyname.app1");

How to convert a mobile app project to a web app (code-sharing) structure in NativeScript?

The official documentation explains how to migrate an existing Angular Web project to a code-sharing structure.
But I could not find documentation on how to do the other way around. That is, how to migrate an existing NativeScript Mobile project to a code-sharing structure.
Any thoughts on how to convert an existing mobile app project to a web app project?
I have answered this before as well, here are the steps that I followed to do the same.
It is actually very time-saving to use same code base for both Web and mobile. Here are the steps I would suggest based on my experience.
You should be using #angular/cli#6.1.0 or newer. npm i -g #angular/cli
Installl nativescript-schematics. npm i -g #nativescript/schematics
Create a new Project. ng new --collection=#nativescript/schematics my-mobile-app (I did it in this way and then copied over src/app folder here from Mobile app).
Copy the app/src folder from existing project. (You may want to look for source folder in nsconfig.json "appPath": "app")
Find the .ts file where you are using mobile specific components and create a wrapper class for the same. E.g. I was using Fancy Alerts for mobile apps, so I created a wrapper helper class like helper.tns.ts and helper.ts
in helper.ts
public show() {
alert('Javascript+HTML alert') .
}
in helper.tns.ts
public show() {
TNSFancyAlert.showWarning('Warning!', 'Message', `Ok`, 0, 300).then(() => {
resolve('Success');
});
}
Rename all .html to .tns.html and create web specific html files.
Build a web app
ng serve
Build a Mobile app
tns run android --bundle
tns run ios --bundle
P.S. --bundle is the key here to compile mobile specific files only. The HTML code that defines the View of the component should be different between a web and a mobile app.

UWP console app with no icon, just execution alias

I have an Win32 application ported to UWP using desktop bridge.
The application has both GUI and command-line interface (separate executables).
I'd like to have an icon and execution alias for the GUI interface, but only execution alias for the command-line interface. I do not want to pollute the Start menu with an icon no one will ever use.
For that I've understood that the manifest needs to include two Application elements, one for the GUI and one for the command-line interface, as one Application can include only one AppExecutionAlias.
See also Create a Universal Windows Platform console app.
My idea was something like this:
<Applications>
<!-- GUI -->
<Application Id="MyApp" Executable="MyApp.exe" EntryPoint="Windows.FullTrustApplication">
<!-- with icon -->
<uap:VisualElements DisplayName="MyApp" Description="MyApp" ...>
...
</uap:VisualElements>
<!-- and execution alias -->
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias"
Executable="MyApp.exe" EntryPoint="Windows.FullTrustApplication">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
</Application>
<!-- Command-line interface -->
<Application Id="MyApp-commandline" Executable="MyApp-commandline.exe"
EntryPoint="Windows.FullTrustApplication">
<!-- with execution alias only -->
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias"
Executable="MyApp-commandline.exe" EntryPoint="Windows.FullTrustApplication">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp-commandline.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
</Application>
</Applications>
But I cannot find out how (if even possible) to have Application with no icon, as it seems that the VisualElements part is mandatory. So the above manifest is invalid. Of it there's some trick to an additional another execution alias (for a different binary) to the (first and only) Application.
Yes, the VisualElements part is mandatory as the file warned, we should follow the rules that the .Manifest file required. But if you don't want to have some Icons, you can try to provide a URI that doesn't refer a real image resource. Such as,
<uap:VisualElements
DisplayName="ConsoleUWP"
Square150x150Logo="Square150x150Logo.png"
Square44x44Logo="Image.png"
Description="ConsoleUWP"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Image.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
the Square44x44Logo, Square150x150Logo and Wide310x150Logo don't refer to correct URIs for images, but the uap:SplashScreen can not be configure a wrong URI, if you did that, it would get error.
---Update---
We can use the Applications element to specify one or more apps for the package, but every Application need the VisualElements part in the UWP .manefest file. So if you add another , you will need to add the Visual Elements as it required, your idea can not implement. Also note that although each package can contain one or more apps, packages that contain multiple apps won't pass the Store certification process, that is to say you can not publish to store.
On the other hand, you can try to create a package that includes both a Win32 and Universal Windows Platform (UWP) processes, and communicate between them via an AppService APIs. It use the FullTrustProcessLauncher extension but not another . You can try and see the sample:
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample

In which package can I find Xamarin IDevice

I am writing a Xamarin Forms PCL application (both iOS and Android)
I have to pick an image from phone gallery.
I have read some documentation about this plugin:
Labs.Platform.Services.Media.MediaPicker
In my Common project, i have to put this code:
var device = Resolver.Resolve<IDevice>();
picker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
But I have an error on the first line: IDevice and Resolver Objects are not know. I think I am missing a reference or a using clause.
Thanks
You need to install the following Nuget package in all of your projects in the solution (i.e. PCL core project, iOS project, and the Android Project, and UWP project if using it):
https://www.nuget.org/packages/XLabs.Forms/
And you will need to add the following using statements:
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

Resources