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.
Related
Problem:
My Launching Activity creatively named LoadingActivity's onCreate method is called 2 times.
Manifest Content:
<manifest>
<application>
...
<activity
android:launchMode="singleTop"
android:name="com.awesome.app.activites.LoadingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
</manifest>
First onCreate call is called with Bundle savedInstanceState which is null, shortly after which the onCreate method is called again, but this time with Bundle savedInstanceState which contains the following serialized content:
Bundle[{com.google.app_measurement.screen_service=Bundle[{referrer_name=LoadingActivity, id=1612091517631091562, name=null}], android:viewHierarchyState=Bundle[{android:views={16908290=android.view.AbsSavedState$1#a24446f, 2131296302=android.view.AbsSavedState$1#a24446f, 2131296313=android.view.AbsSavedState$1#a24446f, 2131296424=android.view.AbsSavedState$1#a24446f, 2131296445=android.widget.ProgressBar$SavedState#b25257c, 2131296581=android.view.AbsSavedState$1#a24446f, 2131296582=android.view.AbsSavedState$1#a24446f}}], androidx.lifecycle.BundlableSavedStateRegistry.key=Bundle[{}], android:lastAutofillId=1073741823, android:fragments=android.app.FragmentManagerState#a24ee05}]
Yes, this doesn't mean much, but it may be related to something at the bottom of the post.
Tried:
I have tried setting launchmode settings with android:launchMode="singleTop" for the LoadingActivty in my AndroidManifest.xml, but this does not help at all, it still runs the onCreate 2 times.
I have gone through my onCreate method, no where do I onCreate again or change ApplicationContext settings i.e. Orientation (physically or programmatically), etc.
Any idea why this happens and what I can do to resolve it.
For what it is worth, I have recently updated my deps and see this in my Manifest:
It compiles (change the package name for obv reasons) with the portrait launchmode, but I think this may have something to do with the double launch
I am developing an application for searching for places. In the application there is a button where user can share a specific place with other user. I was thinking about sharing a link that when other user, "the invited one", clicks on it, my application opens on the shared place page. Just like Clash Royale game, if you know it. The idea is that. How can I do so? Does anyone have idea how to implement this?
Thanks in advance.
To achieve this you need to Create Deep Links to App Content
Code would be something like this:
1) Add intent filter in your activity
<activity android:name="...">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:scheme="schemeName" />
</intent-filter>
</activity>
2) Get data in you activity
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
3) Create sharable URL
eg - http://example.com?data=<your data to share>
4) Now you need to write some script for your page (http://example.com)
that will receive your header data and redirect to open app.
for this get some idea from here
* This is not a complete code but hope will help you.
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;
I have added my Android app to the "Share-Via" window. Following code is added to the onCreate() method of my code.
if(getIntent().getAction().equals(Intent.ACTION_SEND))
{
String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
textField.setText(text);
}
Now the issues is, if this app activity get called from the share-via, it works. But if it get called directly (user opens the app -> go to that activity) this crashes with NullPointerException. I am getting NullPointerException right in here
if(getIntent().getAction().equals(Intent.ACTION_SEND))
Following is how this Share-Via configured in the manifest file.
<activity
android:name="com.xx.xx.xx"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
What is the issue here?
Either getIntent() or getAction() is returning null.
You need to check for that.
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.