How to create private notes with android Memo App - java

I'm building an android app which provides the ability to create notes.
For this purpose I start next activity:
Intent notepad = new Intent(Intent.ACTION_MAIN);
notepad.addCategory(Intent.CATEGORY_LAUNCHER);
notepad.setPackage("com.sec.android.app.memo");
// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(notepad, PackageManager.GET_INTENT_FILTERS);
boolean isIntentSafe = activities.size() > 0;
// Start Notepad if it's safe
if (isIntentSafe)
{
startActivity(notepad);
}
The code works fine and native Memo App is launched successfully.
However, the notes I wrote in Memo from my App are visible when I launch Memo App from the desktop, and I would like that those notes would be private and it only be visible from my App.
This feature (create private notes) is available for iPhone Apps by NoteViewController class.
Does anyone know if that is posible for android App?
Thanks in advance.

No, the app has to be written with this usecase in mind. Memo wasn't. Also, memo is not available on all phones- many phones replace it with other apps with similar purpose. Some don't have a memo app at all. In fact most don't- the sec in your package name is Samasung Electronics Corp, that app will only appear on Samsung phones (and not all of them).

Related

Why code for capturing video is not working in one plus?

I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}

Text to Speech Android Studio

I am trying to do a TTS app for Arabic however whenever I want to initialize my TTS it always fails. I have no idea what I'm supposed to do to fix it. I tried to enter the TTS engine on the emulator but it doesn't show me anything. So I'm unsure whether the issue is from the emulator or my code.
TTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status==TextToSpeech.SUCCESS){
int res = TTS.setLanguage(Locale.forLanguageTag("ar-XA"));
if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("TTS","Language not Supporter");
}
else{
speak.setEnabled(true);
}
}
else{
Log.e("TTS","Init Failed");
}
}
});
This is some information that may help you get TTS working on an android emulator.
When I first tried your code I got the LANG_NOT_SUPPORTED error but soon realized my particular emulator instance did not have an TTS engine installed.
To install a TTS engine with an emulator I then had to use an emulator with Google Play (only a small subset of the AVD emulators have them). From the Android Virtual Device Manager you can Create Virtual Device and see (under phone for example) a few with Play Store: Pixel 4, Pixel 3a, Pixel 3, Pixel, Nexus 5X, Nexus 5.
I then used the Nexus 5 with API 25. (I already had it created.)
With the the emulator running I can then see the Play Store app listed. Run the Play Store app as you would on a phone (you'll have to authenticate yourself with your google account just as you would on a phone). Use the search bar and search for "speech services by google" - and install this app if not already installed. This is one TTS engine example which worked for me. Since this is the only TTS engine installed it is also the default. So if you choose to load other engines then you would have select the proper engine. (The engine name is a package name such as com.google.android.tts.)
I then ran your code (slightly modified) as in the following. I added some diagnostics to list the available languages and variants. I also reviewed the available languages and regions here: https://cloud.google.com/speech-to-text/docs/languages and for example just chose "ar-iq" (but "ar" also worked).
Note your "ar-XA" is a language tag used for voices and not for the engine language.
TTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status==TextToSpeech.SUCCESS){
Set<Locale> avail = TTS.getAvailableLanguages();
for (Locale locale : avail) {
Log.e(TAG,"local: "+locale);
if (locale.getDisplayVariant() != null) {
Log.e(TAG," var: "+locale.getVariant());
}
}
List<TextToSpeech.EngineInfo> engineInfo = TTS.getEngines();
for (TextToSpeech.EngineInfo info : engineInfo) {
Log.e(TAG,"info: "+info);
}
int res = TTS.setLanguage(Locale.forLanguageTag("ar-iq"));
if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("TTS","Language not Supporter");
}
else{
//speak.setEnabled(true);
TTS.speak("اَلْعَرَبِيَّةُ", TextToSpeech.QUEUE_ADD, null);
}
}
else{
Log.e("TTS","Init Failed");
}
}
});
Once you have the TTS engine installed and your code or above code works - I think you can then use Settings to install your voice data:
Settings | Speech | Text-to-speech output | (choose Speech Services by Google) and select the gear icon | and select your voice data.
You could also use the voice data programmatically.
Note you can install another TTS engine (not the default) by using the constructor:
TextToSpeech(Context context, TextToSpeech.OnInitListener listener, String engine)
The Arabic voices which come with the Google TTS engine have the following language tags - I'm guessing that when the language is set a preferred voice is used which is one of these:
ar-xa-x-arz-local
ar-xa-x-arc-local

How launch 3rd-party app on dedicated area of screen in Android 9?

I would like my Android app to launch another app on a dedicated area of the screen, i.e. set the screen bounds within which the other app will be displayed. Below is a screenshot with an example of how this could look, where I have launched Google Maps overlaid on my app:
This is achieved by the following code:
final String packageName = "advanced.scientific.calculator.calc991.plus";
new Handler().postDelayed(() -> {
final int[] location = new int[2];
containerLayout.getLocationOnScreen(location);
final Rect appBounds = new Rect(location[0], location[1],
location[0] + containerLayout.getWidth(),
location[1] + containerLayout.getHeight());
final ActivityOptions launchOpts = ActivityOptions.makeBasic();
launchOpts.setLaunchBounds(appBounds);
final Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent, launchOpts.toBundle());
}, 5000);
The above result would be satisfactory, however this is run on a Samsung Galaxy S10 device running Android 10. Now, I need to be able to achieve a similar result using Android 9. I have looked into the picture-in-picture and freeform modes, but I have not managed to use the former for this purpose, and the latter unfortunately only seems to be available from Android 10 and up. I am open to any solution for this, including creating a launcher app, etc. I am also looking to maximize compatibility with third-party apps.
What are the possible ways to achieve this on Android 9?

