Running code via an application - android

So I am trying to build a simple app which runs a code that is typed in.
For example "*#06#".
I thought this was supposed to be done by using Intent.ACTION_CALL, since you run the code by typing it into the phone keypad.
The "#" character isn't shown when the call is made so it doesn't work.
Is there some other Intent or another way of writing "#" so that this can be done?

try this
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#60#"));
startActivity(intent);

Related

take screenshot from ACTION_DIAL intent -java android

i am amateur in android
i want to take a screenshot from dial activity of user`s phone,
i use this for going to dial page
Intent call = new Intent(Intent.ACTION_DIAL);
startActivity(call);
what is the best way for get screenshot without root? and we should write the code inside onPause() method? because our app is paused when we go to an intent
You can use this library for getting screen shot
Link
hope it help

Android UI transition not as expected

I am trying to launch an SMS app (Messenger/Hangouts) from my app. But the UI transition is not as expected. On launch, my app moves to the background and SMS app is launched from below the screen and this transition is slow and very much visible to the user.
I want the transition to be as fast as possible without showing any animation. I tried overridePendingTransition(0,0) and setting the Intent flag (FLAG_ACTIVITY_NO_ANIMATION), still does not help.
What should I be doing to acheive this?
This snippet of code works fine for me:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
overridePendingTransition(0,0);
startActivity(sendIntent);
Please paste the relevant code you have used for the same if the above does not work and I can look into it. Hope this helps!

Intent Action Call in Android 5

I have this code, that works fine in Android 4.4 and previous:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
Now, in Android 5.0 Lollipop this code doesn't work, and shows this exception:
Fatal Exception: android.content.ActivityNotFoundException
No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxx pkg=com.android.phone }
In the documentation, this Intent doesn't appear deprecated:
Any idea? Thanks in advance
Seems like the package name has been changed from
com.android.phone
to
com.android.server.telecom.
Hope this helps!
An alternative to using the action String manually encoded is to use the default intent like so:
Intent out = new Intent(Intent.ACTION_CALL );
out.setData(Uri.parse("tel:" + Uri.encode("+12345#123")));
startActivity(out);
This will pass the intent to the system and all apps with phone capability will respond instead of the specific one determined via the action String
This means you are trying to call com.android.phone but it's not there. No miracles. It's not gonna work. Either the package is named differently or you are using semi-backed emulator or so with missing stuff. Not to mention you must always have try/catch around startActivity() as there's no guarantee it gonna success (especially when targeting external packages)
This one worked for me on Android 4.4:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setPackage("com.android.dialer");
intent.setData(Uri.parse("tel:1111111111"));
startActivity(intent);
If using Eclipse, open the system dialer app and in DDMS, check for the name of the dialer package; in my case was "com.android.dialer".

Programmatically enter secret code like *#*#4636#*#* on Android

On many Android devices you can get into a secret settings menu from Phone app by typing in
*#*#4636#*#*
http://technology-headlines.com/2010/09/17/4636-android-secret-codes/
There are also some other codes.
Is it also possible to open this stuff programmatically?
I've tried this:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
But it just tries to initiate a phone call and of course fails, hangs up and closes the Phone app.
EDIT: The phone *#*#4636#*#* gets saved to my Contact list as "Unknown" but the call just fails. In fact, the secret code only works when you type manually on buttons in Phone app without pressing Call in the end. Is it probably just a hidden feature of Phone app which has nothing to do with calling?
If so, one could open the Phone app programmatically and simulate typing on the buttons.
According to this post
Programmatically press a button in another appplication's activity
this should NOT be possible because if any app on non-rooted phone could just start other apps and press something there, it could take over control of the whole device and do bad things.
Here are some more details but I guess the post is a bit old and even if it worked it may have been changed in current Android versions:
http://mylifewithandroid.blogspot.de/2009/01/generating-keypresses-programmatically.html
So, no easier way to enter secret code?
Is it also possible to open this stuff programmatically?
Yes:
Intent in = new Intent(Intent.ACTION_MAIN);
in.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(in);
You just need to watch logcat output to learn what this magic combination actually opens:
I/ActivityManager(31362): START {act=android.intent.action.MAIN
flg=0x10000000 cmp=com.android.settings/.TestingSettings} from pid
4257
Secret codes exist and work independent of the dialer application. The dialer application just provides a handy interface for these codes. It recognizes the special string and then calls a special intent to invoke the action. You shouldn't use the dialer to call these dialogs. Instead you can call the secret codes directly yourself like the dialer does internally:
Invoking built in secret codes:
What the dialer really does when you enter the code is extracting the number between *#*# and #*#* and then broadcasting the following intent:
sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://4636")));
Register your own secret codes (if you like):
You can even register your own secret code actions using:
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="4636" />
Source: http://android.amberfog.com/?p=422
Edit: Fixed a bug in the original code (see comment)
try this
String ussdCode = "*" +Uri.encode ("#")+"*"+Uri.encode ("#")+ "4636" + Uri.encode ("#")+"*"+Uri.encode ("#")+"*";
startActivity (new Intent ("android.intent.action.CALL", Uri.parse ("tel:" + ussdCode)));
finally you must encode '#' using Uri.encode()
ACTION_DIAL sends the user to the dialer with the given code (it does not call). So that would be :
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
It would appear that codes are to be dialed, rather than to be called
looking for this
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("com.android.settings", "com.android.settings.Settings$TestingSettingsActivity");
startActivity(intent);
There are different activities for different phone, we can jump to the activity through typing in ##4636##.
And use
adb shell dumsys activity activities
to find the realActivity package and name.
e.g: Xiaomi 8
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("com.android.settings", "com.android.settings.Settings$TestingSettingsActivity");
startActivity(intent);

android linkify intent

I have a ListView that uses Linkify to create a link to another activity in my app. the url looks something like content://com.myapp/activitiy/view?param=blah
this works fine every time.
however, in another view, I'm trying to call some code like this:
Intent i = new Intent("content://com.myapp/activity/view?param=blah");
i.setAction(Intent.ACTION_VIEW);
startActivity(i);
but for some reason this doesn't seem to work. It doesn't trigger my activity (and in fact it blows up if i dont include the setAction() call. How am I supposed to create the Intent such that it acts the same way that Linkify does...?
Now i realize i can setup the extras and then handle it in the activity, but that just seems like duplicated effort. So instead i'll spend the time it would have taken to do that, and post this question. SO any help much appreciated. :)
ah. just figured it out:
String uri = "content://...";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);

Categories

Resources