Ionic2 Native - Camera - Get real path from a given URI on Android - android

I'm following this tutorial:
http://devfanaticblog.com/working-with-camera-in-ionic-2-and-ionic-native/
I'm runing the application on an Android phone.
$ ionic run android
It works properly with only one exception:
Camera.DestinationType.FILE_URI
is returning somthing like:
content://com.android.providers.media.documents/document/image%3A1792
which is not working. I need the real path, for example:
/storage/sdcard/Downloads/ionic.png
These are some of the commands I ran to make the code work.
$ ionic plugin add cordova-plugin-camera
$ npm install --save #ionic-native/camera
Here is the source code of the plugin: github.com/apache/cordova-plugin-camera
There I can see there is already a function which does exactly what I need.
public static String getRealPath(Uri uri, CordovaInterface cordova) {...}
https://github.com/apache/cordova-plugin-camera/blob/master/src/android/FileHelper.java#L44
My question is:
How do I make use of that function on the file: home.ts in order to make the URI conversion?

Try using:
Camera.DestinationType.NATIVE_URI
This should return the native path for the image.

Related

Cordova GLOBAL is not defined when running on Android

I have setup a Cordova app with react following this tutorial.
When I try to run it on a physical android device using cordova run android -- --livereload The app is not compiled and not sent to the device, the only output I get is:
cordova run android -- --livereload
Successfully built!
GLOBAL is not defined
This is the verbose output of the command:
GLOBAL is not defined
ReferenceError: GLOBAL is not defined
at Object.isLiveReloadActivated (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/utils/helpers.js:94:5)
at Object.module.exports.isLiveReloadActive (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/index.js:21:17)
at module.exports (/Users/ivan/Desktop/MasterThesis/Test2/cordovaReact/plugins/cordova-plugin-livereload/lib/postEmulateRunHook.js:19:13)
at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:157:32)
at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:136:12)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:108:40
at processTicksAndRejections (internal/process/task_queues.js:95:5)
What is GLOBAL and how can I fix this error in order to get my app to compile and live reload?
Add this to your index.html file
<script>const global = globalThis;</script>

Ionic Capacitor - how to play ringtone/alarm on Android device?

I would like to know if there is a way to play Android device ringtone/alarm using Ionic Capacitor (not Cordova)?
If it is possible, please provide me with a simple solution (include required npm packages and code).
If not, please tell me how to do it with a simple typescript - I do not want to do it with a Cordova.
Also, I do not want to use Capacitor Local Notifications. I want ringtone sound only.
Thank you for any help :))
Did you check that link ? https://ionicframework.com/docs/native/native-ringtones
You can install it using Capacitor.
npm install cordova-plugin-native-ringtones
npm install #ionic-native/native-ringtones
ionic cap sync
Save some .caf file in your assets repository and do the following :
import { NativeRingtones } from '#ionic-native/native-ringtones/ngx';
constructor(private ringtones: NativeRingtones) { }
...
this.ringtones.getRingtone().then((ringtones) => { console.log(ringtones); });
this.ringtones.playRingtone('assets/ringtones/sound_1.caf');
this.ringtones.stopRingtone('assets/ringtones/sound_1.caf');

cannot use cordova plugin to open files under ionic 2 and typescript

I am developing an android app based on ionic 2 using typescript.
I would like o open a PDF file inside my app with another app that is registered for the fyletype (e.g. Acrobat Reader).
Therefore i tried the two standard plugins:
https://github.com/disusered/cordova-open
https://github.com/pwlin/cordova-plugin-file-opener2
Although ive added both plugins via "ionic plugin add ..." and of course played around with several combination referencing to it
the result is always that they ere not found
cordova-open
var open = cordova.plugins.disusered.open;
Property 'disusered' does not exist on type 'CordovaPlugins'.
cordova-plugin-file-opener2
cordova.plugins.fileOpener2.open(
filePath,
fileMIMEType,
{
error : function(){ },
success : function(){ }
}
);
Property 'fileOpener2' does not exist on type 'CordovaPlugins'.
I am running the app on an emulator via ionic run android
Could you please give some hint how i can achieve to use one of these plugins?
Thank you very much
Shane

Jenkins hanged when I try to build Unity project

I found Jenkins(windows) hanged when I try to build Unity project for android package.
I'm trying to use Jenkins with Unity plugin and windows bat to build project, after windows exe exported successful, android package exported failed.
The arguemnt when I use Unity plugin is
-batchmode -quit -projectPath "D:\Program Files (x86)\Jenkins\jobs\UnityJenkinsTest\workspace\QBAD" -executeMethod QBADBuildScript.Android -logFile "${WORKSPACE}/Build-Log.txt"
Meanwhile, I try using a windows bat to execute the same command from Jenkins, the result is the same.
"D:\Program Files\Unity\Editor\Unity.exe" -batchmode -quit -projectPath "D:\Program Files (x86)\Jenkins\jobs\UnityJenkinsTest\workspace\QBAD" -executeMethod QBADBuildScript.Android -logFile "${WORKSPACE}/Build-Log.txt"
When the building process went to the some part of build process, it hanged, and the build of jenkins never ended. I check with succeed log, it hanged before entering the part of Android.
(succeed log)
Used Assets, sorted by uncompressed size:
....
AndroidSDKTools: // This line and below never showed when hanging happened.
root : D:/Android/sdk
tools : D:/Android/sdk\tools
platform-tools: D:/Android/sdk\platform-tools
build-tools : D:\Android\sdk\build-tools\23.0.1
On the contrary, when I call the same script from command console of windows, it ended and succeed. I wonder what went wrong. Maybe I need set up environment variable for Jenkins.
The version of my Jenkins is 1.614, the version of my Unity is 5.0.1 .
Thanks
public static class AndroidSDKFolder
{
public static string Path
{
get { return EditorPrefs.GetString("AndroidSdkRoot"); }
set { EditorPrefs.SetString("AndroidSdkRoot", value); }
}
}
http://answers.unity3d.com/questions/495735/setting-android-sdk-path-in-environment-variable.html <-- This should help, setting the android sdk path stops the hang.

Unity command line arguments for android and iOS

Please pardon my ignorance, relatively new to working with Unity3D. I am working on automating Unity3d builds from the command line.
I am looking for command line arguments to build apk & xcode project.
Unity's documentation does mention arguments to build a standalone Mac OSX player (-buildOSXPlayer) and a standalone Windows player (-buildWindowsPlayer) but not for android and iOS.
Any help would be really appreciated. Thanks.
Start with Unity's own documentation for command line builds for iOS and android.
For example, put this script in your Assets/Editor folder:
// C# example
using UnityEditor;
class Autobuilder
{
[MenuItem ("File/AutoBuilder/iOS")]
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
string buildPath = "../../../Build/iOS";
// Create build folder if not yet exists
Directory.CreateDirectory(buildPath);
BuildPipeline.BuildPlayer(scenes, buildPath, BuildTarget.iOS, BuildOptions.Development);
}
}
You can actually run this script in the Unity application by going to File -> Autobuilder -> iOS
To run on command line, it looks something like this:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Autobuilder.PerformBuild -email me#email.com -password myPassword
Of course, you're going to want to check the debug log for any errors:
Mac OS X ~/Library/Logs/Unity/Editor.log
Windows XP C:\Documents and Settings\username\Local Settings\Application Data_\Unity\Editor\Editor.log
Windows Vista/7 C:\Users\username\AppData\Local\Unity\Editor\Editor.log
The -executeMethod command line parameter is a very simple option to invoke any function in any of your scripts - which you can then use to do pretty much anything, including firing off an Android build.

Categories

Resources