How does Facebook add badge numbers on app icon in Android?

I know there are several Qs here that ask if its possible to add badges to an android app and they all end up with a NO answer...
But somehow the latest Facebook beta version for Android seems to do something which at least look like a badge even if it is not technically exactly that.
In that post one of the commenters says that it is somehow related to TouchWiz.
And also here they mention it as a feature of the "S3 TouchWiz Jelly Bean Addon".
I still would appreciate information on how does this can be done and if there is some API for this that I can use in my own app (when running in an appropriate environment - i.e. the same device where FB demonstrates this behavior) ?
Hi you can use this lib simply.
Support : Sony,Samsung,LG,HTC,Xiaomi,ASUS,ADW,APEX,NOVA,Huawei,ZUK,OPPO
ShortcutBadger
Add :
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
Remove :
ShortcutBadger.applyCount(context, 0);
I have figured out how this is done for Sony devices.
I've blogged about it here. I've also posted a seperate SO question about this here.
Sony devices use a class named BadgeReciever.
Declare the com.sonyericsson.home.permission.BROADCAST_BADGE permission in your manifest file:
Broadcast an Intent to the BadgeReceiver:
Intent intent = new Intent();
intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");
sendBroadcast(intent);
Done. Once this Intent is broadcast the launcher should show a badge on your application icon.
To remove the badge again, simply send a new broadcast, this time with SHOW_MESSAGE set to false:
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
I've excluded details on how I found this to keep the answer short, but it's all available in the blog. Might be an interesting read for someone.
There is not a standard way to achieve this; Many makers such as Sony or Samsung have implemented it in their own Android customization.
For example in Samsung, you have to broadcast an intent with BADGE_COUNT_UPDATE action, let MainActivity be your main activity class and count be the number you want to display in your app icon, note that 0 will hide the badge:
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", MainActivity.class.getName());
context.sendBroadcast(intent);
Sony devices uses "com.sonyericsson.home.action.UPDATE_BADGE" action with their custom extras as #Marcus Answered, so you have to add "com.sonyericsson.home.permission.BROADCAST_BADGE" permission to your app manifest and:
Intent intent = new Intent("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", MainActivity.class.getName());
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(count));
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(intent);
Note: it's desirable to query your app's data (context.getPackageName(), MainActivity.class.getName()) rather than hardcode it just in case you do some refactoring in the future.
But somehow the latest Facebook beta version for android does just that...
Not according to the forum thread that contains the screenshot that you linked to. Quoting vakama94:
Well, that's actually TouchWiz and not just the app. I have a Galaxy S II running JellyBean 4.1.2 and it makes the same thing but with some other applications
Whether Samsung has a public API to allow apps to publish numbers to be used as badges, I cannot say. This could be something that they did privately with a few firms.
You are welcome to provide evidence of seeing these badges on a stock Android home screen, such as one of the Nexus series devices.
I answer to this assuming that some flutter dev can search this...
In Flutter, you can achieve this by using
Flutter app badger library.
It is as simple as
FlutterAppBadger.updateBadgeCount(1); // show
FlutterAppBadger.removeBadge(); // hide

How to add a widget to the Android home screen from my app?

I'm writing an application which should be able to add widgets (just text boxes) to the home screen of the user's phone when the user instructs my app to do so. How can I do such a thing?
I know that I can add an app widget but how about adding more?
It is not possible from a app to place a widget in the home screen. Only the home screen can add app widgets to the home screen.
similar links link1, link2, link3
But you can offer user to pick widget from widgetpicker.
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetID);
startActivityForResult(pickIntent, KEY_CODE);
This was answered a long time ago, but in case anyone stumbles upon this question I thought I should provide an up-to-date answer.
As of Android O (API 26), you can now pin widgets to the user's launcher from your app!
Simply create the widget in your app's AndroidManifest file and use AppWidgetManager to request that the widget be pinned to the launcher. Note that it is up to the launcher to support this feature, so you must call AppWidgetManager's isRequestPinAppWidgetSupported() method before requesting to pin it.
Here's some documentation from Google that goes into more detail: https://developer.android.com/preview/features/pinning-shortcuts-widgets.html#widgets
Hope this helps!
Edit: It looks like the documentation pages have changed since I posted this answer. Here is a more helpful link that gives a code example of how to pin a widget to a launcher: https://developer.android.com/guide/topics/appwidgets/#Pinning
Looks like Dalvik Droid's links are updated again, the newest link is at requestPinAppWidget
Example:
in MainActivity.java:
private void requestToPinWidget(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AppWidgetManager appWidgetManager =
getSystemService(AppWidgetManager.class);
ComponentName myProvider =
new ComponentName(this, AppWidget.class);
assert appWidgetManager != null;
if (appWidgetManager.isRequestPinAppWidgetSupported()) {
Intent pinnedWidgetCallbackIntent = new Intent(this, MainActivity.class);
PendingIntent successCallback = PendingIntent.getBroadcast(this, 0,
pinnedWidgetCallbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);
appWidgetManager.requestPinAppWidget(myProvider, null, successCallback);
}
}
}
Any anywhere in you code you have call requestToPinWidget() to prompt to see if the user wants to add it to the desktop.
Only thing is that this will not add to user's home screen, it will be appended to the page where you see all the apps:
AFAIK default launcher app does not support this. The reason is that user should place everything on the home screen himself. Allowing to place widgets from an application would open doors for apps to "spam" user's home with their "useful" widgets.

Categories

Resources