How to start specific activity by saying OK Google? - android

I would like to have two activities. FirstActivity should be started from
launcher (by tapping on icon) and SecondActivity should be started by voice
command (by saying "OK Google, start play example").
The problem is that for my current configuration only FirstActivity is
started. Also method isVoiceInteraction returns false. I also don't see any values in flags that indicates that activity was started by voice.
Here's part of AndroidManifest.xml:
<application android:label="play example">
<activity android:name="com.example.FirstActivity" android:label="play example">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.EXAMPLE_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.example.SecondActivity" android:label="play example">
<intent-filter>
<action android:name="com.example.EXAMPLE_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
</activity>
</application>
Here it states:
To specify the text to say after "Start", specify a label attribute for the activtiy that you want to start.
But when I change label for SecondActivity it does not help.
I'm using API version 26.
How to setup configuration to handle described behavior?

AFAIK isVoiceInteraction will always return false when the application is opened using "open" voice command. However, the scenario which you described, having another activity to respond to voice commands, should've worked.
The only thing that you might have missed is to put the action android.intent.action.MAIN in the second activity.

Related

Receive data intent opens second app when app is opened

<activity
android:name=".activitys.SplashScreen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
When app is sterted, trying to share the text and app is launching but if open pervious app by android navigation button i see 2 my app exemplars. How to check if app is launched and reopen not open second at one time
Simple answer: you need to add
android:launchMode="singleInstance"
within your activity bracket (below android:name=".activitys.SplashScreen", for example)
Better answer: Go through this article to understand the different types of launch modes: https://medium.com/#iammert/android-launchmode-visualized-8843fc833dbe
Best answer: Read through the doc on tasks: https://developer.android.com/guide/components/activities/tasks-and-back-stack

How to end a launcher completely?

My application works as a launcher. But, I guess I did something wrong by making it a launcher. For instance, the user selects my application as Default Launcher (clicks 'Always'). However, when the user exits from the application, it appears again, because it's the default launcher. How can I fix it?
<activity
android:name="com.comeks.cocuktablet.Main"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The code comes from my manifest. I also want to make MAIN activity launcher.
Edit:
I realized my exact error. I also wrote a code to start my app on boot. The problem is that when I close my device and open it again, I cannot exit from it.
Thank you for your all answers. I solved my problem by calling Android's home launcher while exiting from app.
Just remove
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
from intent-filter

android) can i set a default activity that runs right after installing

in my app, there is two activity and i want to make activity1 to the starting activity after installation.
But now the RUN button (is showed right after packgae installing) is disabled.
below is the manifest file. thanks.
<activity ...1>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity ...2>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</activity>
android) can i set a default activity that runs right after installing
No activity "runs right after installing". The user has to launch it from the launcher.
below is the manifest file
No, it is not. That is not even valid XML.
Also, note that your third <intent-filter> is invalid. Not only are you missing any category (you need at least DEFAULT for activities), but ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED are not activity actions.
I am going to take a guess that you really mean to ask: "I have two activities, both described as ACTION_MAIN/CATEGORY_LAUNCHER, and now the Run button does not work -- what can I do?" The answer would be "either remove the ACTION_MAIN/CATEGORY_LAUNCHER <intent-filter> from one of them, or mark one of the two as disabled (android:enabled="false") and enable it later on using PackageManager."
I think the problem is the second:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You shouldn't have 2 activities flagged as the MAIN and LAUNCHER activity.
Try removing it within activity2.
Check out: http://developer.android.com/reference/android/content/Intent.html the intentfilter s are discussed.

adding custom action won't start the activity when running it in the emulator

I have the following code in my Manifest:
<activity android:name="com.fletech.android.apparent.CategoriesGrid"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I run the app in Eclipse it starts this activity in the emulator, as expected.
But when I also add:
<action android:name="com.fletech.android.apparent.action.APPARENT_MAIN" />
right below the other action, and run the app, it only installs it to the emulator but doesn't run it. Why?
What I wanted to achieve is this: I would like to be able to show a dialog to the user (from another apps) to chose between all my apps that have "com.fletech.android.apparent.action.APPARENT_MAIN" as an action.
If you want to specify another launch scenario, you should just add another whole intent-filter block rather than putting all of the action clauses in the same one.

Android: proper intent-filter to indicate my application can open a filetype?

I am trying to configure my manifest file to indicate my application can open PDF files. The below configuration works, but it gives some funny behavior with the emulator:
When the "view" action is present, my application is not started on install (when I run from Eclipse, the application gets installed on the emulator, but it does not start automatically).
When application/pdf is present, after running from eclipse the application doesn't show up in my emulator's application menu.
(I don't see either of these issues if my only intents are "main" and "launcher")
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
EDIT: Okay, I was a little confused about intents. The solution to my above issues is to have 2 different intent-filters, as shown below.
However, I do have a second question. Android successfully launches my app for PDF files, but when it launches onCreate(bundle) is called and not startActivity(Intent). How should I get the intent data?
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
In your Activity, you can use getIntent() to get the intent used to start it.
startIntent() is not a callback. Its a method for you to call in order to launch another intent.
When your Activity is launched, you will get your onStart() (and onCreate, just before that), called, and from there you call getIntent() to re

Categories

Resources