load external qml file on android - android

I am developing an app for android with QT/QML. To switch between screens I use this pageloader:
Rectangle {
id: mainApp
visible: true
width: 768
height: 1030
signal handlerLoader(string name, int index)
Loader {
id:pageLoader
source:"mainMenu.qml"
}
Connections {
target:pageLoader.item
onHandlerLoader:{pageLoader.source=name;
if(index===2)
window.source="NewWindow.qml";
}
}}
In a menu I have a button somewhere where another screen is loaded:
Button {
id: continueButton
width: 600
height: 150
text: "Continue with last template"
onClicked: handlerLoader("Template_water.qml",0)
}
This works, because Template_water.qml is in the qml.qrc file. But now I want to load in another file which is on the external storage on my android device: "/storage/emulated/0/Download/Template_water.qml". But it is not described in the qml.qrc file so it doesn't load. How can I solve this? (I want it to be able to add a qml file after deployment on the device.)

Try to provide scheme for your url like:
file:///storage/emulated/0/Download/Template_water.qml

Related

How to have display buckets like android in react native?

I am planning to build a react native app.The app gets targetted to 3 main things.
1ft => Mobiles(IOS,ANDROID),
2ft => Tablets,
10ft => Android TV.
How can we create files so that if I want to build for 1ft(Mobiles),the app should take only 1ft files like
eg; 1ft_android.js,1ft_ios.js
eg; 2ft_android.js ,2ft_ios.js
and in the same how can I build separately without using Platform.Select Or is there any chance to use flavours and is there any way to make this happen?
Edit 1: I have the folder structure as follows:
I want to find a way to let react know that if display metric matches
1ft, take landing.1ft.android.js. I don't want to compare display
metrics everytime. I'm looking for some configuration so react will
pick the respective file like it picks platform specific files.
For Platform specific UI you can Switch using Platform module.
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
height: Platform.OS === 'ios' ? 200 : 100,
});
But if you want to create responsive UI which will adjust its shape
and size with respect to screen you can use the following methods:
Flex: https://facebook.github.io/react-native/docs/height-and-width#flex-dimensions
Screen ratio:
var deviceWidth: Dimensions.get('window').width;
...
myImage { width: deviceWidth, height: deviceWidth * 0.5 }
And for font-size you can use this function:
export const getAdjustedFontSize = (size) => {
return parseInt(size) * metrics.screenWidth * (1.8 - 0.002 * metrics.screenWidth) / 400;
};
Edit:
You can refer to this link also: https://medium.com/react-native-training/build-responsive-react-native-views-for-any-device-and-support-orientation-change-1c8beba5bc23

Downloading data files with React Native for offline use

I am wanting to develop an app where a user can select different gamepacks to install on their android or ios device. A gamepack will consist of:
one or more JSON files
images
sounds
Right now I'm not really concerned if these are transferred individually or in a zip file (though a zip file would certainly be preferred). Of course the device will need to be connected to the Internet to get the current list of gamepacks and to download the ones that the user chooses. Once the gamepacks are downloaded to the phone the user will not need an Internet connection to play the game as they will have all the files.
How do I go about implementing this in my project?
How do I download the files? Would I use the react-native-fetch-blob library and save it in a specific location? This library refers to saving it as "cache" rather than permanently, so I am not sure if this is the correct solution. The specific section I am looking at on the library page is "Use Specific File Path". But because it is cache, should I be looking for something else that is more of a longer term storage? It does say on the page that files will not be deleted so I am a bit confused as to what the difference between permanent storage and cache is in this case.
Once the files are downloaded would I then be able to open images and display them, open sound files and play them, and open the json files and process them?
Check out React Native FS, specifically the documentation on downloadFile:
https://github.com/johanneslumpe/react-native-fs#downloadfileoptions-downloadfileoptions--jobid-number-promise-promisedownloadresult-
Here's a working example:
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
Image,
} from 'react-native';
import RNFS from 'react-native-fs';
export default class downloadFile extends Component {
constructor() {
super()
this.state = {
isDone: false,
};
this.onDownloadImagePress = this.onDownloadImagePress.bind(this);
}
onDownloadImagePress() {
RNFS.downloadFile({
fromUrl: 'https://facebook.github.io/react-native/img/header_logo.png',
toFile: `${RNFS.DocumentDirectoryPath}/react-native.png`,
}).promise.then((r) => {
this.setState({ isDone: true })
});
}
render() {
const preview = this.state.isDone ? (<View>
<Image style={{
width: 100,
height: 100,
backgroundColor: 'black',
}}
source={{
uri: `file://${RNFS.DocumentDirectoryPath}/react-native.png`,
scale: 1
}}
/>
<Text>{`file://${RNFS.DocumentDirectoryPath}/react-native.png`}</Text>
</View>
) : null;
return (
<View>
<Text onPress={this.onDownloadImagePress}>Download Image</Text>
{preview}
</View>
);
}
}
AppRegistry.registerComponent('downloadFile', () => downloadFile);
It's important to know that the height and width must be set on the Image

