I want to create an intent in android, which go to the timer application and input directly the numbers. I've tried this code, but it only starts the timer application, but not enter the numbers.
Intent intent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
intent = new Intent(AlarmClock.ACTION_SET_TIMER);
intent.putExtra(AlarmClock.EXTRA_HOUR,hour);
intent.putExtra(AlarmClock.EXTRA_MINUTES,minutes);
intent.putExtra(AlarmClock.EXTRA_SKIP_UI,true);
startActivity(intent);
}
Do you have any idea?
Thanks for every response.
AlarmClock.EXTRA_HOUR and AlarmClock.EXTRA_MINUTES are for AlarmClock.ACTION_SET_ALARM.
AlarmClock.ACTION_SET_TIMER only supports the extras AlarmClock.EXTRA_LENGTH, AlarmClock.EXTRA_MESSAGE and AlarmClock.EXTRA_SKIP_UI
I suppose you don't want to create a timer (a.k.a. a counter that counts the seconds from the start) but instead you'd like to create a countdown. For this, I'd use a CountDownTimer: https://developer.android.com/reference/android/os/CountDownTimer.html
You can even embed it in your own app instead of launching an external clock app.
As can be seen from the documentation here, the flag ACTION_SET_TIMER does not have the flags you are trying to use as optional request parameters. For the ones you are using you should be setting the ACTION_SET_ALARM flag.
Related
I need some help , I tram trying to close android settings, (com.android.settings (packageName)), but I can't find how can it be done, I am testing in android O , please suggest something , I tried to kill process but it did'nt work too ..
how can it be done ? )
You can use FLAG_ACTIVITY_CLEAR_TOP, you can read more about it in docs
If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
Here is an example
Intent i = new Intent(this, YOUR_ACTIVIRTY.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
I am trying to add a button in my application that starts Google Voice Typing (or the default speech recognition). I have tried following this tutorial. This tutorial is incredibly confusing to me. I imported the .jar, and added the necessary permissions, services, and activities to my Manifest. But I can't seem to figure out how to "put it all together". I'm wondering:
Am I supposed to call the inputMethodService from my button click in my Main Activity? Or does my inputMethodService essentially become my Main Activity?
What does IME mean? I tried to Google it, but the definitions it gave me didn't help my understanding.
When I try to copy and paste the whole DemoInputMethodService code into my current activity, I get an error saying I cannot extend InputMethodService inside of this activity. (Which leads back to to ask question one.)
How can I get this to work?
If you want to follow the tutorial that you mention then you need to implement an IME (input method editor) first, see http://developer.android.com/guide/topics/text/creating-input-method.html
This IME can have a regular keyboard look-and-feel or contain just a microphone button.
The user of your app will first have to click on a text field to launch the IME. (Note that there can be several IMEs installed on the device and they have to be explicitly enabled in the Settings.) Then the user will have to click on the microphone button to trigger the speech recognition.
The tutorial provides a jar that lets you directly call Google's recognizer. It would be nicer if instead you called the recognizer via the SpeechRecognizer-interface (http://developer.android.com/reference/android/speech/SpeechRecognizer.html), this way the user can decide whether to use Google's or something else.
The SpeechRecognizer is given a listener which supports the method onPartialResults, which allows you to monitor the recognition hypotheses while the user is speaking. It's up to you how you display them. Note however that the specification of SpeechRecognizer does not promise that this method gets called. This depends on the implementation of the recognizer service. Regarding Google's implementation: what it supports keeps changing unannounced, it does not have a public API nor even release notes.
You might be able to reuse my project Kõnele (http://kaljurand.github.io/K6nele/about/), which contains two implementations of SpeechRecognizer and an IME that uses them. One of the implementations offers continuous recognition of arbitrarily long audio input, using the Kaldi GStreamer server (https://github.com/alumae/kaldi-gstreamer-server). You would need to set up your own instance of the server porting it to the language that you want to recognize (unless you want to use the Estonian server that Kõnele uses by default).
Voice recognition samples are found where you have the android SDK..
example:
$ find $SDK_ROOT/samples -name *recogni*
./android-19/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-19/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-19/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-18/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-18/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-18/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-21/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-21/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-21/legacy/ApiDemos/res/layout/voice_recognition.xml
any one of the services should help show how to do a RecognizerIntent
The "APIDemo" seems to include use of a RecognizerIntent. check the source for that one. Otherwise look into the services and carve them up into an intent.
I had the same issue, but after a long time looking for continuous voice dictation on an activity, I solved that problem using pocketsphinx.
I couldn't find the way to integrate Google Voice Typing on an activity, just on an input method by following that tutorial. If it confuse you, just download this demo and modify it.
Good Luck!
You can trigger an intent from a button listener
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
And the result can be get from
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
Refer this link for more info.
Is where any function which returns Activities to foreground from Service?
I can move activities to background by moveTaskToBack(true);
How to return all activities back?
Intent dialogIntent = new Intent(service.getBaseContext(), class_);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
service.getApplication().startActivity(dialogIntent);
The code below just adds Acitivies to history and do not open them. Is it possible?
Yes, it is called moveTaskToFront()
I'm building an app for universal access, my app works in fullscreen with a custom dialer. So if users press home or back during a phone call I need to give them the opportunity to return the call somehow. (In fact I'm thinking about reopening the call in progress automatically if they leave).
I know how to start a call with a number but I don't know how to open the incall screen during a call, I tried doing an Intent.ACTION_CALL without a number but it initiates a second phone call on top of the other:
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"));
startActivity(callIntent);
I think this should be doen with an intent or by simply bringing it to front. But I don't know how to do it. How can I reopen a call in progress programatically?
if it's still relevant or for other people interested in this:
ACTION_CALL_BUTTON do exactly that.
if the call is in progress, it would bring it to the front, and if it's not, it would
bring the call log.
http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL_BUTTON
I found a different solution that seems to work well. I many combinations of Intents and also tried the ACTION_CALL_BUTTON as suggested above but in 4.3 it opens a new dialer and does not take you to the current call in progress. Not sure how this behaves in older sdks. After much research and tries I found this to work well, although it could probably use some optimizing...
telephonyManager = (TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE );
if( telephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK )
{
ActivityManager m = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = m.getRunningTasks( 10 );
for( int i = 0; i < tasks.size(); ++i )
{
RunningTaskInfo task = tasks.get( i );
ComponentName component = task.baseActivity;
String packageName = component.getPackageName();
if( packageName.contains( "com.android.phone" ) )
{
m.moveTaskToFront( task.id, 0 );
return;
}
}
}
You will also need to add the permissions to your manifest file:
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
I'm trying to port my iPhone Cocos2d game to Android using the Cosos2d for Android framework (Java).
I'm running into a problem when I start PreferenceActivity from my main activity. This is my setup:
(1) HelloWordActivity.java:
Inits the Cocos2d environment and starts GameLayer.scene
(2) Gamelayer.scene:
Presents the user with the game but also has a button to show the settingspane which gets called from the Gamelayer class like this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(helloworldactivity, ShowSettingsActivity.class.getName());
helloworldactivity.startActivity(intent);
This shows the Preference Activity just fine, but when closing the preferences and returning to my game it appears it did not persist (it get's reloaded/restarted and does not retain it's state).
How can I present the user with a standard Android preferences screen without destroying the current game session in Cocos2d ?
from the names of your classes , I'm assuming you used Dan's tutorial as a starter
make sure you remove dan's onStop() override method , that gets called when you are loading the preferences and it calls
CCDirector.sharedDirector().end();
removing this should do it for you
I did notice that you gave up and switched to andEngine , that's a nice engine too but I thought I'd answer this one anyway
You need to get the main activity to start new activity, I hope this code will help you
Activity context = CCDirector.sharedDirector().getActivity();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(helloworldactivity, ShowSettingsActivity.class.getName());
context.startActivity(intent);