I am facing problem to work with VoiceInteractor. Here it my Manifest part:
<activity android:name=".ProductSearchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
And in the Activity,
#Override
public void onResume() {
super.onResume();
if (isVoiceInteraction()) {
getVoiceInteractor().submitRequest(new VoiceInteractor.PickOptionRequest(prompt, optionArr, null) {
#Override
public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
if (finished && selections.length == 1) {
showResult(selections[0].getIndex());
}
}
#Override
public void onCancel() {
getActivity().finish();
}
});
}
}
Whenever I am starting my app using "OK Google, search Jackets on MYCART", it starts the application, but isVoiceInteraction() is always returning false and getVoiceInteractor() is always returning null even if I am starting the app by google search. Can anyone help me on that?
Related
I'm using intent filter for catching a custom scheme for my app:
<activity
android:name=".activities.MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/title_my_activity"
android:launchMode="singleTop"
android:noHistory="true"
android:screenOrientation="portrait">
<!-- myapp://app.open -->
<intent-filter android:label="#string/my_intent">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
<data android:host="app" />
<data android:host="app.open" />
</intent-filter>
</activity>
In my activity I override:
#Override
protected void onNewIntent(Intent intent) {
Log.d("DEBUG", "New intent!");
super.onNewIntent(intent);
}
but this is never called...where am I wrong?
Is noHistory flag necessary? If I remove that, I've two copies of the same activity on the stack.
Below code is working fine for me
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<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" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
<data android:host="app" />
<data android:host="app.open" />
</intent-filter>
</activity>
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("DEBUG", "New intent!");
}}
I referred sample application code (https://github.com/googlesamples/android-DirectShare) and I added ChooserTargetService to my application
public class ShareChooserTargetService extends ChooserTargetService {
#Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
IntentFilter matchedFilter) {
Log.d("ShareChooserTargetService", "onGetChooserTargets: ");
ComponentName componentName = new ComponentName(getPackageName(),
ShareActivity.class.getCanonicalName());
ArrayList<ChooserTarget> targets = new ArrayList<>();
for (User user : Users.getAll()) {
Bundle extras = new Bundle();
extras.putInt("user_id", user.id);
targets.add(new ChooserTarget(
user.name,
Icon.createWithResource(this, R.mipmap.ic_user),
componentName,
extras));
}
return targets;
}
In Manifest file I added these lines:
<activity
android:name=".ui.ShareActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value=".ShareChooserTargetService" />
</activity>
<service
android:name=".ShareChooserTargetService"
android:label="#string/app_name"
android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
<intent-filter>
<action android:name="android.service.chooser.ChooserTargetService" />
</intent-filter>
</service>
But ShareChooserTargetService is not called, log isn't printed. I run sample application in my phone and it works perfectly but these code in my app isn't working. I am unable to find what is the issue. Can anyone help please?
I am using android studio and playing around with CsipSimple. I am trying to figure out the flow for an outgoing call.
There is a method called Place call, which triggers the intent that handles the action ACTION_CALL for the scheme csip
#Override
public void placeCall(String number, Long accId) {
if(!TextUtils.isEmpty(number)) {
Intent it = new Intent(Intent.ACTION_CALL);
it.setData(SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, SipUri.getCanonicalSipContact(number, false)));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if(accId != null) {
it.putExtra(SipProfile.FIELD_ACC_ID, accId);
}
getActivity().startActivity(it);
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
resetInternals();
}
Here is the declaration of activity in the manifest, that handles the action
<activity
android:name="com.freemobile.ui.outgoingcall.OutgoingCallChooser"
android:allowTaskReparenting="false"
android:configChanges="orientation"
android:excludeFromRecents="true"
android:label="#string/call"
android:launchMode="singleTask"
android:permission="android.permission.USE_FREEMOBILE_SIP"
android:process=":sipStack"
android:taskAffinity=""
android:theme="#style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="android.phone.extra.NEW_CALL_INTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
</activity>
I have put a debug point in the onCreate method of the activity OutgoingCallChooser. But it never comes there. Please help me. am i missing something obvious?
You should override onNewIntent in your activity:
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
//Do something
}
More information here:
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
I have added the following code to my manifest file:
<activity
android:name="com.example.123.scan"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.scan" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Every time I start my app.
I could not get the intent of NFC that I need to proceed.
public void onResume() {
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
String sss=getIntent().getAction();
Toast.makeText(this,sss, Toast.LENGTH_SHORT).show();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(sss)) {
Toast.makeText(this, "NDEF", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(sss)) {
Toast.makeText(this, "TAG", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(sss)) {
Toast.makeText(this, "TECH", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
}
Every time, it toasted android.intent.action.scan instead of the NFC intent.
What is the problem?
I created an Android Library for easy NFC on android, check it out it might be an easy solution - link
Roger,
I see that you've been tinkering with camera intents. I'm having real trouble just getting
a simple app to tell me when the camera button has been pressed. Do you have some code to help me on my way.
Thanks.
David
In the manifest, you need to state you want to receive the intent for the camera button:
<receiver android:name="domain.namespace.CameraReceiver">
<intent-filter>
<action android:name="android.intent.action.CAMERA_BUTTON"/>
</intent-filter>
</receiver>
<activity android:name="domain.namespace.MyCameraActivity"
android:label="#string/app_name" android:screenOrientation="landscape" android:icon="#drawable/camera"
android:clearTaskOnLaunch="true">
<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>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the receiver:
public void onReceive(Context context, Intent intent) {
KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
}
//prevent the camera app from opening
abortBroadcast();
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClass(context, MyCameraActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}