Disable GotoHome behaviour provided by a mouse middle button click on Android - android

In a business context (not commercial app), I need to avoid middle button click behaviour, that is to say displaying Home Screen
I spent hours browsing Stackoverflow pages, and the conclusion is often :
it's not possible, regarding obvious security considerations
My need is a bit different :
I use a connected mouse, I don't want to override device hardware button.
my app will only be use in a business context, not publicly.
Details :
my device is a Samsung Galaxy 3 (Model Number GT-P5210, Android version 4.2.2)
the mouse is a classical 3-buttons mouse (left-click, mouse wheel, right-click)
I can accept :
to override OnPause, OnUserLeaveEvents (https://stackoverflow.com/a/32938986/2773267 doesn't work in my case)
to modify my manifest
to use a service (watchdog-like), that prevent Home display
to root the device (last-chance solution):
modify /system/usr/keylayout (part of https://stackoverflow.com/a/29311126/2773267 answer)
all others solution, excepted those I can't accept :)
I can't accept :
using service (as in http://www.piwai.info/chatheads-basics/)
--
Thanks, Jerome.
Excuse my awful english, I'm french !

Putting this 3 lines to the manifest solved the problem.
Firstly it didn't work because I made a mistake on activity name
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Thanks !
--
Jerome

You can build your app as a HOME-screen replacement. In this case, your app IS the HOME-screen, so pressing HOME does nothing.

Related

What is the name of this on app development?

We are doing an app for a client an he needs some similar functionality to this (see picture attached) offered by the iTranslate App on iOS.
With this functionality, when you are in any other App (for instance reading anything on the Medium App) and you select a word, a menu appears and you can select to open this word with the app of my client. But instead of opening the whole App and closing the one were are using, a kind of pop up appears:
I have a few questions about this:
- Does this have a name?
- Can something like this be done with Ionic or you need to code the app in Native?
- Is this possible only on iOS or also in Android?
I am really lost about this issue and would appreciate some guidance.
Thanks
The example in the first picture would be called a "Floating Context Menu," according to the Android Developers website. The example in the second picture would be called a "Popup Menu."
Hope this helps! Good Luck!
You can use a text selection toolbar https://material.io/design/platform-guidance/android-text-selection-toolbar.html# for this, which was added in Android 6.0. Note that you can only use this on Android 6.0 and later.
There is a nice article here, which provides some examples on how to create this:
https://medium.com/androiddevelopers/custom-text-selection-actions-with-action-process-text-191f792d2999
From the article, the basic implementation is the following:
AndroidManifest.xml
<activity
android:name=".ProcessTextActivity"
android:label="#string/process_text_action_name">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
ProcessTextActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.process_text_main);
CharSequence text = getIntent()
.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
// process the text
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, result);
setResult(RESULT_OK, intent);
}
So, I am pretty sure you can implement this in ionic. I never wrote anything in ionic, but you may be able to call something like this Java code from it.
This is a customized PopupWindow(Android Documentation) which should not be a major issue to cook up with something like PopoverController (Iconic Documentation).
the real problem you will face is the text selection. you can look into this stackoverflow link for pointers.
Solutions like these may work in one or the other platform you have to muck the code unless there is and api for text selection in iconic.
if iconic does not give you the API you will have to roll up your sleeves. At this point you are on a slippery slope looking over the webview(s).
Update:
All the above juggling is needed to implement this within your app. Android and iOS will not allow you to add items to system context menu as you see in an PC based(Windows/MacOS/...) OS(s).
If you check Google Translator app in Android. it listens clipboard copy event and pops up a transient icon over other apps. in iOS drawing over other app is not possible.
So if you want your feature to show up in Medium App then they have to add the UI and they have to call your 'API'.

My Android app always opens links instead of Android asking every time

