nLL

Mobile web, .Net, Android, gadgets and some random stuff

Android how to sell licence/license to your app?

In-app billing is one option but if you can't be bothered to implement it, there is another simple solution.

 

Create a dummy app without launcher and view in AndroidManifest, publish it and set a price.

In your original app that you want to sell license for create a helper class and add below method and call it in your activity like below by replacing  YOUR_PRO_PACKAGE_NAME with your pro package name i.e my.app.licence 

 

checkProLicenceInstaled("YOUR_PRO_PACKAGE_NAME",this);

 

public static boolean checkProLicenceInstaled(String uri, Context c)
	{	
		PackageManager pm = c.getPackageManager();
        boolean app_installed = false;
        try
        {
               pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
           	   String installationSource = pm.getInstallerPackageName(uri);
           	   if(installationSource==null)
           	   {
           		   Log.d("checkProLicenceInstaled", "Installed but NOT from market, return false");
        		   app_installed = false;
           	   }
           	   else{
	           	   if(installationSource.equals("com.google.android.feedback") ||installationSource.equals("com.android.vending"))
	           	   {
	           		   Log.d("checkProLicenceInstaled", "Installed from market, return true");
	           		   app_installed = true;
	           	   }
	           	   else{
	           		   Log.d("checkProLicenceInstaled", "Installed but NOT from market ("+ installationSource +"), return false");
	           		   app_installed = false;
	           	   }
           	   }
        }
        catch (PackageManager.NameNotFoundException e)
        {
        	   Log.d("checkProLicenceInstaled", "NOT installed, return false");
               app_installed = false;
        }
        return app_installed ;
	}

Android programmatically get device name

Here is a small snippet to get device name on Android

public static String getDeviceName() {

		try{
		  String manufacturer = Build.MANUFACTURER;
		  String model = Build.MODEL;
		  if (model.startsWith(manufacturer)) {
		    return capitalize(model);
		  } else {
		    return capitalize(manufacturer) + " " + model;
		  }
		}
		catch(Exception e)
		{
			return "";
		}
	}
	
	public static String capitalize(String s) {
		  if (s == null || s.length() == 0) {
		    return "";
		  }
		  char first = s.charAt(0);
		  if (Character.isUpperCase(first)) {
		    return s;
		  } else {
		    return Character.toUpperCase(first) + s.substring(1);
		  }
	} 

Android move WindowManager TYPE_SYSTEM_ALERT view

I have been struggling with one feature I wanted to add one of my apps. I wanted to let user move a button placed on the screen with TYPE_SYSTEM_ALERT flag. As usual destination I went to stackoverflow and asked my question. Funny enough no one answered. There were few replies but nothing significant to solve my issue. So, I placed a bounty on it. Unfortunatelly that didn't help either. 

Couple of days later still without a solution I've asked same question to pingpongboss, creator of StandOut floating app library creator. With his help after 10 days I was able to get user to move Android button view around with below code.

 

private WindowManager recButtonWindowManager;
private Button recButton = null;
WindowManager.LayoutParams prms;
boolean touchconsumedbyMove = false;
int recButtonLastX;
int recButtonLastY;
int recButtonFirstX;
int recButtonFirstY;


OnTouchListener recButtonOnTouchListener = new View.OnTouchListener() {
    @TargetApi(Build.VERSION_CODES.FROYO)

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        WindowManager.LayoutParams prm = getRecbuttonLayout();
        int totalDeltaX = recButtonLastX - recButtonFirstX;
        int totalDeltaY = recButtonLastY - recButtonFirstY;

         switch(event.getActionMasked())
            {
                case MotionEvent.ACTION_DOWN:
                    recButtonLastX = (int) event.getRawX();
                    recButtonLastY = (int) event.getRawY();
                    recButtonFirstX = recButtonLastX;
                    recButtonFirstY = recButtonLastY;                   
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                case MotionEvent.ACTION_MOVE:
                    int deltaX = (int) event.getRawX() - recButtonLastX;
                    int deltaY = (int) event.getRawY() - recButtonLastY;
                    recButtonLastX = (int) event.getRawX();
                    recButtonLastY = (int) event.getRawY();
                    if (Math.abs(totalDeltaX) >= 5  || Math.abs(totalDeltaY) >= 5) {
                        if (event.getPointerCount() == 1) {
                            prm.x += deltaX;
                            prm.y += deltaY;
                            touchconsumedbyMove = true;                
                            recButtonWindowManager.updateViewLayout(getManualRecButton(), prm); 
                        }
                        else{
                            touchconsumedbyMove = false;
                        }
                    }else{
                        touchconsumedbyMove = false;
                    }
                    break;
                default:
                    break;
            }
            return touchconsumedbyMove;
    }               
};

 
private WindowManager.LayoutParams getRecbuttonLayout() {
    if (prms != null) {
        return prms;
    }
    prms = new WindowManager.LayoutParams();
    prms.format = PixelFormat.TRANSLUCENT;
    prms.flags = LayoutParams.FORMAT_CHANGED; // 8
    prms.type = LayoutParams.TYPE_SYSTEM_ALERT;
    prms.gravity = Gravity.TOP | Gravity.CENTER;
    prms.width = LayoutParams.WRAP_CONTENT;
    prms.height = LayoutParams.WRAP_CONTENT;
    // Tools.Log("getRecbuttonLayout", "return getRecbuttonLayout()");
    return prms;
}



private Button getManualRecButton() {
    if (recButton != null) {
        return recButton;
    }
    recButton = new Button(ACR.getContext());
    recButton.setText(R.string.start_recording);
    recButton.setTypeface(null, Typeface.BOLD);
    recButton.setGravity(Gravity.CENTER_VERTICAL);
    recButton.setBackgroundColor(Color.parseColor("#65FF0000"));
    recButton.setPadding(100, 30, 100, 30);
    recButton.setOnClickListener(recButtonOnClickListener);
    recButton.setOnTouchListener(recButtonOnTouchListener);
    return recButton;
}

Solved - ERROR: cannot start Android Studio. No JDK found. Please validate either ANDROID_STUDIO_JDK, JDK_HOME or JAVA_HOME points to valid JDK installation.

This error is due to android-studio IDE not knowing location of your Java Development Kit. 

Funny thing is, it doesn't even let you that it can't find JDK. When you double click on android-studio icon, nothing happens!

First  download and install the latest version of JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Then, right click on Computer, select properties, select Advanced system settings (on the left), select Advanced tab, select Environment Variables, select New... under "System variables" section and 

Type "JDK_HOME" as variable name

Type "C:\Program Files (x86)\Java\jdk1.7.0_21"  or  "C:\Program Files\Java\jdk1.7.0_21" (if 32bit machine) as variable value

 

Select ok, and you are done

adBrite is closing down on Feb 1, 2013

 I have just received below email from adBrite. They are closing down!

Dear adBrite Publisher,


Over the last few weeks, adBrite and its management have been evaluating the go-forward plan for the business. Given market conditions and certain financial liabilities, in working with our lenders, we have decided to cease operations on Feb 1, 2013.

This is a difficult decision for all of us at adBrite. However, after much deliberation this seems to be the best course of action despite the impact it will have on all the employees, clients and partners who helped build this business. There will be a team in place as needed to assist with winding down.  

Thank you for being part of the adBrite community.

The adBrite Team