Connecting Nox with Android Studio

More info here: https://www.bignox.com/blog/how-to-connect-android-studio-with-nox-app-player-for-android-development-and-debug/

However If You created emulator from nox multiplayer (You can create android 5.1), make sure You have created shortcut to this device and runned by this shortcut.

The rest info related with enabling usb debug and setting to be executed with root permissions is the same.

Raw service with bindings

public class Request2Service extends Service {

    public static final int MSG_REGISTER_WATCHER = -1;
    public static final int MSG_UNREGISTER_WATCHER = -2;

    private ArrayList<Messenger> clients = new ArrayList<>();

    private Messenger clientMessenger = new Messenger(new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_REGISTER_WATCHER:
                    if (!clients.contains(msg.replyTo)) {
                        clients.add(msg.replyTo);
                    }
                    break;

                case MSG_UNREGISTER_WATCHER:
                    if (clients.contains(msg.replyTo)) {
                        clients.remove(msg.replyTo);
                    }
                    break;

                // TODO: 2017-07-12 case: ... 
            }
        }
    });

    private ExecutorService executor = Executors.newCachedThreadPool();

    private static void sendToClients(ArrayList<Messenger> clients, Message msg) {

        for (int i = clients.size() - 1; i >= 0; i--) {
            try {
                Message msg2 = Message.obtain();
                msg2.what = msg.what;
                msg2.arg1 = msg.arg1;
                msg2.arg2 = msg.arg2;
                msg2.setData(msg.getData());
                msg2.replyTo = msg.replyTo;
                clients.get(i).send(msg2);
            } catch (RemoteException e) {
                clients.remove(i);
            }
        }
    }

    @Override
    public int onStartCommand(final Intent intent, int flags, final int startId) {
        if (intent != null && intent.getAction() != null) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    handleStartCommand(intent);
                }
            });
        }
        return START_STICKY;
    }

    private void handleStartCommand(Intent intent) {
        // TODO: 2017-07-12  
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return clientMessenger.getBinder();
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}

 

Passing bitmap to bundle

I found this somewhere in Internet and I thought it would be useful someday

To pass bitmap to bundle, first we ought to convert it to byte array. Then the rest goes straight.

public static byte[] toByteArray(Bitmap bmp) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    return stream.toByteArray();
}

public static Bitmap fromByteArray(byte[] byteArray) {
    return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
}

 

Reading plain text file in java and android asset

//read lines from file

ArrayList<String> lines = new ArrayList<String>();
try {
    BufferedReader input = new BufferedReader(new FileReader(f));

    String line;
    do {
        if ((line = input.readLine()) != null)
            lines.add(line);
    } while (line != null);
} catch (IOException e) {
    e.printStackTrace();
}
return lines;

//read lines from file asset

StringBuilder sb = new StringBuilder();
try {
    BufferedReader input = new BufferedReader(
            new InputStreamReader(assets.open(fileName)));

    String line;
    do {
        if ((line = input.readLine()) != null)
            sb.append(line);
    } while (line != null);
} catch (IOException e) {
    e.printStackTrace();
}
return sb.toString();

Permanently block apk updating

All you need to do is: decompile apk, change code version of apk, compile again and sign with already not original key.

  1. apktool d app.apk
  2. open folder, find yml file, open it and change versionCode to i.e
  3. apktool b app folder
  4. output will be in app folder / dist folder
  5. use this command to sign app, instead you will not be able to install it
    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name

    i.e.

    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore "C:\Users\Me\.android\debug.keystore" app.apk androiddebugkey

     

  6. Done.

Information:

  1. jarsigner is placed in java pathfolder
  2. debug.keystore should be created first time when running own project in android studio

Attachment: apk tool

Remove operator boot animation i.e. plus in Android – Samsung device

First of all You should have root on device, second be able to change your partition on android device to status as: writeable (posted few posts ago what is the command for it).

I assume all is set. Now go in adb shell as a root to : /system/media/

When You call to list files, You will get two interesting files:

-rw------- root     root        69056 2016-12-26 01:42 bootsamsung.qmg
-rw-r--r-- root     root        69056 2016-06-02 17:23 bootsamsungloop.qmg

First is the first static or animating animation, second is the loop. Usually it is like:

-show anoying operator animation
-show after that samsung animation

What to do is to backup first file, and copy the second one but renaming it like the backuped file, which is here “bootsamsung”.

As a result there will be two files as above, but both will do the same animation.