Android: Show notification (push)

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;

public class Notify {
    private static String CLASS_NAME;
    private final NotificationManager manager;
    private final Context context;
    public int smallIcon = R.drawable.cnote2;
    private static final int MESSAGE_ID = 1;
    public Notify(Activity activity)
    {
        CLASS_NAME = getClass().getName();
        manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
        context = activity.getApplicationContext();
    }
    private Notification create(String title, String message, long when)
    {
        Notification notification = new Notification.Builder(context).setContentTitle(title).setContentText(message).setWhen(when).setSmallIcon(smallIcon).build();

        return notification;
    }

    public void notify(String title, String message)
    {
        Notification not = create(title, message, System.currentTimeMillis());
        manager.notify(MESSAGE_ID, not);
    }
}

MSBuild: error MSB4019: The imported project “C:\Microsoft.Cpp.Default.props” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

  • How to fix this error on your automated build?

MSBuild: error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the  declaration is correct, and that the file exists on disk.

This error appears usually when a project was created in a newer visual studio version than the one installed in your build machine  (using a different v… build tools). You can check your version by going into this path and looking for a v… folder:  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\.

For example, if the projects requires V120 and your build machine has v110 installed, do the following in order to fix the build:

  1.  On your MSBuild command add property VCTargetsPath with the correct path: /p:Configuration=Release /p:Platform=Win32 /t:Rebuild  /property:VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110"
  2.  Open your vcxporject and modify all of your PlatformToolset from v120 to v110:<PlatformToolset>v120</PlatformToolset> should be replaced with:  <PlatformToolset>v110</PlatformToolset>

Alternatively,  of course, you could install the correct Visual Studio version:

i.e.:

v110 (build tools) = require installation of Visual Studio 2012

v120 (build tools) = require installation of Visual Studio 2013

 

Android: app:transformClassesWithDexForDebug…ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.7.0_79\bin\java.exe’… finished with non-zero exit value 2

  • How to overcome this error:

Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.7.0_79\bin\java.exe” finished with non-zero exit value 2

If you already tried clean, rebuild, resync, remove unused references and still got this error you may be facing a memory issue.

Most chances is that you are using some double dependency and you should exclude, for example (removing double dependency for facebook bolts):

compile ('com.facebook.android:facebook-android-sdk:4.+'){
exclude group: 'com.parse.bolts',
module: 'bolts-tasks'
exclude group: 'com.parse.bolts',
module: 'bolts-applinks';}

If you do not have time to find these double dependency or you are actually having a memory issue a solution could be to use MultiDexApplication

(read about it here:  android developer link )

The solution:

  1. In your build.gradle (module:app), enable the multiDex
    defaultConfig {
    applicationId "com.software.mizz.pokerfriends"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true}
  2. In your build.gradle(module:app), add the multidex dependency compilation

    dependencies {
    ...
    compile 'com.android.support:multidex:1.0.1'
    }
  3. Your main application should extend MultiDexApplication
    public class myApplication extends MultiDexApplication {...}
  4. This class should be defined in your manifest.xml
    ...
    <application
    android:name=".myApplication"
    ...
    >

Remark: Adding MultiDex to your application may detect double dependenices!

C#: Reflection tutorial

  • How to use reflection – reminder 🙂


Assembly DLL;
DLL = Assembly.LoadFile(@"<local path of your dll>");
var MyClass= DLL.GetType("NameSpace.MyClass");
var MyMethod= MyClass.GetMethod("MethodName");
var instance = Activator.CreateInstance(BasicADAuthenticator);
var res = MyMethod.Invoke(instance , new object[] { param1,param2 });
var theResult= DLL.GetType("NameSpace.ResultClass");
if (SASAuthResult.GetField("ReturnCode").GetValue(res).ToString()=="SUCCESS")
{
return true;
}


// How to avoid ambiguity? answer: use GetMethod including parameter types
var myMethod= MyClass.GetMethod("MethodName", new[] { typeof(string), typeof(string) });