How to create static app shortcut for android 7.1 app? - android-7.1-nougat

like this I want to do with my own shortcuts. And to open particular activity depending on shortcut type
https://i.stack.imgur.com/Q87SO.png

Create android project with target api level 25
Create an xml named shortcuts.xml under res, inside xml directory and add following code in it: (to create static shortcuts)
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="#mipmap/ic_launcher"
android:shortcutDisabledMessage="#string/static_shortcut_disabled_message"
android:shortcutId="static"
android:shortcutLongLabel="#string/static_shortcut_long_label"
android:shortcutShortLabel="#string/static_shortcut_short_label">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="<Fully_Qualified_Activity_Name>"
android:targetPackage="Package_Name_Of_Activity" />
</shortcut>
</shortcuts>
Inside Manifest.xml add this meta-data tag for your activity:
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
And test it by long pressing app icon.

Related

PhoneGap URL scheme on other pages not working

Hi i have this simple app and and i use myapp:// to open app my ANDROID APP this works file but when i use myapp://index.html to open a page it does not work i searched the internet but i could not find the solution can any body tell me i want to open a specific page in my APP because TWITTER does not support myapp:// it supports only if if has any extension like myapp://index.html
or if this is not possible is there any why i could redirect user to a url myapp:// after login from my TWITTER application
THANKS
Muhammad Zeeshan
You can listen also http scheme as your site with a listener activity. Something like this code.
<activity android:label="#string/app_name" android:name="com.foursquare.robin.BrowsableActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="example.com" android:pathPrefix="/" />
<data android:scheme="https" android:host="example.com" android:pathPrefix="/" />
</intent-filter>
</activity>
When any platform re-route your app to your scheme will be revoked shortly.
That myapp:// URL is only useful within the device as a means to start another app on the device (or, in this case, to start your app from another app). I think what you want to do is use a plugin that allows your app to login using the builtin native apps. See this plugin, in particular, as a possible solution: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
You can make "myapp://" as your mobile app URL scheme using these things :
Android :
In your menifest.xml file, add intent-filter into tag
<application ... >
<activity ... >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp"/>
</intent-filter>
</activity>
</application>
Use android:scheme="myapp". So, whenever you want to start your app from other app, you need to add this hiperlink.
Open myApp
iOS :
In iOS, open .plist file of your project(which can be found in Resources/) in xCode.
You need to add 2 things :
Information Property List->URL types->item0->URL identifier = Bundle identifier
Information Property List->URL types->item0->URL schemes = myApp
If anything is not there, you can right click and select "add row", then you can type elements. Help will help you. ;)
So, whenever you want to start your app from other app, you need to add this hiperlink.
Open myApp
Your app will open if it is pre installed in device
You can use javascript frameworks for single page apps.
they can handle by easy way that you do not need to request to other url or external file.
all of your application will run in just single page without refresh.
here i offer list of this frameworks:
backbonejs ( that is easy to use )
emberjs
angularjs witch is google project and personally i offer this.
knockoutjs
list of javascript single page framework is mush bigger, but know about these more.
UPDATE
to handle custom url schema i know some plugins, but personally i did not test theme
- Custom URL scheme
-

Is there a way to submit a reactjs PWA on Google Play?

