Search This Blog

Thursday, 24 September 2015

create ionic app with appname and id

we create ionic app just by saying:
ionic start YourAppName blank

if you create app this way, problem will come after building ios/android app.
you need to edit config.xml . if you want to give app name and bundle id while creating project itself use the below command.

ionic start YourAppName blank --appname YourApp --id com.yourcomapny.yourapp

Wednesday, 23 September 2015

Signing and Generating .apk for Ionic apps

ionic build android will give you an unsigned apk file. unsigned apk is not accepted in play store. so you need to sign and make .apk to release to play store.

Building Ionic Android app:
ionic build --release android
This will generate a release build based on the settings in your config.xml. Your Ionic app will have preset default values in this file, but if you need to customize how your app is built, you can edit this file to fit your preferences. Check out the config.xml file documentation for more information.
Now, we can find out unsigned apk in \platforms\android\ant-build\MainActivity-release-unsigned.apk
app name "MainActivity" looks ugly. to change the app name follow the steps below:
You will need to update the following files:
  1. YourProjectName/platforms/android/AndroidManifest.xml
  2. YourProjectName/platforms/android/build.xml
  3. YourProjectName/platforms/android/src/com/yourpackagename/appfolder/MainActivity.java
STEP 1
Got to the AndroidManifest.xml file and look for:
<activity android:configchanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchmode="singleTop" android:name="MainActivity" android:screenorientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowsoftinputmode="adjustResize">
change MainActivity to whatever name you want. ex:ItsMyCodeShare
STEP 2: In the build.xml file locate the following line:
<project name="MainActivity" default="help">
Change MainActivity to the name of your project and should match the one in put in step 1 (i.e  name="ItsMyCodeShare").
STEP 3 This stage is abit more tricky and extra caution should be taken when doing this, or else you  might mess things up big time...and that is not Awesome!!
  • Locate the file MainActivity.java and rename it to project name (Same as step 1 and 2...i.e ItsMyCodeShare.java).
  • Open the renamed file and locate the line : public class MainActivity extends CordovaActivity change it to the project name like: public class ItsMyCodeShare extends CordovaActivity
Sorry to disappoint you but.....That's it!!!
Run the command : ionic build android --release
more so, we are ready with our desired name.apk file.
Lets start signing it now.
1) Generate Private key
2) Sign the apk
3) zip the apk
For the above steps you will be using keytool, jarsigner and zipalign tools respectively.
1)keytool will be available in "C:\Program Files\Java\jre7\bin"
2)jarsigner will be available in "C:\Program Files\Java\jdk1.7.0_79\bin"
3)zipalign will be available in "C:\Users\e571224\AppData\Local\Android\sdk\build-tools\22.0.1"
Note:build-tools version(22.0.1) might vary depending on your installed version.
Step 1:
 we need to generate a private key using keytool of JDK.
open your command prompt and enter keytool. if it is not recognized add your jre/bin to Path environment variable.
Then, use the following command to generate the private key
keytool -genkey -v -keystore yourapp-release-key.keystore -alias app_alias_name -keyalg RSA -keysize 2048 -validity 10000
yourapp-release-key.keystore is now generated in that folder. copy and keep it safe.
It will ask for a password, followed by some security questions. remember the password.(take a screenshot to be on safer side)
Step 2:
we need to sign our unsigned apk with the above private key.
copy the private key (yourapp-release-key.keystore, generated in above step) into the folder in which your apk is present. Also, make sure to add the jdk/bin to Path environment variable.
now, run the below command to sign it.
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore yourapp-release-key.keystore yourapp-release-unsigned.apk app_alias_name
enter the password and your apk is signed now. 
Step 3:
we use the zipalign tool to generate the apk. zipalign is available in build-tools/yourversion. add that path to your environment variables.
Now, run the below command to generate the apk:
zipalign -v 4 yourapp-release-unsigned.apk ItsMyCodeShare.apk
this will generate the apk file which you can ship to play store.
References:
http://ionicframework.com/docs/guide/publishing.html
http://forum.ionicframework.com/t/renaming-android-build-apk-from-cordovaapp-to-your-app-name/15416

Friday, 28 August 2015

Ionic View - explained

Ionic came up with a good idea for releasing the apps for QA/UAT and also kind of sharing.
i will just explain the steps to use this feature.

Pre-requisite:
you and the recipient to whom you want to send should have Ionic accounts. go to this link and sign up to get an account https://apps.ionic.io/


Step 1:
create the project in ionic (as you do normally)
ionic start testapp blank

you can add platforms, push notifications and do the development as you want.
Step 2:
Now you need to upload this app.
go to the app directory (cd appname).
then use this command to upload : ionic upload

