I am trying to send a broadcast to simulate an incoming call.
I added the permission in AndroidManifest.xml file,
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
When I try to run the program, the phone reboots.(Emulator too).
Intent intent = new Intent();
intent.setAction("android.intent.action.PHONE_STATE");
intent.putExtra(TelephonyManager.EXTRA_STATE, TelephonyManager.CALL_STATE_RINGING);
intent.putExtra("EXTRA_INCOMING_NUMBER", "923982398");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendBroadcast(intent);
I may be wrong as I can't find anything in the docs but I'd say it's not possible to 'spoof' a call ringing broadcast. It's almost certainly reserved as 'system only'.
Think about it - if apps could do this, it may simply result in 'mischief' rather than anything malicious but it isn't something that I'd like to happen on my phone.
Create your own 'phone ringing' action to use for testing purposes and have your BroadcastReceiver listen for it. When you come to release the app then simply change the BroadcastReceiver's intent filter to listen for the real one.
I Downloaded some of the fake Caller Apps from play store and tested them.
I found that the App Raises an Event which displays the pre-mentioned GUI on the Top of Lock Screen and adds the entry into call logs using the insert method of ContentResolver.
The app does not use the inbuild Calling (Broadcast) mechanism. it just fakes the GUI on the Screen and plays the Default Ringtone/Vibration.
As per my Knowledge, I think it is not possible to fake a call ringing broadcast
Related
Originally, it received the BootComplete Action and tried to start automatically when the app completes booting. However, while checking because startActivity did not work, I found out that context.startActivity executed by the Action received from BoradcastReceiver does not work.
BroadcastReceiver
Intent startIntent = new Intent(context.getApplicationContext(),MainActivity.class);
startIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
It's a very simple code that I can't explain, but it gets Received, but the app doesn't start. The existing apps seem to work without problems. It feels like a ghost.
There is a log like this, but I don't know what the problem is.
D/BootReceiver: BootRecived
D/ZLA: Setting app side flag to false due to ActivityStarter-Normal Launch
Please add the following permission to manifest and ask for user permission once when the app opened the first time by calling
startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)); somewhere in your app :
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
if you are targeting/running on Android 10 then it isn't possible to startActivity, thats Android new policy (check out HERE)
now docs suggest to show Notification and user may pick it and this will start your Activity (or may remove it and your app won't start)
I have this piece of code
private void initiateInstallation() {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File("/sdcard/example.apk"));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
that from within my service installs an application named example.apk
I want after the installation is finished to run an activity which notifies the user about the installation.I did that except the activity appears before the installation finishes.
The problem is that within a service I cannot use startActivityForResult. So, I need a way around this so that I can start my notification activity(or for the sake of example just print something out with Toast within the service) only AFTER the installation is complete.
I already tried some answers from other questions like "alternative to startActivityforResult in services" but still I couldn't figure this out.
I also put the code so that maybe there may be something done in there.
Thanks in advance ... any suggestions are welcome.
You could listen to the PACKAGE_ADDED broadcast intent: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED
As far as I know, these are sent after the installation is done, and you can listen to those from the service.
Just note that if the application was already installed, you will get ACTION_PACKAGE_CHANGED (as far as I know).
Also you must know the package name as well, not just the apk name, since the intent will contain the package name.
The answer given by #Pal Szasz is technically correct (as far as I know ;-) ).
However, based on the information given in your question, I assume you only wish to show a notification (no further programmatically actions are to be performed). If my assumptions are correct I would respectfully advise you NOT to show such a notification. And this is why:
The Android system already has a standard means of passing notifications to the user. The status bar will in this case already show you a message saying that the new app is successfully installed (or not installed in case of an error). If you implement yet another notification channel you will most likely confuse or irritate your users by diverging from the standard, expected behaviour.
Taking this beyond the borders of sanity one could also argue for the fact that you in some sense also would contribute to the fragmentation of Android (in a very small scale, but nevertheless).
Is there an app or another possibility to watch for ALL Intents and Broadcast flowing in an android system?
Maybe another app which uses a special intent (not the standart ones) you want to use or broadcast yourself.
You can't listen to every Intent.
If you are worried that someone else uses your intent use your package name as prefix.
For example if you are willing to have an intent with the action SERVER_UPDATE, use: com.nitromouse.appname.SERVER_UPDATE
why not? Just list all permitted intents in the intent filters section. If you find that intimidating, write a program to write the xml menifest (or may be pay someone for typing)?
Oh.. dont forget to add all required permissions also...
Can someone explain me how to control one application from another application? I'm running a music player in an app1 using service class. And I want to stop that music player from another app.,i.e app2. But, I'm fallin short o the concept.
Depends what you need to do.
Opening another activity (or sending messages) is by using Intents:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// ...
startActivity(intent);
Starting service is by using startService()
What you are trying to do can also be done using Intent broadcasts but only if your target app supports and listens to specific actions on the broadcast. You need to see if there is such an ACTION supported.
I'd like to continue this question a bit.
In my case, I'm developing the target app and I need to implement few simple procedure calls for the main app. Basically 'start', 'stop' and 'sendData'. As I wrote, I'm developing the target app so I can support whatever I want. Which would you say is the easiest way to handle.
The whole situation a bit more explained. Main app would like my app to start it's work, and if needed they'll request that I turn myself off and when the main app is closing it would request me to send my data forward.
I'm quite new to android development, so code snippets are preferable. Thank you.
1 . can we get any event when user tap/touch native application(i.e. messaging,contacts).
2 . i know that any application launch by intent in android, there is any way to know which application launch with launch of application.
Thanks
No, We can not get any event directly or by any receiver.
what I have figured it that it can not be done directly......
But there are two work around for this :
Start a service that will check top-activity always by this way can know what activity got launched and do whatever you do under this condition.
Catch the logcat, read the line, and you can easily get what event what even took place, and by using your required filters you can even do whatever you like :)
can we get any event when user
tap/touch native application(i.e.
messaging,contacts).
Not generally. Most of these icons are tied to their applications.
there is any way to know which application launch with launch of application.
This makes no sense to me, sorry.
I am agree with #K_Rapid's answer..
Check code of AppLocker
I hope you will got solution from that code...
For (1): what do you mean by 'tap/touch'? Do you mean when the built-in applications are launched, or when they're interacted with?
If you mean launching, you can listen to any intents being fired by the system by registering a broadcast receiver. If you set your IntentFilter to receive intents with CATEGORY_LAUNCHER, you should be able to see when the launcher starts applications.
See:
http://developer.android.com/reference/android/content/Intent.html#CATEGORY_LAUNCHER
http://developer.android.com/reference/android/content/BroadcastReceiver.html
If you mean interacting, I don't think you can do that.
For (2): I don't believe that intents remember where they were constructed, so I don't think this is possible. I could be wrong, however.