vendredi 14 mars 2014

Windows 8 - How to Dismiss Touch Keyboard?

I am developing my app for Windows 8 in C#, and one very annoying thing is that the touch keyboard sometimes stays on screen even though all textboxes have lost focus.

Solution:


What you need to do is set focus to any control that does not accept text entry. However, be aware that if the user manually showed the keyboard (as opposed to it automatically showing because a TextBox received focus) then the keyboard will remain open.
Check out this really good thread about the on-screen keyboard for more info:

jeudi 13 mars 2014

Beta test for windows store apps

if your developing a new Windows 8 app and you want to test it on another device (e.g. Surface), you’ll need to use a technique called sideloading. This can easily be done through a 
few steps that I’ll describe in this post.


How do I Sideload My App on Another PC or ARM

 Device?

In order to deploy an app, you need an App Package. Visual Studio has functionality to create an App Package you can use to deploy your app to another machine. The following steps are how to create a local App Package.
  1. In Visual Studio Express 2012, choose “Create App Package” in the Store menu.
    image
    Note: In Visual Studio 2012 Ultimate, the Store menu is in a different location. In the “Project” menu, use the “Store” option .
  2. In the Create App Package wizard, you will want to create a local package. Therefore, answer “No” to the “Do you want to build a package to upload to the Windows Store”. Notice the information text indicates this is the option for sideloading.
    image
  3. The next dialog provides a choice of processor platforms to target. In most cases, you would want to choose “Any CPU”. This will allow you to target all of the processor platforms and architectures. However, if you are using platform specific binaries in your app, you’ll need to build separate packages for each platform.
    image
  4. In my example, I’ll just leave the default “Any CPU” and click “Create”
    image
    Note the wizard gives us a link to where the package was created.

If we click the link, here is an example of what was created:
image
Here is a quick summary of the relevant files in the package directory:
Appx package (MyApp_1.0.0.0_AnyCPU_Debug.appx)
The appx package is a zip file of all of the program files for your app. This file gets deployed and installed into Windows. Try renaming the extension to “.zip” and open the zip file to see what is inside. Don’t forget to change it back before you try and deploy it.
Developer test certificate (MyApp_1.0.0.0_AnyCPU_Debug.cer)
This is your development certificate. This is the certificate that was used to sign the appx package.
PowerShell script (Add-AppDevPackage.ps1)
This PowerShell script can be used to install the development certificate and install the App.

 

Installing the App on the Target Machine

Everything you need to deploy the app is included in the package directory created by Visual Studio. I usually copy the directory to a USB memory stick to transfer the app to the target machine. On the target machine, you just need to run the PowerShell script (Add-AppDevPackage.ps1) to deploy the app. You can do this easily by right clicking on the script and selecting “Run with PowerShell”.
image
The first action performed by the script is to install the certificate. It needs to run elevated in order to perform this step. If PowerShell isn’t running elevated, the script will prompt to start an elevated process to install the certificate.
image
You will be warned and prompted to allow the certificate to be installed.
image
Once the certificate is installed, the app package is installed.
image
 Your app should now be installed on the target machine. You should be able to find the tile on the Start screen (usually at the end of the list):
image
The final requirement is to allow trusted apps to run. If your target machine has Visual Studio installed, this requirement will already be met. However, if you don’t have Visual Studio installed, you can meet the requirement through group policy or setting a registry key.  For development purposes, it’s usually easiest to set the registry key.
  • Use RegEdit to navigate to the key: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Appx
  • Set AllowAllTrustedApps (REG_DWORD) to the value of 1
Your app should now run on the target machine.

How to programmatically copy/paste in windows phone?

There is a way to programmatically copy/paste text in windows phone.if you want the user to click on a button that should automatically copy some text to the clipboard.

code :
Clipboard.SetText("foo-bar");


and to get the text:

Clipboard.GetText();

mercredi 12 mars 2014

How to get source code from apk file

let see something cool, i know this is not what y expect from this blog but let's learn something new ;)

What is .apk file?
 APK file is nothing but Android Package File(APK). APK is the file format used to distribute and install application software and middleware on Google's Android operating system.



Apk Files are Zip file formatted packages based on the JAR file format, with .apk extension. Apk files contains all program resources and code i.e it contains .dex files, resources, assets, certificates, and manifest file.



How to get source (java files) from .apk file?
As we now know that apk file is just a zip file containing all program resource file, we can now get java code from apk files with ease. Following are steps to get java code from apk files.
Step 1:Renaming .apk file
  • Rename the .apk file with the extension .zip (for example let the file be "demofile.apk" then after renaming it becomes "demofile.apk.zip")

