How do i make flutter application that open another app within it and not webview - flutter

I have tried to make flutter app in which within it I have a list of another application. I want on tap of any app within a list to open that app, like the code below. How to do it in flutter ?
openExternalApp : function(packageName) {
try {
var KonyMain = java.import("com.konylabs.android.KonyMain");
var context = KonyMain.getAppContext();
var pm = KonyMain.getAppContext().getPackageManager();
var intent = pm.getLaunchIntentForPackage(packageName);
if(intent !== null && intent!== undefined){
context.startActivity(intent);
}
else {
var url = "https://play.google.com/store/apps/details?id="+packageName;
kony.application.openURL(url);
}
} catch(e) {
kony.print("error opening app external: "+e)
}
}

If i understood correctly you want to do something like kindle which allows the user to open a book (in this case an app) directly from your app.
That being the case, maybe this package can help you https://pub.dev/packages/device_apps
to check for installed apps List<Application> apps = await DeviceApps.getInstalledApplications();
and to launch the app DeviceApps.openApp('package.name');
This package currently only supports android.

Related

How I can detect first app lauch in Flutter?

I work on a Flutter mobile app and I want to detect the first app launch to show a little tutorial to the user. I have tests the Shared-Preferences Module But when If I start the app for the first time The console tells me the key is not recognized, I think it's normal because this key does exist! There is another method for checking that?
Thank you guys
use shared preferences to store value that indicate if user has ever been in this page or not
like this
try {
final SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
splash = sharedPreferences.getString("SPLASH_DONE");
} catch (e) {
print("this is first time");
}
if (splash == null) {
page = AppSplashScreen();
} else {
page = LoginPage();
}
and after completing your first time operation call
sharedPreferences.setString("SPLASH_DONE", "DONE");

Flutter web PWA install prompt from within the app

I'm working on a Flutter Web PWA app and having trouble with triggering the Add To Home Screen prompt from within the flutter app. I understand it can be triggered using Javascript with the code below, but how do I do this from my Flutter dart file?
buttonInstall.addEventListener('click', (e) => {
// Hide the app provided install promotion
hideMyInstallPromotion();
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the install prompt');
} else {
console.log('User dismissed the install prompt');
}
})
});
Currently, Flutter web can only prompt PWA installs from the browser. The issue with displaying PWA install prompt is it breaks the compatibility/design with Android/iOS builds as the feature is web-specific.
A different approach that you can take here is by displaying "PWA install" reminders when the app is run on web. Otherwise, it's best to file this as a feature request.
I created the pwa_install package specifically for this purpose.
1. Update index.html
<!-- Capture PWA install prompt event -->
<script>
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
deferredPrompt = e;
});
function promptInstall(){
deferredPrompt.prompt();
}
// Listen for app install event
window.addEventListener('appinstalled', () => {
deferredPrompt = null;
appInstalled();
});
// Track how PWA was launched (either from browser or as PWA)
function getLaunchMode() {
const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
if(deferredPrompt) hasPrompt();
if (document.referrer.startsWith('android-app://')) {
appLaunchedAsTWA();
} else if (navigator.standalone || isStandalone) {
appLaunchedAsPWA();
} else {
window.appLaunchedInBrowser();
}
}
</script>
2. Call PWAInstall().setup()
You can call this method in main.dart before calling runApp()
Future<void> main() async {
// Add this
PWAInstall().setup(installCallback: () {
debugPrint('APP INSTALLED!');
});
runApp(MaterialApp(home: App()));
}
3. Check if the Install Prompt is enabled
Before calling the promptInstall_() method, you can check if the Install Prompt is available using PWAInstall().installPromptEnabled.
installPromptEnabled will be true if:
The app was launched in a browser (It doesn't make sense to prompt a PWA install if the app is already running as a PWA)
The beforeinstallprompt event was captured.
promptInstall_() won't do anything if installPromptEnabled is false so you should check this flag before attempting to call the prompt.
4. Call PWAInstall().promptInstall_()
Finally, call PWAInstall().promptInstall_() to show the install prompt.
Note that this will not work on Safari since Safari does not implement the beforeinstallprompt method this package relies on.

detecting if the current code is running as an app or as web page

I'm developing an hybrid application using ionic.
Most of the features would work on mobile web browser. So the final product can be used from an http address as well. But there are certain code segments/features ( such as vibration, background alerts ) which will obviously be for the app version. And those features will only be available on the app version.
What's a good/recommended way to detect the current situation in the code base so that I can do logic such as if (isRunningAsApp) {do this} else {do that}*?
would it be just checking window.location.href and if you get something that starts wiih http:, then it is a mobile app, otherwise it is an app?
This is from Ionic's documentation
angular.module('PlatformApp', ['ionic']).controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});

Unity start Instagram with data

I made the Unity app to start Instagram, when I press a button. I would like not only to start the app, but also load my company's Instagram page.
Is there any idea,how can I do it ? I need this solution for android as well as on iOS.
Thanks,
This is how I start the Android Apps:
#if UNITY_ANDROID
AndroidJavaObject launchIntent = null;
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
bool fail= false;
try
{
if(bundleId==null){
fail = true;
}else{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage",bundleId);
}
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{ //open app in store
Application.OpenURL(appStoreLink);
}
else //open the app
ca.Call("startActivity",launchIntent);
#endif
Instagram uses custom url scheme to provide opening their app on device. So all you need to do, is call instagram://user?username=YOURINSTAGRAMPAGE as url.
See https://developers.facebook.com/docs/instagram/sharing-to-feed/

Titanium_iphone contacts

I am trying to list contacts with Titanium. WOrks on android device, but on iphone simulator doesn't return anything.
var contacts= Ti.Contacts.getAllPeople();
alert("contacts.length");
returns 0. I am not sure what am i missing here.
Make sure that you have contacts created on your iOS simulator:
Use Home button (CMD+Shift+H) to go to dashboard.
Open up Contacts app
Create few contacts which you want to retrieve in your app.
Also before you call Ti.Contacts.getAllPeople() you have to request authorisation to contact list. Try code below:
function processContacts() {
Ti.API.info('authorized');
var contacts = Ti.Contacts.getAllPeople();
Ti.API.info(contacts.length);
}
if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
processContacts();
} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
Ti.Contacts.requestAuthorization(function(e){
if (e.success) {
processContacts();
} else {
Ti.API.info('disallowed');
}
});
} else {
Ti.API.info('disallowed');
}
One last thing, in your code you wrote: alert("contacts.length") which will always display dialog view with "contacts.length" as a string, not value. To call it properly you should write: alert(contacts.length) without double quotes.