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'.
Related
With Crosswalk I had a very convenient javascript-to-app interface so I could call a java function from javascript and share data from my webapp to my android app.
How can I achieve this with Custom Tabs (or Trusted Web Activity) ?
There seems to be no way at all. There should be, especially when my app and my game/webapp are from the same author.
For example, I do not trust LocalStorage, especially now with Custom Tabs, it may get cleaned, or the user may uninstall the browser and install another one, so the saved data will be lost and the user will be angry at the app for the loss of the saved data, not even understanding that the data were in the browser, not in the app. So I used to have my webapps call the app to save datas.
Another example, when the Custom Tab uses Firefox instead of Chrome, then speech synthesis won't be available. I can detect it easily in my webapp. But I want my webapp to call the app and send it the words to pronounce. That is what I was doing with Crosswalk since it didn't support speech neither.
I understand that webviews are more appropriate for my use than Custom Tabs, but when the webview can't be used on a device (especially Android <5) then my app doesn't have a lot of other options than opening a Custom Tab instead (or Trusted Web Activity if available). I can't use Crosswalk anymore, it is discontinued and still full of serious bugs. And other solutions such as GeckoView or Alibaba Gcanvas are not ready.
edit:
In this article about Trusted Web Activity https://developers.google.com/web/updates/2017/10/using-twa I read
Nevertheless, you can coordinate with the web content by passing data
to and from the page in URLs (e.g. through query parameters, custom
HTTP headers, and intent URIs.)
edit:
I've been reading many pages, Intents and deep-linking are still obscure to me though, but here is what I tried.
I added an intent filter for a custom action :
<receiver android:name=".OutgoingReceiver" android:enabled="true">
<intent-filter>
<action android:name="custom_tabs_js_interface" />
</intent-filter>
</receiver>
I created a class for that receiver :
public class OutgoingReceiver extends BroadcastReceiver {
public static final String CUSTOM_INTENT = "custom_tabs_js_interface";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "received" , Toast.LENGTH_SHORT).show();
}
and I call it in javascript with
location.href="intent:#Intent;action=custom_tabs_js_interface;end";
I don't even pass data for now, I just try to call it.
but nothing happens...
Yes broadcast receiver doesn't work for some reason, probably security. But you can use an Activity in place of Broadcast Receiver to do this as below.
Use custom Android Intent Uri with custom host, query parameters, package, scheme and intent action. Invoke this intent uri from your javascript/html code. Example
"intent://myhost?key=value#Intent;scheme=myscheme;package=my.app.package;action=someaction;end"
Also declare an activity in the manifest file with intent filter to handle the specific host, scheme & action. Example
<activity android:name="my.app.package.ReceiverActivity">
<intent-filter>
<action android:name="someaction" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="myhost"
android:scheme="myscheme" />
</intent-filter>
</activity>
Now in the activity, handle the intent and extract the data from query parameters. Do whatever you want with the data and probably finish the activity in case you want to go back to the same screen. Example
public class ReceiverActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String value = getIntent().getData().getQueryParameter("key");
if (value != null) {
// value is basically your data
}
// in case you want to go back to same screen
finish();
}
}
And that is it. You have data for your disposal at an Android Activity. This ReceiverActivity could (preferrably) belong to same TWA app. Now from this Receiver Activity, you can easily send/share the data to any other apps. Hope this helps.
You can use a hybrid solution:
Use custom tabs as you want for game.
Your server can call your app when is needed using socket programming or push notifications to get the data you need to save in your app.
Also if sending data to your app is unsuccessful your game can warns user in browser at game.
Support for older android versions is encouraged as far as reasonably possible. Platform versions distribution (https://developer.android.com/about/dashboards/) at the moment this post was written states that you would lose around 12.7% of devices if you drop support for version 4.
Consider raising your minimum version to Lollipop where WebView was moved to an APK and use it. You will gain time and implementation simplicity since you'll be able to call #JavascriptInterface annotated methods while keeping your users engaged inside your app (https://developer.android.com/guide/webapps/webview_.
I have a WatchFaceService (WatchFace) and every time I run my application it switches to the SimpleFace and then I have to set mine as the watchFace which ends up to be quite frustrating after many restarts.
To notice this does happen with the new Android Studio 2
I read around S.O. how to set the default activity but that does not do the same job as my WatchFaceService is not an activity but a service.
Also via the UI of Android Studio 2 it cannot be selected.
Is there a way to achieve this ? I think it might be difficult because actually it's not running an app, but setting the watch's Watchface at every run.
Any ideas?
The short answer is that this isn't possible. Your watch face is a Service, after all, so there's no way that it can be the default (launch) Activity for your app. They're completely different component classes.
But you can get close.
What you need to do is create a tiny little shell Activity that contains only the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(getPackageName(),
MyWatchFaceService.class.getName()));
startActivity(intent);
finish();
}
...where MyWatchFaceService is the class name of your watch face service (surprise). You'll also need to declare it in your manifest, of course:
<activity android:name=".FaceActivity"
android:enabled="true"
android:exported="true">
</activity>
Finally, configure your Wear module in Android Studio to launch FaceActivity when you run the app. This is under the Run menu, in Edit Configurations.
Having done that, run your app from AS onto the watch, and it'll open the watch face chooser on-device, with your face selected. From there, one tap will start it.
I can't see a way to eliminate that single tap, though.
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.
I am new in Android Application Development.
Research: Before asking this question, I have read topics related with my question (How to send string from one activity to another?). Unfortunately they are explaining how to copy string from one activity to another activity.
My intention: User opens default browser of mobile phone, highlights text and clicks the button which will be added by me on menu and needed activity is opened with highlighted (copied) text
Tried: I have added intent filter to activity, then added action (android.intent.action.SEARCH) and category (android.intent.category.DEFAULT) into intent-filter. I thought, link for activity will be in Search section after Google, Google Translate, Wikipedia, Dictionary. Also, tried android.intent.action.ACTION_SEARCH_LONG_PRESS. Also, android.intent.action.SEND. Why it is not working, I have no idea.
Tried(2): Found answer for my question partially from here. But link for activity will be in Share->Share as Text->Activity. I think it is too long way.
<activity android:name="ActivityDate">
<intent-filter android:label="Lesson">
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
</intent-filter>
</activity>
Questions (I have many questions. I will try make them short and ask the ones that are most important for me)
Question 1: Is it possible to add a button within menu (which opens when
text is highlighted. It includes copy, search, share)?
Question 2: If it is possible, how to do that? How to make the button so
that when it is clicked, highlighted text should be send to my
activity?
Question 3: If I could do this function for the default browser, can I implement to
other applications (3rd party applications)?
I know there has been lot of discussion for hiding system bar on android 4.0 but no discussions on disabling the functionality of virtual button or status bar or system bar on Android 4.0 tablets?
Is this possible? Can somebody guide me to the right direction?
Thanks!
Try FLAG_FULLSCREEN, it should hide the status bar
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN
I have done a lot of research to design a lock screen and finally found a solution to permanently disable System bars i.e Navigation bar(Back, home, Recent apps soft keys) and the status bar. Android disabled the feature to override System bars except the back button. But there is a little work around to make this work:
Understand and implement screen pinning patiently and you will be successful.
You can create an app to control what all applications you want to implement screen pinning in or you can implement screen pinning directly in the same application you want to pin.
I'm going to show you the later implementation in this article:
1. Firstly your app should be the device owner.
You can do it in several ways and the easiest is to execute the command:
adb shell dpm set-device-owner [yourPackageName]/.[MyDeviceAdminReceiver]
Create a receiver(MyDeviceAdminReceiver) that extends DeviceAdminReceiver. You needn't have any code in here. For more info on Device owner implementation refer this link
http://florent-dupont.blogspot.com/2015/02/10-things-to-know-about-device-owner.html
Register the receiver in the AndroidManifest.xml file this way :
<receiver
android:name=".MyDeviceAdminReceiver"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
2. Your onCreate method should look like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
}
if (mDpm.isLockTaskPermitted(this.getPackageName()))
startLockTask();
3.To unpin the screen and make Navigation Bar functional:
Call the function stopLockTask() at a place in your code where you want to unpin. For example in my application, as soon as I verify that the user has typed the correct passcode, I call this function:
if (userInput.length() == 4) {
if (userInput.equals(passcode)) {
userInput = "";
etxtPasscodeDisplay.setText("");
stopLockTask(); // this is what you need
unlockHomeButton(); // A method to show home screen when
passcode is correct
finishAffinity(); //kill other activities
}
Extra Info which usually is required for lockscreens:
1. If your app is the first thing that comes up after boot:
You need a service(StartAtBootService) and a receiver (BootCompletedReceiver) for this.
2. If you want your app to show up after screen lock and unlock
(the power button is pressed to lock and unlock):
Create AEScreenOnOffService that extends service and AEScreenOnOffReceiver that extends BroadcastReceiver to launch your activity when the screen is on.
For a detailed info on everything I mentioned here, refer http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/
This is an excellent write up which helped me a lot. Special thanks to the author.
I need at least 10 reputation to post more than two links. As I'm new to stackoverflow I don't have enough reputation so I'm sorry for not being able to share all the links I referred. Will surely update the post once I get access.