Step 2:Getting java files from apk
  • Now extract the renamed zip file in specific folder, for example let that folder be "demofolder".
  • Now Download dex2jar from the link for windows and extract that zip file in folder "demofolder".
  • Now open command prompt and go to the folder created in previous step and type the command "dex2jar classes.dex" and press enter.This will generate "classes.dex.dex2jar" file in the same folder.
  • Now  Download java decompiler from the link and extract it and start(double click) jd-gui.exe
  • From jd-gui window browse the generated "classes.dex.dex2jar" file in demofolder, this will give all the class files by src name.
  • Now from the File menu select "save all sources" this will generate a zip file named "classes_dex2jar.src.zip" consisting of all packages and java files.
  • Extract that zip file (classes_dex2jar.src.zip) and you will get all java files of the application.
Above steps will generate java files but to get xml files perform following steps.

Step 3:Getting xml files from apk
  • Download apktool and apktool install from the link and extract both files and place it in the same folder (for example "demoxmlfolder").
  • Place the .apk file in same folder (i.e demoxmlfolder)
  • Now open command prompt and goto  the directory where apktool is stored (here "demoxmlfolder") and type the command "apktool if framework-res.apk" 
  • Above command should result in "Framework installed ..."
  • Now in command prompt type the command "apktool d filename.apk" (where filename is name of apk file)
  • This will generate a folder of name filename in current directory (here demoxmlfolder) where all xml files would be stored in res\layout folder.



Google Analytics SDK for Windows 8 and Windows Phone

I found a very cool API for you guys to add google analytics to you application , i am using this one for a while now and it works just fine!


1. Update your application manifest

The only capability you need to add to your application is the IDCAPNETWORKING capability for Windows Phone or Internet (Client) capability for Windows 8 store apps. These capabilities are already selected by default but you should confirm to make sure your app can send data over the internet.

On Windows Phone (7 & 8):

GA_Capabilities_WP7.png

On Windows 8 store apps (JavaScript and Xaml):

GA_Capabilities_Win8.png

2. Install the NuGet package

Option A: From Visual Studio Nuget Package Manager

  1. Right click on your project and choose 'Manage NuGet Packages'
  2. Search for "GoogleAnalyticsSDK"
  3. Click 'Install'.
nuget1.png
nuget2.png

Option B: Run the following command in the Package Manager Console

PM> Install-Package GoogleAnalyticsSDK -Pre

3. Modify your analytics.xml file

By default, a file called analytics.xml will be automatically added to the root of your project. This file contains configuration options that you must edit. At the very least, you should always modify your tracking ID, app name and version:
<?xml version="1.0" encoding="utf-8" ?>
<analytics xmlns="http://googleanalyticssdk.codeplex.com/ns/easytracker">
  <!--Replace placeholder ID with your tracking ID-->
  <trackingId>UA-XXXX-Y</trackingId>
  <!--Replace placeholder name with your app name-->
  <appName>TestApp</appName>
  <!--Replace placeholder version with your app version-->
  <appVersion>1.0.0.0</appVersion>
</analytics>
See the analytics.xml parameters reference for the complete list of parameters you can use to configure your implementation.

4. Add EasyTracker methods

Add a single line of code to your app for each event you want to track. Here are examples of the different types of activities you can track in your app:
// track a page view
GoogleAnalytics.EasyTracker.GetTracker().SendView("main");
// track a custom event
GoogleAnalytics.EasyTracker.GetTracker().SendEvent("test", "userclick", null, 0);
// manually track an exception
GoogleAnalytics.EasyTracker.GetTracker().SendException("oops, something went wrong", false);
// track a transaction (in app purchase)
double cost = 1.99;
long costInMicrons = (long)(cost * 1000000);
var transaction = new GoogleAnalytics.Transaction("01234", costInMicrons);
var item = new GoogleAnalytics.TransactionItem("myproduct", "My Product", costInMicrons, 1);
transaction.Items.Add(item);
GoogleAnalytics.EasyTracker.GetTracker().SendTransaction(transaction);
// track a social networking interaction
GoogleAnalytics.EasyTracker.GetTracker().SendSocial("facebook", "share", "http://googleanalyticssdk.codeplex.com");
// track a timing (how long it takes your app to run a specific task)
GoogleAnalytics.EasyTracker.GetTracker().SendTiming(DateTime.Now.Subtract(startTime), "Startup", "MainPage", "Label");

JavaScript Windows Store Apps

The same APIs are available for JavaScript, C#, VB.NET, & C++ and work the same for both Windows 8 store apps and Windows Phone 7.1 and 8 applications.
JavaScript developers should note that WinRT objects are exposed to JavaScript with some minor casing changes that are more consistent with JavaScript naming conventions. Therefore to track a page in JavaScript you would need to do something like the following (note the case change on properties and methods):
// track a page view
GoogleAnalytics.EasyTracker.getTracker().sendView("main");
Warning: The Google Analytics SDK for Windows 8 and Windows Phone can automatically track exceptions and application lifetime events if autoAppLifetimeTracking is set to true in analytics.xml. However, this is not supported in JavaScript store applications. WinRT objects cannot gain access to JavaScript store application lifetime events such as suspend, resume, and unhandled exceptions like they can for Xaml based apps. Therefore, if using JavaScript you should consider manually calling EasyTracker for these events.

Congratulations! Your app is now setup to send data to Google Analytics.