I have created a custom ui and making a call using telecom manager for direct dialing. But every time Device default Calling UI is opening.
Here is some code for making calls directly...
TelecomManager telecomManager=(TelecomManager)getSystemService(Context.TELECOM_SERVICE);
Uri uri = Uri.fromParts("tel", phonenumber, null);
Bundle extras = new Bundle();
extras.putBoolean(TelecomManager.METADATA_IN_CALL_SERVICE_UI, true);
extras.putBoolean(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,true);
try {
if (telecomManager!=null) {
telecomManager.showInCallScreen(true);
}
}catch(SecurityException incoming){
incoming.printStackTrace();
}
try {
if (telecomManager!=null) {
telecomManager.placeCall(uri, extras);
}
}catch(SecurityException unlikely){
unlikely.printStackTrace();
}
is there a way to hide the default calling ui and use our own calling ui.?
Any help will be appreciated.
See the API docs on how to use the placeCall API. METADATA_IN_CALL_SERVICE_UI should not be passed to placeCall, and EXTRA_PHONE_ACCOUNT_HANDLE is not a boolean extra. You need to pass in a PhoneAccountHandle. However, if you're just trying to place a regular mobile call, just omit that extra as the system will pick the right one.
showInCallScreen should also only really be used by the Dialer app to bring its UI to the foreground; its not going to have any impact in your case.
If you want to use your Dialer app as the in-call UI, you need to change it in the system settings.
System Settings --> Apps & Notifications --> Advanced --> Default Apps --> Phone App. Choose your app there.
To be a default phone app you need to handle the DIAL intent and implement the InCallService API.
Related
The problem seems to be known, but I could not find the right solution.
I will describe the scenario:
There is an application making requests to the API. In some FirstActivity, a request is made to the API, upon positive result of which startActivity () is called in SecondActivity. The problem is that if, while sending the request, the application is minimized to the background (that is, startActivity () will be called in the background), then:
If android version> = 29 then startActivity () basically won't work. The one following startActivity () finish () will work and upon restarting the application will restart (which is logical)
If the android version is < 29, then startActivity () will fire and bring this SecondActivity to the foreground.
Based on this, the question is. How can I force the application, regardless of version, to transition between activities and not bring them to the front?
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
finish();
As per documentation
Android 10 (API level 29) and higher place restrictions on when apps
can start activities when the app is running in the background.
Workaround : In specific situations, your app might need to get the user's attention urgently, such as an ongoing alarm or incoming call. You might have previously configured your app for this purpose by launching an activity while your app was in the background.
To provide similar behavior on a device running Android 10 (API level 29) or higher, complete the steps described in this guide.
you can show a high-priority notification with a full-screen intent.
More Details
Updated answer for new requirement: For your comment
(Well, please tell me how to make startActivity () in the background start the activity also in the background, and not raise the application from the background)
you can add a LifecycleObserver that will be notified when the LifecycleOwner changes state.
Inside your activity api response callback use the following condition
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
// Activity is in resumed state, Open new activity immediately
} else {
// else add a LifecycleObserver that will be notified when the LifecycleOwner changes state
lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
// remove observer immediately so that it will not get triggered all the time
lifecycle.removeObserver(this)
// Activity is in start state again, Open new activity here
}
})
}
I'm developing an application that among other things , lets user interact with it by voice recognition (Speech to Text).For example user speaks the word "contacts" and the application can recognize and proceed to use logic to it to do something (i.e get the list of contacts and present them).
Now I have used a custom speech Recognizer , and not the one Google provides with the alert dialog.
I also have an animated gradient as a background with some colors.
From the RecognitionListener we get either an error as a response or we get results from the method onResults(Bundle results).In both cases after the response i need to restart the listener in order for the user to continue to interact with the application. However, when my speechRecognition is destroyed and created again, my application "blinks"(very quick black screen, but then the Ui is returned to normal).
I know that the problem is happening because i try to destroy my speechListener and then i re-create it(By calling the function restartSpeechListener), but i cannot seem to find a way to solve this "blinking".
Below is my code for the speechRecognizer initiation and restart :
public void startRecognising() {
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mySpeechRecogniser listener = new mySpeechRecogniser();
Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
"el");
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
mSpeechRecognizer.setRecognitionListener(listener);
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
startActivity(mSpeechRecognizerIntent);
}
// Restart speech recogniser
public void restartSpeechListener() {
mSpeechRecognizer.stopListening();
mSpeechRecognizer.destroy();
startRecognising();
}
Any suggestions or help would be very helpful !
I have a mobile app (kotlin/android studio) does not have an activity openned. This is a background service.
My app is connected by socket with my server. Via this server, I can ask to the mobile app to start an another app.
I found the code to do that and this works well. But I have a problem. I need to turn on my screen when I start a new app.
I have seen many solutions with different flags to setwith getWindow(). But getWidnow() works only on an activity class.
So can I turn on the screen in a class which does not inherit "Activity"?
If this is possible, can you explain me how?
Thank you.
var intent = contextTmp.packageManager.getLaunchIntentForPackage(packageName)
if (intent == null) {
// Bring user to the market or let them choose an app?
intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("market://details?id=$packageName")
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
contextTmp.startActivity(intent)
I have the following code:
https://github.com/lucas-kejan/React-Widget/blob/master/android/app/src/main/java/com/androidwidgetpoc/BackgroundTaskBridge.java#L26
That should add the widget to the android home screen, when the method is called, but it does not work.
It gives me the following error:
lenght = 0; index = 0.
BackgroundTaskBridge.java:31
Well, let's take a look on things that you want to do - let user to pick widget and take a place in launcher. If you want to make it pre Oreo devices, where is no api for following action. So to run PICK_APPWIDGET intent you need appWidgetId. The only way to get appWidgetId by yourself is to bind id to appWidgetInfo, but this thing requires BIND_APPWIDGET permission, which is only available to system. So on pre Oreo device it's impossible to make a thing that you want (of course if you're not a system app).
On Oreo devices we have a new pinning widget api.
AppWidgetManager mAppWidgetManager =
context.getSystemService(AppWidgetManager.class);
AppWidgetProviderInfo myWidgetProviderInfo = new AppWidgetProviderInfo();
ComponentName myProvider = myWidgetProviderInfo.provider;
if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
// Create the PendingIntent object only if your app needs to be notified
// that the user allowed the widget to be pinned. Note that, if the pinning
// operation fails, your app isn't notified.
Intent pinnedWidgetCallbackIntent = new Intent( ... );
// Configure the intent so that your app's broadcast receiver gets
// the callback successfully. This callback receives the ID of the
// newly-pinned widget (EXTRA_APPWIDGET_ID).
PendingIntent successCallback = PendingIntent.createBroadcast(context, 0,
pinnedWidgetCallbackIntent);
mAppWidgetManager.requestPinAppWidget(myProvider, null,
successCallback.getIntentSender());
}
Don't forget that it requires api version 26+. You can check documentation of following api here
I'm working on an android application which is basically a service to convert speech in to text as a background process, I'm getting help from How to register a custom speech recognition service? but I'm unable to know when onStartListening() is called.
Signature:
protected void onStartListening(Intent recognizerIntent, Callback listener)
Can any one can help or help me add more statements in the code given in that link so that I can recognize the speech in to text and show it in the toast?
In general, there are 2 kinds of apps:
apps that direct the user to convert audio into text, but don't actually implement the speech recognition part but just do the UI part (microphone button, VU visualizer) (let us call them app1);
apps that actually convert audio into text, either on the device or by calling a cloud service, and to make themselves available to app1, they extend RecognitionService (let us call them app2).
Since you mention "toast" (i.e. a UI element), I guess you want to implement app1?
app1 needs to do the following:
Intent intent = ...
SpeechRecognizer recognizer = ...
recognizer.setRecognitionListener(new RecognitionListener() { ... });
recognizer.startListening(intent)
Based on the specified intent and taking into account the user settings, Android finds a suitable app2 to service app1.
app2 extends the abstract class RecognitionService, i.e. it needs to implement a bunch of methods, among them onStartListening. The latter is called by Android when app1 calls startListening.
As the author of app1 you just need to provide the input details to the recognizer using the various intent extras, provide the handling of the output of the recognizer using the methods of the interface RecognitionListener, and start the app2 using startListening.