I want to create an app for android nougat, when I click on a button I launch two apps at the same moment and the same screen.
I want to use this new feature of Android 7, Is it possible?
You can use Accessibility API for such feature. It doesn't require any permissions.
android.accessibilityservice.AccessibilityService has following apis:
service.performGlobalAction(GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN) which you can use to initiate split screen mode.
public List<AccessibilityWindowInfo> getWindows () to check wether split screen mode is on. Look for a window with AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER
You also will need to play with intent flags when launching activities.
val options = ActivityOptionsCompat.makeBasic().toBundle()?.apply {
putInt(
ActivityOptionsFlags.KEY_LAUNCH_WINDOWING_MODE,
ActivityOptionsFlags.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
)
putInt(
ActivityOptionsFlags.KEY_SPLIT_SCREEN_CREATE_MODE,
ActivityOptionsFlags.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT
)
}
startActivities(listOf(intentBottom, intentTop).toTypedArray(), options)
Using this accessibility apis and intent flags you can achieve your goal. Consult this repo by stavangr for detailed implementation.
https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html
Related
My Android app features a text input box that has a button on the right of the EditText to call the voice-input feature.
I am porting the app with Codename One. At present time the iOS port is the goal.
The button has a suitable icon. This is the code:
voiceInputButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
try {
activity.startActivityForResult(voiceIntent, RESULT_SPEECH_REQUEST_CODE);
} catch (ActivityNotFoundException ex) {
}
}
});
It works very well, the voice-input screen is called and then the result is passed back to the app as a string.
The string is what the user said (for example, a single word).
I need to have this functionality in the CodenameOne app for iOS.
What should be the equivalent? Is it necessary to call native iOS functions, through the native interface?
You can implement speech-to-text via Speech framework, to perform speech recognition on live or prerecorded audio. More info: https://developer.apple.com/documentation/speech
About Codename One, you can create a native interface using Objective-C code.
To use the Speech framework with Objective-C, see this answer:
https://stackoverflow.com/a/43834120
The answer says so: «[...] To get this running and test it you just need a very basic UI, just create an UIButton and assign the microPhoneTapped action to it, when pressed the app should start listening and logging everything that it hears through the microphone to the console (in the sample code NSLog is the only thing receiving the text). It should stop the recording when pressed again. [...]». This seems very close to what you asked.
Obviously the creation of the native interface takes time. For further help, you can ask more specific questions, I hope I have given you a useful indication.
Lastly, there are also alternative solutions, again in Objective-C, such as: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/objectivec/ios/from-microphone
You can search on the web for: objective-c speech-to-text
I want to open another app in a second screen(POS) so kindly help me to run another app in side second screen. I got the code for Oreo but I need this to work from Lollipop to latest.
ActivityOptions options = null;
Intent launchApp = MyApplication.getInstance().getActivity().getPackageManager().getLaunchIntentForPackage(packageInfo.packageName);
launchApp.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
options = ActivityOptions.makeBasic().setLaunchDisplayId(1);
MyApplication.getInstance().getActivity().startActivity(launchApp, options.toBundle());
}
}
Android did not support showing multiple apps very well back on Android 5.0. All that you could do was:
Have one app use both screens, either by default mirroring or by using Presentation; or
Use something like my PresentationService to have your app use the secondary display from the background, while a "regular" app uses the primary display
You may wish to discuss your ideas with the device manufacturer, to see if they have other device-specific alternatives.
I have published my app now and found that it is creating two shortcut icons where as when I install through android studio it creates only one shortcut. I have added duplicate false and sharedpreference has also been used to check once icon is created. Why the app behaving different and how can I fix it now? This is my code for creating shortcut.
public void createShortCut() {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(StartupActivity.this).edit();
editor.putBoolean("shortcut", true).apply();
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Smart App");
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashScreen.class));
sendBroadcast(shortcutintent);
}
and before calling above method I have below code which runs on activity start.
if (!sharedPreferences.getBoolean("shortcut", false)) {
createShortCut();
}
When you install from Android Studio (directly from an .apk), no shortcut is made. However, apps installed from the Google Play Store will automatically sometimes create a shortcut after installation.
So when a user installs your app from the play store, two shortcuts are made, one from your app and one from the installation.
EDIT: This solution might prove useful to you: How to detect shortcut in Home screen
I'm building a Cordova app and using the excellent cordova-music-controls-plugin to create a notification card with pause/forward/etc. controls.
https://github.com/homerours/cordova-music-controls-plugin
The icon it uses looks pretty naff and if like to switch it out for the ones used on Google's material design icons site.
https://www.google.com/design/icons
I'm very confident with the JavaScript and HTML side of the app, but to make this change I need to edit some Android (I assume Java) code.
Can anybody help by letting me know:
- where I need to import the icon files
- how I reference then in the plugin code
/* Pause*/
nbControls++;
Intent pauseIntent = new Intent("music-controls-pause");
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 1, pauseIntent, 0);
builder.addAction(android.R.drawable.ic_media_pause, "", pausePendingIntent);
You only have to fork the plugin, and replace the icon for the one that you want, keeping the file format, size and name
I'm trying to make a button in my App open the built in gallery.
public void onClick(View v) {
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
I'm trying to make a button in my App open the built in browser.
Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.
I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.
However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.