React Native Android - Static Resources not Showing

I'm just trying to load an image as a static resource. Here is an example that gives me a blank white screen.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
Image,
View
} = React;
var impowerz = React.createClass({
displayName : "Login",
render: function() {
return (
<View style={styles.container}>
<Image source={require('image!bg-splash')} style={styles.bg} />
</View>
);
}
});
var styles = StyleSheet.create({
bg : {
height: 667,
width: 375
},
container: {
flex: 1,
},
});
AppRegistry.registerComponent('impowerz', () => impowerz);
I checked in Chrome Debugger and this is what I got
[![Chrome Debugger sees my static resource][1]][1]
Edit I wrapped the image tag in a view and added a flex: 1 styles for the container
Update I tried to console.log() the assetsRoot property in react-native/packager/packager.js and it came back as /impowerz/assets/ which is where my image lives. I made a #2x and #3x as suggested [in this answer][2]
I tried using .jpg instead of .png images and tried replacing require('image!bg_splash') with {uri: 'assets/image/bg_splash.jpg'} (with and without the ext).
How did you add "bg-splash" to your android app? It should go under android/app/src/main/res/drawable (or drawable-hdpi, -xhdp etc if you have different version per DPI). Also take into account that android only accept resources names that contain lowercase letters and underscores, so your image name doesn't match that requirement as it contains dash sign.
in react-native v.0.14+
// same syntax for IOS and Android
require('./my-icon.png')
Full Image docs here
As of 0.14 release, React Native provides a unified way of managing images in your iOS and Android apps. To add a static image to your app, place it somewhere in your source code tree and reference it like this:
<Image source={require('./my-icon.png')} />
//relative path
.
├── button.js
└── img
├── check#2x.png
└── check#3x.png
I couldn't get my images to show up either.
When I went to <yourapp>/android/app/src/main/res, there were only mipmap-<qualifier> folders. I first put the images in those folders. Didn't work. My reading comprehension skills obviously need upgrading, because in the instructions, it clearly says "drawable." Then, I made the mistake of thinking that these "mipmap" folders needed to be changed to "drawable" folders (in the place of "mipmap"). So if anyone did that, backtrack, and instead, add the drawable-<qualifier> folders in addition to the "mipmap" ones. And then make sure to recompile the app.
To get the image to show on the screen, put the image in a view:
return (
<View
style={styles.container}>
<Image source={require('image!bg-splash')} style={styles.bg} />
</View>
);
And add these styles to the view
var styles = StyleSheet.create({
container: {
flex: 1,
},

File Input field sencha touch does not show phone memory browse option in android 4.1.2

I am using sencha touch to write a hybrid app for android. I have a screen wherein user can upload a file from their device. I am using sencha touch's filefield to open the file browser for user. Below is the code for the view
Ext.define('BikeApp.view.FileUploadView', {
extend: 'Ext.Container',
xtype: 'fileuploadview',
requires: [
'Ext.form.FieldSet',
'Ext.field.File'
],
config: {
title: 'Upload file',
items: [{
xtype: 'fieldset',
title: 'My Uploader',
items: [{
xtype: 'filefield',
itemId: 'fileField',
label: "Select file:"
//name: 'photo',
//accept: 'image'
}, {
xtype: 'button',
text: 'Submit',
itemId: 'uploadSubmit',
margin: '1em 0 0 0'
}]
}]
}
});
The issue i am facing is that on one of the android devices (Samsung Galaxy Chat) which runs on android 4.1.2 the options shown to user when he taps on browse do not include an option where user can browse his phone memory or sd card (whatever is available) and select a file. The only options shown are Music files, Gallery and Music Player. I have attached a screenshot below showing these options. I have a file stored in phone's internal memory and i cannot browse that path and select it from these options.
What's interesting is that this thing works correctly on android 5.0 and i get all the options. Any help ?

Application restart after taking picture with camera(Titanium android)

I am developing android application, In my application I want to take photo from camera and set as image in image view. my code looks like
var img_view = Titanium.UI.createImageView({
image: '/images/default.png',
height: '100%',
width: '100%',
}); win.add(img_view);
photo_camera_view = Ti.UI.createView(
{
height: '20dp',
backgroundColor:'#fff'
}); win.add(photo_camera_view);
photo_camera_view.addEventListener('click', function(e)
{
Titanium.Media.showCamera(
{
success:function(event)
{
img_view.image = event.media;
},
cancel:function()
{
},
error:function(error)
{
// create alert
},
});
});
my need is take a pic from camera and set image: 'photo from camera' in img_view. In Android, when I execute Ti.Media.showCamera, after successfully taking a picture and hitting "OK" in the app, the application will restart. I am using titanium sdk 2.0.1 and testing it on android device with android version 2.2. Need Help ..... Thank you........
You need to set the image in the success event like below.
img_view.setImage(event.media);
You just cannot assign the image to the property. The image view has to be redrawn with new image. And try it in Android 4.0 emulator as the below versions had issues with camera.

Categories

Resources