get Random Long String - Android java.util

Android examples for java.util:Random String

Description

get Random Long String

Demo Code


import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Random;

public class Main{
    private static ArrayList<String> mLongStringList;
    public static String getRandomLongString() {
        if (mLongStringList == null) {
            initLongStringList();//from w ww.  j av a2 s  .c  om
        }
        if (mLongStringList == null) {
            return "Laziness is a feature of a programmer.";
        }
        int idx = random(mLongStringList.size());
        return mLongStringList.get(idx);
    }
    private static void initLongStringList() {
        PackageManager pm = Test.sApp.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(Test.sApp.getPackageName(),
                    0);
            String pkgName = pi.packageName;
            PackageInfo pkgInfo = pm.getPackageInfo(pkgName,
                    PackageManager.GET_PERMISSIONS);
            String sharedPkgList[] = pkgInfo.requestedPermissions;
            mLongStringList = new ArrayList<>();
            for (String name : sharedPkgList) {
                PermissionInfo perm = pm.getPermissionInfo(name, 0);
                mLongStringList.add(name + ": "
                        + perm.loadDescription(pm).toString());
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static int random(int n) {
        return (new Random()).nextInt(n);
    }
}

Related Tutorials