I want to use the "Write once, run everywhere"
So I created a PWA in reactjs with create-react-app.
My app works greatly, and I can put it on the home screen of my mobile from the website.
However, I want to be visible on mobile stores too (starting with Google Play).
I tried:
Microsoft pwaBuilder which doesn't seems to work (the downloaded bundle is not recognized by Google play)
Packaging my app in Cordova (by copying files of the reactjs build in www) but I'm stuck with a white screen like some other people (publishing PWA on app stores : google play and ios itunes, Reactjs with cordova)
Is there a way today to deploy a reactjs PWA app on a store?
That would realize my great dream about progressive web apps :)
months ago I've developed a small ReactJS application using Cordova/Phonegap that actually works so I think you miss a couple of details in order to make your application works.
First, did you wait the deviceready event before to bootstrap ReactJS?
Your entry point should be something like this ( code is quite old, I used it in an old AngularJS application and adapted it just to bootstrap ReactJS )
var appName = 'myApp';
var PhoneGapInit = function (appName) {
this.boot = function (appName) {
ReactDOM.render(
<Router>
<Route exact path="*" component={ApplicationAsync} />
</Router>,
document.getElementById('root')
);
};
if (window.cordova !== undefined) {
// "Found Cordova";
var self = this;
document.addEventListener('deviceready', function() {
self.boot(appName);
}, false);
return;
}
// 'PhoneGap not found, booting manually';
this.boot(appName);
};
window.addEventListener('load', () => {
new PhoneGapInit(appName);
});
Second, using Webpack I've found necessary to use this webpack plugin to have cordova object available, https://github.com/markmarijnissen/webpack-cordova-plugin ( everything is explained there )
Moreover your index.html should contain a body tag like this
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
The first step should be enough to have your application running.
Also, it is important to know that using Chrome it is possible to access the console to see what is happening in the application, just follow these steps
Connect your device with the application installed ( must be
DEBUG version, not release )
Open the Chrome console and near the last tab you should see a
three vertical dots icon, click it and select 'more tools', then
'remote devices', you should see your connected device listed. Select
it
Find your application in the list and click the 'inspect' button,
at this point you shold have your application opened also in Chrome browser.
Hope it helps
The simple answer is there's currently no way to directly add your PWA to the Google Play Store, Apple's iTunes or Microsoft's App Store. You can, however add your PWA directly to Amazon's App Store. For the rest of them, you have to first create a wrapper for it, then deploy the wrapper package to the store. Since you specifically asked about Google Play Store, you basically need two files (see below), plus a few supporting files, which will be automatically created for you when you create a new Android project in Android Studio (or similar environment). You need a main activity that launches your PWA starting URL, something like:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
view.loadUrl("about:blank");
Toast.makeText(MainActivity.this,
"Failed loading initial resources. Online access is needed when starting the app up for the first time. Close and try again with network connectivity", Toast.LENGTH_LONG).show();
super.onReceivedError(view, request, error);
}
});
webView.loadUrl(APPLICATION_URL);
}
}
You don't need a XML layout file (you could just create the WebView in code) but in case you prefer configuring options in xml, it'd be something like this:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mypackage.myapp.MainActivity"/>
Finally, you need the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/my_logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/my_logo"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Then, you need Android build tools to create your package. If you've downloaded Android Studio, you are all set. The good thing is that, once you've published your wrapper app, you don't need to change it much but can focus on updating just your PWA.
For Microsoft App Store, the process is similar. You don't necessarily need Visual Studio. You can just use PWABuilder's package as a base, remove whatever you don't need and create an "app package upload file" with (Windows) command-line tools.
For iTunes, you need another wrapper and AFAIK, the only way to create one is with (Apple's) Xcode IDE.
The problem was about the create-react-app PUBLIC_URL environment variable which was unfilled.
With a cordova run browser, all seems to be ok as browser seems to be more permissive in the path resolution.
I had as example a /favicon.ico
But when i was doing cordova run android, path were not found at runtime.
By creating a new file .env and put in it:
PUBLIC_URL=.
resolved the path error and the application works now well!
The advice of Sergio running on device with chrome chrome://inspect helped me a lot
Yes there is way to publish your PWAs to PlayStore.
TWAs
Trusted Web Activities are a new way to integrate your web-app content such as your PWA with your Android app using a protocol based on Custom Tabs.
TWAs uses The Digital Asset Links protocol and API enable an app or website to make public, verifiable statements about other apps or websites. For example, a website can declare that it is associated with a specific Android app, or it can declare that it wants to share user credentials with another website.
Checkout the following link for complete guide to launch PWA to Appstore by Google Developers forum and tutorial guide on medium by Maximiliano Firtman here

Cordova - Change app name accordingly to the build type

I need to change the app name of a Cordova based project depending on the gradle build type (debug/release). If I understand correctly, Cordova uses the <nametag in master config.xml as app name. Is there any easy way to configure it? If no, what should I use?
I am using cordova-android": "^6.2.3
Below are the 3 ways to do so :
- Step 1:
You can set the name of your Application in your config.xml
the tag which defines it is
<name>your appname</name>
- Step 2 :
You actually need to go to res -> values -> strings.xml and change:
<string name="app_name">Your app's name</string>
- Step 3:
In cordova project> properties> WMAppManifest.xml file you can change you app's name and icon as well.
If Still Issue :
Check this link - http://www.cordovacircus.com/articles/cordova-android-name
Change the value of android:label attribute in your <application> tag in your AndroidManifest.xml fileLike this:
<application
android:hardwareAccelerated="true"
android:icon="#mipmap/icon"
android:label="#string/app_name" <!--Replace with your Application name-->
android:supportsRtl="true"
android:allowBackup="false"
android:fullBackupContent="false">

How to show my cordova app in IOS share menu?

We have an existing Cordova iOS App for which we need an iOS share extension which will allow Users to to share files from other apps (like Photos, Pages, Numbers, Keynote, etc) with our App (i.e. Export file from Pages to our App).
We need the following delivered:
Prototype / Sample iOS Cordova App
with a share extension setup up for jpg, png, video, pdf and office (xls, xlsx, doc, docx, ppt, pptx) files
Extension to either open the Cordova App directly OR to open the Cordova App as a webview inside the share widget
Cordova App must receive parameters about the shared file (filename, path, type, filesize) from extension - the handling of the file afterwards will be done by us.
Documentation on how to implement this functionality (share extension) in our existing Cordova App (steps necessary to perform in Xcode etc)
I think you could find a solution here. It is not clear, but it seems to work.
There is a cross-platform cordova plugin (iOS and Android) that achieves that: https://github.com/j3k0/cordova-plugin-openwith
That's a good and still relevant question.
I tried to make use of the awesome cordova-plugin-openwith by Jean-Christophe Hoelt but faced several issues. The plugin is meant to receive share items of one type (say, URL, text or image), which is configured during installation. Also, with its current implementation, writing a note to share and selecting a receiver in a Cordova app are two different steps in different (native and Cordova) context, so it didn't look as a good user experience to me.
I made these and other corrections to this plugin and published it as a separate plugin:
https://github.com/EternallLight/cordova-plugin-openwith-ios
Note that it works only for iOS, not for Android.
There are few links which could be helpful even if you do not want to use open with plugin
https://irace.me/tumblr-ios-extension
http://engineering.curalate.com/2017/03/09/ios-share-ext-with-ionic.html
In android editing, the manifest worked fine for me. I had to add one more java file added in some already added plugin like below in plugin.xml. Which in turn added in the manifest.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="application/pdf"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/mspowerpoint"/>
<data android:mimeType="application/powerpoint"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
<data android:mimeType="application/x-mspowerpoint"/>
<data android:mimeType="application/excel"/>
<data android:mimeType="application/vnd.ms-excel"/>
<data android:mimeType="application/x-excel"/>
<data android:mimeType="application/x-msexcel"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
</intent-filter>
</activity>

How to share a link within ionic app that links back to the app

I am trying to implement social sharing within ionic app, I was able to successfully share links through native share sheet. When the link is clicked by the person whom the link is shared with it is meant to link back to the item within the app, If the the user have the app installed, otherwise, it prompt the user to install the app. But it is not work that way, rather it asks if you want to open with PlayStore or browser.
Below is the first thing I did which shares the link successfully after installing cordova social share
.controller('myCtrl', function($state, $cordovaContacts, $ionicActionSheet, $cordovaSocialSharing ) {
$scope.share = function(id) {
$cordovaSocialSharing
.share("my Link Description", null, null,"https://play.google.com/store/apps/deatils?com.ionicframework.myapp/app/item/"+id) // Share via native share sheet
.then(function(result) {
// Success!
}, function(err) {
// An error occured. Show a message to the user
});
}
}
})
and the view is like this
<a ng-click="share(id)"><i class="ion ion-share"></i> </a>
When the link refused to work as I expected, I did a further research, and I found Custom URL scheme PhoneGap Plugin which is a cool plugin for Cordova that is designed to allow to launch apps by clicking on a link in an email or on a web page
after installing the plug , the link is meant to be used like this;
Open my app
Open my app
Open my app
Open my app
but if I put any of this raw into the social sharing implementation, it shared it as it is written, so the link cannot be clicked.
Okay. Let's go step by step.
First of all, you need to install, not only the plugin you use for the URL scheme (I use this one), but also a universal-link plugin which links the http URL http://example.com to your app example://.
After all the process, your config.xml file should be like that:
<plugin name="cordova-plugin-customurlscheme" spec="~4.2.0">
<variable name="URL_SCHEME" value="example" />
<variable name="ANDROID_SCHEME" value=" " />
<variable name="ANDROID_HOST" value=" " />
<variable name="ANDROID_PATHPREFIX" value="/" />
</plugin>
<plugin name="cordova-universal-links-plugin" spec="~1.1.2" />
<universal-links>
<ios-team-id value="xxxxxx" />
<host name="angular.example.com" scheme="https">
<path event="openUrl1Page" url="/url1/*" />
<path event="openUrl2Page" url="/url2/*" />
</host>
</universal-links>
Note: You'll see that a folder called ul_web_hooks is created. Copy also the <link> elements to your main .html file (Actually for me It works without that, but in the documentation, they say it's necesary).
After you have done that 2 things, you should be able to open your app throught console typing something like:
adb shell am start -W -a android.intent.action.VIEW -d "http://angular.example.com/url1/x"
It should also work if you use the URL scheme:
adb shell am start -W -a android.intent.action.VIEW -d "example://url1/x"
Next, you'll need to manually bootstrap your app, so cordova decides bootstrapping depending of the way the app was loaded (common loading opening the app or because someone clicked the link) (note that here you'll have to handle the resume and pause possible status of your up with their respectives addeventListener.
Pay attention since it's a nice trick to use your $urlRouterProvider.otherwise() since you can set over there the right path.
Our last step should be to create a website for those who open a link for the first time and the app is not installed yet (They will successfully open the URL).
Hope it helps!
window.open('https://www.facebook.com/sharer/sharer.php?u={{YOUR URL}}, '_system', 'location=yes');
and
window.open('https://www.twitter.com/share?url={{YOUR URL}}, '_system', 'location=yes');

Resources