Writing a panic button for android (Part 2)

Alexey is in touch again, who is already in a hurry with the technical details of the project) In this part, we will learn how triggers work in the application and talk about the problems of Google Play! This part will be larger than the previous one, so grab a drink for the weather and dive into the article!

Under the hood

As I wrote earlier – in earlier versions there was one main trigger – a snag shortcut. What is its essence? The user himself sets the icon and the name of the shortcut under which he disguises himself, and in the latest versions opens the application with the specified package name! Below in the screenshots you can see how the Viber shortcut is made

Screenshots
Main screen
Main screen
Icon selection
Icon selection
Which package to choose
Which package to choose
Ready shortcut
Ready shortcut

All values ​​are saved in preferences, I personally use for quick access TinyDB, and to select files in the application FilePicker… After adding the shortcut with the following code:

The code
  public void addcustomshrt(View view){
        String iconpath = tinydb.getString("icon");
        String nameoftag = tinydb.getString("label");
        File check = new File(iconpath);
        if (check.exists() && !check.isDirectory()){

            Bitmap bitmap = BitmapFactory.decodeFile(iconpath);
            if (ShortcutManagerCompat.isRequestPinShortcutSupported(ShortcutSettings.this))
            {
                ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(ShortcutSettings.this, "#1")
                        .setIntent(new Intent(getApplicationContext(), ShortcutLaunch.class).setAction(Intent.ACTION_MAIN))
                        .setShortLabel(nameoftag)
                        .setIcon(IconCompat.createWithBitmap(bitmap))
                        .build();
                ShortcutManagerCompat.requestPinShortcut(ShortcutSettings.this, shortcutInfo, null);
            }
            tinydb.putBoolean("short",true);
        }else{
            new AndExAlertDialog.Builder(this)
                    .setTitle(getResources().getString(R.string.error))
                    .setMessage(getResources().getString(R.string.short1))
                    .setPositiveBtnText("Ok")
                    .setCancelableOnTouchOutside(false)
                    .OnPositiveClicked(new AndExAlertDialogListener() {
                        @Override
                        public void OnClick(String input) {
                            final String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
                            showListItemDialog("Select png, jpg, ico file", rootPath, FILE_ONLY_DIRECT_CHOICE_IMMEDIATE, PICK_DIALOG);
                        }
                    })
                    .build();

        }}
Explanation

In this line, we say that our shortcut opens the desired activity, which launches our pre-introduced application package:

.setIntent(new Intent(getApplicationContext(), ShortcutLaunch.class).setAction(Intent.ACTION_MAIN))
public void openapp(){
        tinydb = new TinyDB(this);
        if( tinydb.getString("apppkg").length()>3){
            Intent launchIntent = getPackageManager().getLaunchIntentForPackage(tinydb.getString("apppkg"));
            if (launchIntent != null){
                startActivity( launchIntent );
            }
        }

        finish();

    }

Then using the method finish (); the application remains invisible to the eye because it immediately closes, and the selected one opens on top

How are actions triggered?

There was a mini war with Google and miui. If the first one could be dealt with using the service in the background, then miyuay simply cuts autorun. I just had to ask the user to manually enable this unfortunate checkbox ..

There is a main service that is launched using a trigger, the trigger sends which script to apply through extra… After that, the list of actions is checked and accordingly launched.

Launch code
Intent intent = new Intent(this, StartActions.class);
        intent.putExtra("from","shortcut");
        startService(intent);
Processing code
if (from.equals("shortcut")){ List<String> actions = tinydb.getListString("shortactions");
            for (int i =0;i<actions.size();i++){
                if (actions.get(i).equals("Delete Apps")){try {deleteapps(clean,root,list); }catch (IOException e){e.printStackTrace();}}
                if (actions.get(i).equals("Delete files")){startdelete(list2);}
                if (actions.get(i).equals("Crypt folders")){try{ startcrypter();} catch (Exception e){e.printStackTrace();}}
                if (actions.get(i).equals("Send Sms")){sendsms(list4,msg);}
                if (actions.get(i).equals("Power off")){Intent i2 = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
                    i2.putExtra("android.intent.extra.KEY_CONFIRM", true);
                    i2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getApplicationContext().startActivity(i2);}
            }
        }

And so for about each trigger, since the user turns off the notification from the application (well, we ask :)), the deletion occurs in the background and unnoticed

What’s with the markets?

Google Play is another story. I managed to download only the very first public version of the application, and after adding a trigger to SMS, Google Play went into failure. More than 10 requests for approval of declarations (default handler, device automation, etc.) and 2-3 requests to support for permissions – result 0, you see, it is not the main function – then it is not necessary. Camera access, background location, full memory access – approved. But here’s the sms not in any (By the way, who had experience, maybe I’m doing something wrong? Or there are those who are ready to help with this, write it down in the comments. I admit that I am doing something wrong, although what exactly no one can say …)

F-Droid – honestly for me (a more or less confident Linux user) it became a horror in terms of publishing the application .. I even asked several friends, it did not work out .. so the publication here is also postponed

About the rest of the lesser known, I did not even try, almost all my free time is spent on development, and you also need to eat for something, and studying and improving skills is not the last thing.

On this, while the article has come to an end, in the next articles he will fight with the firmware, look for bugs in the android protection system and some more interesting things!

I also read and write down all your ideas, but alas, I can not devote as much time to the application as I would like! ..

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *