no apps can perform this action android studio - java

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.

Related

How do you change the default dialer package in android studio?

I'm currently trying to change the default dialer package of the machine to my application. When running the code that is supposed to change it, however, it results in the default dialer package retaining a value of NULL. This is loosely following the guide here, but some of it is deprecated so I've had to make some adjustments.
EDIT: has REQUEST_CODE_DEFAULT_DIALER been changed somehow? I can't find it referenced anywhere other than outdated tutorials on how to do this, so I'm not sure what it would even have been changed to. I'm getting a "cannot resolve symbol" error whenever I try to use it.
I've included the following under the relevant activity in my AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme = "tel"/>
</intent-filter>
The following code executes the package change and then prints its value to logcat so I can see what happens:
Log.i("Before", "Before default dialer change");
startActivity(new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,getPackageName()));
TelecomManager telecomManager = ((TelecomManager) getSystemService(Context.TELECOM_SERVICE));
if(telecomManager.getDefaultDialerPackage() == null) {
Log.i("Default dialer package:", "NULL");
} else {
Log.i("Default Dialer Package:", telecomManager.getDefaultDialerPackage());
}
I'm getting "Default dialer package:: NULL" in logcat every time I try this.
Intents are asynchronous. If you start an activity to do something, you have to wait for that intent to finish before using the results of it. You're instead immediately querying for the default dialer package. That will always fail, because it wouldn't even have shown the picker on screen yet.

Google Assistant ignores homescreen shortcuts

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>

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.

Restore android app stack from background

Lets say I launch my app from the home screen, navigate through some activities, then I press the home key and do something else in the Gmail app.
After i'm done checking my mail,I press the home key again to leave the Gmail app and click my app's icon at the home screen again to return to it.
When I return to my app, I want it to return to the last activity I was at, NOT start a whole new session. I've been trying to figure this out all day.
My manifest for my first activity is as follows:
<activity android:name=".Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The category attribute LAUNCHER makes my app ALWAYS start at activity Main, so I don't know how to go about restoring the last activity. People have told me to use sharedpreferences to save the last activity and load it on Launch, but I don't think it's intended to be done that way because it isn't very elegant.
I think its the only way because what happens when you're launching an app is that Launcher application sends intent "android.intent.action.MAIN" And the only activity in your app that responds to this intent is your main activity, thus it gets activated. So the only thing you can do is save somewhere your session and on activity start up if there's already saved session restore the app to the previous state.
Try using one of these in your manifest :
<activity android:launchMode=["multiple" | "singleTop" |
"singleTask" | "singleInstance"] ...
Are onResume() and onPause implemented properly?
protected void onResume(){
super.onResume();
}
protected void onPause() {
super.onPause();
}

Categories

Resources