My app is designed to work with various Amazon links but for some reason it has started to always open links instead of the Android system asking every time.
If I click a link on the Amazon website in Chrome my app opens. If I click an Amazon link in an email my app opens.
In my settings I have Android set to Ask every time for Amazon (see screenshot) but it's acting as though it is set as the default.
What's odd is that my app didn't used to do this, and it sometimes doesn't do it now (though only very occasionally) and instead asks as you would expect. But 95% of the time my app launches automatically.
Now I'm getting reports from users of the same thing.
Is it possible for something in the manifest to cause this (I wouldn't have thought so as that could effectively allow app hijacking) or are my OS settings (and those of the users reporting the problem) messed up?
Manifest.xml below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nooriginalthought.amalfi">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="AmALfi" android:largeHeap="true" android:resizeableActivity="true" android:supportsPictureInPicture="true" android:theme="#style/AppTheme">
<activity android:name="com.nooriginalthought.amalfi.MainActivity" android:configChanges="orientation|screenSize" android:screenOrientation="portrait" android:launchMode="singleTop" android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="#string/generate_affiliate_link_with_amalfi">
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
<intent-filter android:label="#string/generate_affiliate_link_with_amalfi">
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="*.amazon.ae" android:scheme="http"/>
<data android:host="*.amazon.ae" android:scheme="https"/>
<data android:host="*.amazon.ca" android:scheme="http"/>
<data android:host="*.amazon.ca" android:scheme="https"/>
<data android:host="*.amazon.co.uk" android:scheme="http"/>
<data android:host="*.amazon.co.uk" android:scheme="https"/>
<data android:host="*.amazon.com" android:scheme="http"/>
<data android:host="*.amazon.com" android:scheme="https"/>
<data android:host="*.amazon.com.au" android:scheme="http"/>
<data android:host="*.amazon.com.au" android:scheme="https"/>
<data android:host="*.amazon.com.br" android:scheme="http"/>
<data android:host="*.amazon.com.br" android:scheme="https"/>
<data android:host="*.amazon.com.mx" android:scheme="http"/>
<data android:host="*.amazon.com.mx" android:scheme="https"/>
<data android:host="*.amazon.de" android:scheme="http"/>
<data android:host="*.amazon.de" android:scheme="https"/>
<data android:host="*.amazon.es" android:scheme="http"/>
<data android:host="*.amazon.es" android:scheme="https"/>
<data android:host="*.amazon.fr" android:scheme="http"/>
<data android:host="*.amazon.fr" android:scheme="https"/>
<data android:host="*.amazon.in" android:scheme="http"/>
<data android:host="*.amazon.in" android:scheme="https"/>
<data android:host="*.amazon.it" android:scheme="http"/>
<data android:host="*.amazon.it" android:scheme="https"/>
<data android:host="*.amazon.jp" android:scheme="http"/>
<data android:host="*.amazon.jp" android:scheme="https"/>
</intent-filter>
<intent-filter android:label="#string/generate_affiliate_link_with_amalfi">
<action android:name="android.intent.action.VIEW"/>
<data android:host="*.amazon.ae" android:scheme="http"/>
<data android:host="*.amazon.ae" android:scheme="https"/>
<data android:host="*.amazon.ca" android:scheme="http"/>
<data android:host="*.amazon.ca" android:scheme="https"/>
<data android:host="*.amazon.co.uk" android:scheme="http"/>
<data android:host="*.amazon.co.uk" android:scheme="https"/>
<data android:host="*.amazon.com" android:scheme="http"/>
<data android:host="*.amazon.com" android:scheme="https"/>
<data android:host="*.amazon.com.au" android:scheme="http"/>
<data android:host="*.amazon.com.au" android:scheme="https"/>
<data android:host="*.amazon.com.br" android:scheme="http"/>
<data android:host="*.amazon.com.br" android:scheme="https"/>
<data android:host="*.amazon.com.mx" android:scheme="http"/>
<data android:host="*.amazon.com.mx" android:scheme="https"/>
<data android:host="*.amazon.de" android:scheme="http"/>
<data android:host="*.amazon.de" android:scheme="https"/>
<data android:host="*.amazon.es" android:scheme="http"/>
<data android:host="*.amazon.es" android:scheme="https"/>
<data android:host="*.amazon.fr" android:scheme="http"/>
<data android:host="*.amazon.fr" android:scheme="https"/>
<data android:host="*.amazon.in" android:scheme="http"/>
<data android:host="*.amazon.in" android:scheme="https"/>
<data android:host="*.amazon.it" android:scheme="http"/>
<data android:host="*.amazon.it" android:scheme="https"/>
<data android:host="*.amazon.jp" android:scheme="http"/>
<data android:host="*.amazon.jp" android:scheme="https"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity android:name="com.nooriginalthought.amalfi.ManageAffIdsActivity" android:configChanges="orientation|screenSize" android:screenOrientation="portrait" android:theme="#style/AppTheme"/>
<activity android:name="com.nooriginalthought.amalfi.PreviewLinkActivity" android:configChanges="orientation|screenSize" android:screenOrientation="portrait"/>
</application>
</manifest>
You have set one activity for android:mimeType="text/plain" and as Browser.
Split both in owns Activities
You have probably set that your app is standard for text/plain and so it will be always opening as browser

Launch Home choice from an app

Hello my question is a bit difficult let me explain and try to understood
I have a custom Home who is set as default when user press home. Know i need a way to ask wich home use when i press on a setting key, or a way to launch Setting activity for delete home default action.
In fact i wan't a way to go back to home app installed by google instead of mine just in case.
I need this because my custom home is still in dev and don't have all feature yet.
I need to keep my home as a default action when user press home buton but i need to add a home selector in special case.
I have try to use finish() when i need to go back to old home but mine as default is automaticly relaunch because he is the default one.
Any idea?
EDIT
I try to reformul a bit.
I'm making a home apps. I set it as default on my tablet. My home apps don't have all feature yet. And when i will launch something or go to setting i need to relaunch default home app.
So i need a way inside my app to reset default home action or launch a home apps, or ask user to choice wich app he will use has home apps.
Hope this is clear for all.
Probably you should use this one to implement your idea. keep the below lines in your manifest file.
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more info about the sample project. just go the below path in your Android SDK
\android-sdk\samples\android-8\Home
EDIT :
Hi Please check this to pro grammatically unset the default application.
How do I use PackageManager.addPreferredActivity()?
for more info go through this also to clear the clearPackagePreferredActivities
http://developer.android.com/reference/android/content/pm/PackageManager.html#clearPackagePreferredActivities%28java.lang.String%29
hope this helps you.

What does "category" in the manifest mean?

The documentation says you can specify a custom category.
When, why and how would you do it?
What would be the use of it?
The way I understand it, categories are public directives to the android operating system(and other apps) that represent different categories that your app should be a part of.
Example
When the launcher icon is tapped on the home screen, the home application looks through every installed app's manifest for the HOME category -- and if so it displays it in the app drawer.
However, there's more. You can specify categories in your applications manifest that lets the system know that you application can handle the intent category. For example, by putting a ALTERNATIVE category, other apps in the system know that your app can handle that category without specifically knowing the action name! In the following example, custom intent categories are passed through this intent, which is filtered and the corresponding object gets edited(taken from the Notes example app):
<intent-filter android:label="#string/resolve_title">
<action android:name="com.android.notepad.action.EDIT_TITLE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
By registering this intent filter in an <activity /> tag, you can edit a "note". The intent data would contain the note, and the intent would get routed to the activity that this filter is registered in.
In Conclusion:
There isn't really a reason you'd use a custom category. They are for Android, and thus don't really make sense in application use. But, if you choose to use them, they can be used in the methods described above. "They provide some specific semantic rules, and if those rules are useful to you then feel free to use them"(Hackbod).
http://developer.android.com/guide/topics/intents/intents-filters.html
Scroll down a bit and you should see a section under "Intent Objects"
They basically describe certain special properties of an activity. for example, adding
<category android:name="android.intent.category.HOME" />
means that the app can be started on the phone's bootup
I'm kinda a noob to Android still, although I have programming experience otherwise.. It says a custom category in your own namespace. I'm guessing that if you are programming multiple apps and you want one app to run another app, you could use a custom category for your intent to force the phone to find your other app to catch the intent with?
When you do not want to use the default category then use the custom category.
Custom categories should use the package name as a prefix, to ensure that they are unique.
Some information is provided on below link:
http://developer.android.com/guide/topics/manifest/category-element.html
Check the below link it has somewhat same question:
Android custom categories

Overriding Home button for a Car Home replacement app

I have been working on a replacement for the stock Car Home app for a bit, and I am completely stumped on how to override the Home button so that my app will be brought back to the foreground whenever the phone is docked. This is the way that Car Home works, so there must be a way.
It seems that BroadcastReceivers won't work, because the intent that is broadcast whenever the Home button is pressed will still cause the default homescreen app to launch; I cannot prevent it. I can override the Home button from within my app, but that does me no good since this needs to work when the user is outside my app. Car Home also does not do anything weird like set itself as the default homescreen app while it's running (I checked the logcat to make sure).
What can I try next?
Well, after many months I have finally found the answer to this question. The key is the "android.dock_home" metadata element, found here:
http://developer.android.com/reference/android/content/Intent.html#METADATA_DOCK_HOME
By using this in your AndroidManifest.xml, you can make your dock application become the home application temporarily. To do this, add this line to the AndroidManifest.xml inside the Activity tags for the dock app activity:
<meta-data android:name="android.dock_home" android:value="true" />
If the value is set to true, as long as your phone is docked the Home button will return you to the dock app. After undocking, the Home button will take you back to your normal home app.
Unfortunately, there is no way in the public APIs to override the Home button without the user confirming it.
Your best bet would be to implement a CATEGORY_HOME Intent. This means when a user pressed Home they would be presented with the option to run the standard Home or yours and make yours the default if they wanted.
When your application was launched you could then check if the phone was docked. If the phone is not docked you could then open the standard Home screen and close your app before anything is displayed.
You need to the correct intent filter in your manifest for the app to launch automatically when you dock the phone. Refer to http://developer.android.com/reference/android/content/Intent.html#CATEGORY_CAR_DOCK for the information.
I found a way to tackle HOME key. For your application set the manifest as
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
Now your application is an alternate Launcher application.
Use the adb, and disable the launcher application using package manager
pm disable com.android.launcher2.
Now the Home key press will aways stay in the same screen.

Categories

Resources