React Native - Open the device default gallery app - android

I'm developing a camera for a React Native app, and it needs to include a button to open the device gallery app (gallery for android, camera roll for iOS). All photos are stored in a specific album, so it would be better to open the app in that album, if possible, but it's not mandatory. It's worth noting that I don't want to create a custom in-app gallery. That would actually be easier, but it's not what the client asked for.
It seems to be a pretty simple task, but I haven't found a way to do this yet. Some people suggested using linking, like this:
Linking.openURL('content://media/internal/images/media');
This makes the OS ask the user what app should be used to open that link. If I select Google Photos, it works fine. However, if I use the default android gallery, it opens a photo that doesn't exist, showing a placeholder image. So this method doesn't work reliably.
According to android docs, it should be possible to open the gallery app by using an intent. But I tried doing both:
Linking.sendIntent('CATEGORY_APP_GALLERY');
Linking.sendIntent('android.intent.category.APP_GALLERY');
and it didn't work. Either I'm doing something wrong, or sendIntent doesn't work at all.
There's also a plugin called "react-native-send-intent", but it doesn't include a function to open the gallery. I'm running out of ideas, any help would be appreaciated.

I had the same issue in my personal project.
According to the doc, CATEGORY_APP_GALLERY is just specifying app categories and must be used with the ACTION_MAIN action.
As far as I understand, we cannot pass a category via React Native built-in Linking.sendIntent() method, unfortunately. We must rely on third-party libraries on that part.
I picked up expo-intent-launcher (If you are not using expo, still you can use it by following bare workflow as it's described in the doc).
Here is a working snippet example with expo-intent-launcher:
import * as IntentLauncher from 'expo-intent-launcher';
IntentLauncher.startActivityAsync('android.intent.action.MAIN', {
category: 'android.intent.category.APP_GALLERY',
})

Related

Open local video on Android device, from a QR code

Background
Some teams in my company's facilities are using Android tablets for multiple operations. We would like to allow them to access video demos from their tablets, when they are at specific places in the facility, without having to search through the tablet for the right video. So we thought of QR codes (printed on paper, stuck to the wall). Problem is: for security reasons, we can't allow the devices to access any network.
Question
So the idea is to store the videos locally, and have the QR code route to the local file. I thought this would be easy but it doesn't appear to be.
I have generated QR codes like file:///path/to/my/file.mp4, also trying to play with intents, like this:
file:///path/to/my/file.mp4#Intent;scheme=file;action=android.intent.action.VIEW;type=video/mp4;end.
(+ variants including intent://, using scheme=file, targeting images instead of videos...)
In the best cases, the browser opens, closes, and I receive "Cannot display file. Invalid PDF", and in the worst cases, "Sorry, the application could not be launched. The bar code content may be invalid.".
I also tried variants (images instead of videos, URL vs plain text QR codes, several code scanner applications), all with the same result. I have searched through SO, but most questions are about doing this programmatically in an application, while I would like to avoid designing an app just for this.
What am I doing wrong? Is there no way to do this that way?
Note: I had absolutely no knowledge about Android and intents before trying to solve this case, there may be smarter workarounds. Any hint is appreciated.
Given the network requirement within your company, it seems building a simple application is the easiest solution(maybe because I am an app developer).
So your app would need only 2 screens. QR code Scanner and a View that shows the video.(once you click done, go back to scanning)
The app can have all the videos you need prebuilt in the app itself and the QR codes can be the names of those videos.
Okay, I don't know if you are using web page or any android app for this fature, for web page you need to create your own scanner or integrate ready made solution i found 1 here, you will need setTimeinterval so it scans bar code once, Once barcode is found you will need to call your ajax method to fetch complete URL of that video, once any item is returned, you need to display it in iframe.
Hope it works for you.

Is it possible to open native android clock app from web application?

I am looking for a way to open the native android alarm clock app when a user clicks on the link or button on a web browser of the android. So basically need to open the native android app from web application. I tried using intent://#Intent;package=com.android.deskclock;end' and it is not working. I am wondering if I am using the wrong package name or it is not even possible in android.
Thank you much for help!
According to this documentation, this is not possible. In particular, this footnote is the limiting factor:
Only activities that have the category filter, android.intent.category.BROWSABLE are able to be invoked using this method as it indicates that the application is safe to open from the Browser.
If you look at the AndroidManifest.xml for the DeskClock app, none of the activities contain the android.intent.category.BROWSABLE category filter, meaning none of them can be opened from the browser.
I have a suspicion that the problem is that you are not providing a URI path in your URL. It might need to be a path declared in the app's manifest. See: https://developer.chrome.com/multidevice/android/intents
This could change it to ie intent://path/#Intent;package=com.android.deskclock;end'
It might be helpful if you were to look at the javascript console when you try to click on that link in Chrome, there might be details of what went wrong.
Keep in mind that the alarm clock app is not necessarily consistent. Manufacturers can remove the default alarm clock app to replace it with a different one, or just modify the source code so that it has the same package name but different source code. You could try opening multiple package names from javascript depending on what happens when the intent can't be opened.
Welcome to code party
You can get a android device IFrame from appetize site.
This is the easiest way for show android apps in web applications.
Update me in comments ;)

React Native (or alternative) that supports native "share via" feature

I need to create a wrapper app. Basically it is just a webview pointed to our online hosted react app. It must build to both iOS and Android. Therefore I have considered using plain react native.
Most important feature is that the app must be registered on the device as an app that can handle links when using the native "share" feature.
Example; if I do a google search in chrome/safari/whatever I am able to press-hold any of the links (search results) I can then click "share" this will normally open a menu with lets say share to; "drive", "gmail", "messenger", "sms".... etc. I want our wrapper app to show up in the menu and be able to handle the link.
I have tried to search for libraries/frameworks that makes this possible. But all search result I am getting seems to be explanation on how to do the opposite thing, opening the native share menu from within the app.
I have been looking at expo, but can't figure out if they support this feature, otherwise I would consider create-react-native-app which is react-native based, but I am also not able to find direct documentation on how to implement such feature.
Further more, I know that there is a unity plugin that will do this, and that I could combine it with a uniWebView which would handle the wrapper app part.
How can I achieve a native share to feature on a simple wrapper app that builds to both iOS and Android?
You won't be able to do that in react native on Android because its not part of the native code. Its part of the manifest. You need to follow the instructions at https://developer.android.com/training/sharing/receive and set up an intent filter in your manifest telling the OS your app handles the correct mime type, and what activity to send it to. That activity would then have to handle the incoming data, either directly or by sending it to react native (which is going to be at least a mild pain, RN is ok when you want it to display a isolated view or want it to call a native module, calling RN code isn't very easy). This doesn't mean your app can't use react native, but that you'll need to modify the default manifest it creates.
If that's a major usecase of your app and your app is 90% just displaying your webpage, you may have an easier time of things not using react native and just displaying a web view. (I'll leave my bias of RN just being a horrible solution for everything at the door here).