Step 3:
you can share the app with the person by using the below command.
ionic share test1234@test.com

Step 4:
The sharing is through the account associated with that email and ionic view mobile app.
you can download the ionic view mobile app from Play store and App Store.

Step 5:
Sign into the app with the registered mail id. here it is test1234@test.com. then you can find the app there.
Step 6:
If you click on an app it will show you a menu as below:
 Step 7:
If you select View App, it will get downloaded and it will show as like an installed App. sample screenshot for reference.
Easy way to share app....!!! 


Thank the Ionic team for their work to bring new features to simplify developers job.

Ionic Framework Installation

Installing Ionic framework is pretty simple and straight forward.
Follow the below steps to complete it.

1. All Ionic installations are based on node.js. So, first install nodejs.
you can get the latest version of nodejs here: https://nodejs.org/download/

2. After installing nodejs, first you need to have Cordova. run the below command in command prompt: npm install -g cordova

Now you have installed, nodejs and Cordova. All ionic project templates are stored in Git. So you need Git to start any project in Ionic,

3. Install latest version of Git from : http://git-scm.com/

4. Install ionic framework. run the below command
npm install -g ionic

That's it. your Ionic is ready to start. to test give the following command in cmd prompt: ionic start testapp blank


Sunday, 16 August 2015

Print Stylesheet Emulation/Debugging in Chrome


CSS for printing a div:

html body *{
display:none;
}
#printBillDIv , #printBillDIv  *
{
display:block !important;
}

Emulation /Debugging


  • Under Emulation > Media check CSS media and select print (3).Emulate print media query on Chrome v43

    • Open the Developer tools (CTRL+SHIFT+I or F12)
    • Click the Toggle device mode button in the left top corner (1).
    • Make sure the drawer is shown by clicking the Show drawer button (2) or pressing the ESC key to toggle the drawer.
    • Source: http://stackoverflow.com/questions/9540990/using-chromes-element-inspector-in-print-preview-mode 

    Tuesday, 19 May 2015

    Service vs provider vs factory vs Value vs Constant in angularjs

    All Services are singletons; they get instantiated once per app. They can be of any type, whether it be a primitive, object literal, function, or even an instance of a custom type.
    The valuefactoryserviceconstant, and provider methods are all providers. They teach the Injector how to instantiate the Services.
    The most verbose, but also the most comprehensive one is a Provider recipe. The remaining four recipe types — Value, Factory, Service and Constant — are just syntactic sugar on top of a provider recipe.
    • The Value Recipe is the simplest case, where you instantiate the Service yourself and provide the instantiated value to the injector.
    • The Factory recipe gives the Injector a factory function that it calls when it needs to instantiate the service. When called, the factory function creates and returns the service instance. The dependencies of the Service are injected as the functions' arguments. So using this recipe adds the following abilities:
      • Ability to use other services (have dependencies)
      • Service initialization
      • Delayed/lazy initialization
    • The Service recipe is almost the same as the Factory recipe, but here the Injector invokes aconstructor with the new operator instead of a factory function.
    • The Provider recipe is usually overkill. It adds one more layer of indirection by allowing you to configure the creation of the factory.
      You should use the Provider recipe only when you want to expose an API for application-wide configuration that must be made before the application starts. This is usually interesting only for reusable services whose behavior might need to vary slightly between applications.
    • The Constant recipe is just like the Value recipe except it allows you to define services that are available in the config phase. Sooner than services created using the Value recipe. Unlike Values, they cannot be decorated using decorator.

    Tuesday, 17 February 2015

    Match a string against a List of Regex Patterns in C# - Better way

    when you have list of Regex Patterns and you want to check whether your string matches any one of the patterns, then doing it using Lamda Expressions is an efficient way.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;

    public class Program
    {
    public static void Main()
    {

    List<Regex> lstpat= new List<Regex>();
    lstpat.Add(new Regex(@"\d{2}"));
    lstpat.Add(new Regex(@"\d{4}"));
    string str = "qqw1q1q2q1q2q2q3qqwqw";

    if(lstpat.Exists(x=>x.Match(str).Success == true))
    System.Console.Write("exists");
    else
    System.Console.Write("no");
    }

    }

    Output
    no

    if i give str = "qq11";

    output will be exists.

    if you are not doing it using Lamda Expressions you may need to write one loop for finding Matches.
                        foreach (Regex pattern in lstSmartTagPatterns)
                        {
                            lstMatches.Add(pattern.Match(str));
                        }
    then i need find a Match found or not in another loop.
                        foreach (Match result in lstMatches)
                        {
                            if(result.Success)
                                       System.Console.Write("exists");
                             else
                                       System.Console.Write("Doesnt exist");
                        }

    found doing first way is better. open for improvements.. share urs...