Google Assistant ignores homescreen shortcuts - java

I just added homescreen shortcuts to my app. They open an activity which will do some IoT stuff depending on the extra value.
I read I could integrate them to work with Google Assistant. In this example I want them to open when the user says something like: "Light", "Start light", "Start light shortcut", ...
But the assistant just ignores them. They don't show up in the assistant settings -> shortcuts either.
Later I created the shortcuts.xml and tried the test tool (I'm not even sure if this is necessary for pinned shortcuts).
I signed in with my account, entered the app name and clicked on "Run App Action". I'm not sure what to enter as "feature". I tried different things: to leave it empty, the app name, the name of the shortcut, …. The assistant always opens but shows the error "App isn't installed.".
The checkmark on the Play Console is activated but greyed out (Setup -> Advanced settings -> Actions on Google -> "Integrate my services with App Actions using Actions on Google
"). I never uploaded the app since creating the shurtcuts.xml.
Thanks for reading and answers!
android.useAndroidX=true
android.enableJetifier=true
.
dependencies {
implementation "androidx.core:core:1.9.0"
implementation "androidx.core:core-google-shortcuts:1.0.1"
...
}
.
Intent intent = new Intent(getActivity(), ShortcutActivity.class);
intent.putExtra("ID", id);
intent.setAction("ACTION");
ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(getActivity(), id)
.setShortLabel("Light")
.setLongLabel("Light")
.setIcon(IconCompat.createWithBitmap(bitmap))
.setIntent(intent)
.addCapabilityBinding("actions.intent.OPEN_APP_FEATURE")
.build();
ShortcutManagerCompat.pushDynamicShortcut(getActivity(), shortcut);
.
<activity
android:name="...MainActivity"
android:exported="true"=>
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.OPEN_APP_FEATURE">
<intent
android:targetPackage="com...appid"
android:targetClass="com...ShortcutActivity">
</intent>
</capability>
</shortcuts>

Related

no apps can perform this action android studio

Im new to this area, I have a mission, I have build up an application that register some data that I have insert.
lets call this app "A", now i copy the same app and called it "B".
In app "A" and "B" in the manifest file I write this:
<activity
android:name=".Register"
android:exported="false">
<intent-filter>
<action android:name="com.action.ex3.register" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now in app "C" I want to use what app "A" or "B" doing, in order to to that in the app "C" I write this:
public void registerBtnClicked(View view) {
Intent intent = new Intent(); //implicit activity.
intent.setAction("com.action.ex3.register");
startActivityForResult(intent, REGISTER_ID);
}
what I expected that will happen it that when I press in my app "C" on the regiser button a pop out with a "chooser dialog" with option to choose "A" or "B", but instead of that I got "chooser dialog" with "no apps can perform this action android studio"
what im doing wrong?
here a picture of the problem
App C "no apps can perform this action android studio"
Im using pixel emulator in android studio IDE.
Your activities are not exported. They cannot be accessed from other apps. Change android:exported to be true if you want other apps accessing your activities.

Android createChooser appear in front of Activity

I'm hoping one of you fine folk may be able to help me out with a little issue I am having whilst using Android Intent.createChooser(). I am learning as I go with my application so I apologise if I have the wrong end of the stick with how this should work!
I have been following a number of tutorials and have implemented some code which starts an Intent.createChooser() to share a picture to social media. The code that I have used works fine in that I am able to share the picture as I intended, my issue is that when the code is run my main activity (or any activity I call the code from) appears to close and the chooser appears in front of the homescreen or any other applications I may have open. The effect that I was hoping to have, and the one which seemed to be apparent in the tutorials, is for the chooser to appear in front of the running activity (eg as it does for the gallery).
I am using LibGDX meaning that I have had to use an interface to call the android function that executes the chooser code (in my AndroidLauncher java file). The interfaces all work fine but I wasn't sure if that may have a bearing on the way in which this code operates. I have also played around with swapping to a new activity to implement the chooser code, which I had moved from the AndroidLauncher. This had the same end result.
Any advice on how to make the chooser appear in front of my application would be greatly appreciated! The code which implements the createChooser is included below:
public void ShareHandler(){
String type = "image/*";
String mediaPath = Environment.getExternalStorageDirectory().getPath()+"/Smile.png";
createShareIntent(type, mediaPath);
}
private void createShareIntent(String type, String mediaPath)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(type);
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share to"));
}
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme">
<activity
android:name=".AndroidLauncher"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FacebookServiceHandler" />
<meta-data
android:name="come.facebook.sdk.ApplicationID"
android:value="#string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProviderxxxxxxxxxxxxx"
android:exported="true" />
</application>
</manifest>
Thanks in advance, Ben.
If
android:name=".FacebookServiceHandler"
is the activity, that handle the social media sharing of the picture, i would expand that to something like this:
<activity
android:name=".FacebookServiceHandler">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".AndroidLauncher">
</meta-data>
</activity>
This will tell the programm, that the AndroidLauncher is the parentactivity and should make it appear in front of your activity.
Thank you for the suggestions, I have now solved my issue. It turned out that my code was working correctly all along and the issue I was experiencing was as a result of an exit statement within my Core (LibGDX) java code. Essentially when the startActivity(Intent.createChooser(...)) was called, a dispose function within my core files was also being called. This dispose function contained the exit command and was causing the application to finish.

Detecting problems with my app using NFC TAG

I have developed an app which uses NFC function and got this TAG for my tests.
a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120054648901134.png
and its characteristics
a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120054925844663.png
All very well ..
and add the following lines in the config
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Add my code so that when it detects the nfc and select my app
Get the UID .. And makes it right. (Then find out if you can get the different fields such as text.)
Good. It works all right ..
my app blue http://nsae02.casimages.net/img/2014/11/19/mini_141119082121303903.png
my problem is then
That same edit it using NFC TAG TAG Writer application
a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120055409818122.png
a busy cat http://nsae02.casimages.net/img/2014/11/20/mini_141120055615627271.png
And I put a text and I go back to using my app but no longer appears in the list ..
Not my app http://nsae02.casimages.net/img/2014/11/19/mini_141119081714874308.png
Giving many turns and able to reappear in my app list formatting the NFC TAG
What am I doing wrong?
If I have not put enough information please ask me.
thank you very much
You need to setup proper intent filters that match the type of your tag. Currently you are using
an NDEF_DISCOVERED intent filter that won't trigger on most devices as it does not specify a data type, and
a TAG_DISCOVERED intent filter that is meant as a fall-back only when used inside the AndroidManifest.xml.
Consequently, what you experience is the fall-back behavior: While your tag does not contain an NDEF record, it will match the fall-back. As soon as you write a Text record to it, it will match all apps that registered for Text NDEF records and, therefore, won't trigger the fall-back anymore.
So, if you want to use a Text record on your tag, you could add the following intent filter for your activity:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Note that it is usually a bad idea to use Text records. First, they are meant for human-readable data only and, second, many apps register for them which makes it difficult for a user to select the right app in the activity chooser dialog.
This will still not catch the case where your tag does not contain any data (which is currently handled by the fall-back filter). In that case, you should use a TECH_DISCOVERED intent filter for the NfcV tag technology:
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/filter_nfc" />
And in your res/xml folder you would need to create a file named filter_nfc.xml with this contents:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcV</tech>
</tech-list>
</resources>
Or when you want to register for multiple different tag technologies:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcV</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
</resources>

Android app opening wrong page after using uri scheme

In IOS I have 2 apps (App A and App B) that will be performing different objective but at 1 point, App A will call App B using uri scheme to perform a function where App A does not have.
I wanted to implement this function to Android and currently have developed a demo for initiating call to App B. Now I am working on App B that will be receiving the uri scheme from the demo app.
Problem:
After App B return to the demo app using uri scheme I close the demo app.
When I go back to home page and open the multitask to reopen App B(or open App B through the icon), the page it reopen is the function that is used for demo app but what I wanted is the login page of App B.
This is a part of the Manifest for the intent-filter
<activity
android:name="com.apps.MasterActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="x-callback-url"
android:scheme="myapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
This is where I call back to the demo app
Intent sendIntent = new Intent(Intent.ACTION_VIEW, responseUri);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(sendIntent);
Try adding this to your activity tag in AndroidManifest.xml
android:clearTaskOnLaunch="true"
Apparently I kinda found a solution that can force the app to show the login page after going back to the demo app. By putting this code in the activity.java file.
#SuppressWarnings("deprecation")
#Override
public void onDestroy()
{
super.onDestroy();
System.runFinalizersOnExit(true);
System.exit(0);
}
I know its a deprecated function that I'm using but will try to solve it when there's something wrong in the future or when I found a better solution for it.
Edit:
Found a better solution that does not need to use the deprecated function which I have forgotten to set it to false.
I have a flag that is set to true when the app is connected through Uri Scheme which i just have to set it to false and it will be fixed. This is the change location that I made
Intent sendIntent = new Intent(Intent.ACTION_VIEW, responseUri);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(sendIntent);
Util.isUriScheme = false;

How can I get a number placed in a text message on Android?

I want to add a feature to my app that when I touch the number in a message, the user can decide to send the number to my app or Android Dialer.
For example my friend send me a code and i want to use this code for special ussd code that my app run it.
I think I have to use implicit intent but I don't know how?
Thanks
I have quoted the below links
-intent filter
-Intents implicit\explicit
Implicit intents specify the action which should be performed and
optionally data which provides data for the action.
For example the following tells the Android system to view a webpage.
All installed web browsers should be registered to the corresponding
intent data via an intent filter.
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.vogella.com")); startActivity(i);
If an Explicit intent is send to the Android system, it searches for all
components which are registered for the specific action and the
fitting data type.
If only one component is found, Android starts this component
directly. If several components are identifier by the Android system,
the user will get an selection dialog and can decide which component
should be used for the intent.
How to use
You can register your own components via Intent filters. If a
component does not define one, it can only be called by explicit
intent.
Register an activity as Browser
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
UPDATES
A code sample for mimeType
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
I assume you are talking about a number in a SMS that you received. On clicking that number you want the user to get an option to either dial or use your app.
If yes then you need to include intent filter in your manifest file for launcher activity.

Categories

Resources