Easiest way to launch webpage in android with an icon

We have a website that offers an e-mail service. We would like to create a fully fledged app for this but cannot afford this right now. In the mean time it would be great if we could give users an icon on their phones that will take them to a page formatted for mobile on the internet. So what I'd like to know is how can we get an icon on an android users phone that will simply launch a web link in a browser- does this have to be an app, is there an easier way, or am I over estimating how complicated it would be to make this as an app anyway?
Thanks in advance
Create a new Android project (after following the SDK installation steps provided at http://developer.android.com)
on the directory /res/drawable-*dpi you have the laucher icons. Modify all of them.
In the main activity, delete all inside the onCreate method an put this:
String url = "http://www.YOUR-URL.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
This will open the android browser with the URL provided.
I have done projects like this in the past, it is very simple. You need to create a website formatted for a smaller screen. Once you do this, building an android app that displays your website inside it is simple. You can even remove all of the android browser toolbars so it appears as if your website is a real android application. Google android webviews, this will point you in the right direction.
See here for what's probably the best instruction page on how to do exactly that:
http://intelnav.50webs.com/app_project.html
It's based on a Webview, that is it opens the page and does all the navigation in the app window, not in the default browser. So if you want to open it in the browser, you have to use Intent, as said in previous answers.
My 2 pennies worth, I think it's better in the app window unless you really want complex navigation with the possibility of opening additional tabs, windows and so on. The drawback with the external browser is that, as far as I could see, there's no way to tell if the page is already open in the browser so you'll launch a different copy (in a new tab) every time. If the user doesn't close the tab at the end, they usually don't, it can become quite annoying. Besides, within an app you'll probably have somewhat better possibilities for ads should you ever want them.
Versus a simple home-screen bookmark, as others pointed out, it's simpler and more convenient for end users to just download an app from an online store (usually Google Play). It's what they're used to do. And they do have a lot of additional info available, like what it does, what others say about it, screen shots (if you provide some for them but you should). Plus a way to comment / complain themselves. It's a different thing. Technically it may not make a lot of sense but from a simple user's perspective it's clearly better IMO.
One way is to bookmark the site and then add it to your home screen. Source
It seems to me like you need a mobile version of your web page. Do you have that already? Once you have your mobile website (ie. website optimized for mobile devices), you could create a simple application with only one WebView. All content would be fetched from your site and displayed inside a webview. This is trivial to make, however, making an entire mobile website will take some time.
Note that you do not HAVE TO have a mobile website, you could pack you existing website into a WebView, but this would lower user experience.
you would build an app that launches a browser intent linking to your website, or a custom WebView to launch your website in full screen without any navigation bar etc..
The only easier way is to put instructions on your site (directly, or as a contextual pop-up) on how to add the bookmark as an icon on your home screen. This can be slightly more complicated on Android, and depends on the browser. A simpler option for your potential users is to provide a wrapper app via the Marketplace.
It is not overly complicated to create a simple wrapper Android app in Java that launches the browser, using Intents. The essential browser launch code is basically this:
Uri uriUrl = Uri.parse("http://www.yourwebpage.com");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
A more detailed tutorial for creating this is available here:
http://mobile.tutsplus.com/tutorials/android/launch-android-browser/
Try this kick-start mobile device app for showing websites. Written with cordova for platforms like android, ios, browser and so on: https://github.com/jetedonner/ch.kimhauser.cordova.kickstartwebsite (GooglePlay: https://play.google.com/store/apps/details?id=ch.kimhauser.cordova.kickstartwebsite, Website: http://kimhauser.ch/index.php/projects/cordova-phonegap/kick-start-website)

Is there Android Intent concept in iPhone SDK

Just switching from Android to iPhone. In Android I can make several apps and use a tabView to call each app as intent.
In iPhone, I can make several apps. I need a tab to call each apps or app views. Is there similar concept as intent in iPhone? Just switched to iPhone, copying all the other projects into the tabbar does not work out. If you have other methods to solve, I really appreciate. Thanks,
Android and iOS are very different in this regard. Android is very open about letting you use intents to mix and match activities from other apps. iOS isn't like that; each app runs in its own private space and generally cannot even see other apps' data, let alone use their services. It is possible to cause other apps to run via custom URLs, but that's not the same thing.
What you'll need to do is to copy or move the code for the view controllers, views, etc. of your various iOS apps into your tab bar app project. You'll build them all into a single application, and the tab bar will switch between the view controllers.
With iOS 8 you will have something similar to Android Intents. Using App Extensions you can reach similar behavior.
In a close future Apps will start expose their "extension" (as you do in Android Framework declaring Intent Filters in the manifest) that will be used by application who need.The extension areas allowed in this first version are:
Today
Share
Action
Foto Editing
Document Provider
Custom Keyboard
It's great finally apple release this functionality!
Intent in Android covers a lot of functions. There is no iOS equivalent to that.
But if your objective is to launch a different app, and pass parameters to it, you can try out URL Schema.
Let's say you have app AAA with URL schema aaa:// and app BBB with URL bbb://
You can launch app AAA, and call bbb://v=1&c=2 for example, to launch BBB and get the parameters. you can even take these parameters to control what view to show, so you can have a similar concept in Android, to call different Activity with Intents.
You have to register URL schema in Info.plist
The closest concept to an Intent on iOS is the handling of certain URLs by the system applications. See here. It was possible to register your own application URL schemes at one point (see this article), but I must admit I haven't tried this in recent SDKs (IIRC Glympse links can be opened in the Glympse app, so this technique probably still works).
As of 2016, Apple has added an Intents framework that is similar to Android's, albeit much more restrictive. Expect Apple to add more Intents in the future, but for now it is quite limited. https://developer.apple.com/reference/intents
Since iOS 8, you can use App Extensions.

Categories

Resources