android: how to trigger a service globally by special action? - android

I want to write a screen capture app, but I don't know how to trigger my app globally by special action such as shaking the device or long press a button or anything else. Which means bring up my app under any app any time. Is there any suggestion?

You'll need to use a reciever for that. For example, if you wanted the app to start activity MyReciever when the phone boots up, you could do the following:
<receiver android:name=".MyReceiver">
<intent-filter >
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

Related

How to show all intent-filter of a component in android programmatically?

As the title says, I want to know all intent-filter(s) and actions inside it of a component like activity, receiver or service.
For example in AM.xml:
<receiver android:name="com.samsung.longuni.receivers.WakeServiceUpReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Is there any way that in my application I can list up all actions in a intent-filter of a component of a certain application.

How can I update a widget on receiving a broadcast?

I'm working on a widget that displays information from a completely separate app. The separate app sends a broadcast when its data is changed, and I want to refresh/update my widget upon receiving this broadcast.
I can't seem to work out how to update a widget from within a BroadcastReceiver however. Is there a way to do this? Or another method to get the same result?
If the separate app has special action for its broadcast, you can add the intent filter to the manifest of your widget. Something like this:
<receiver android:name="ExampleAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="SEPARATE_APP_ACTION" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/example_appwidget_info" />
</receiver>
And just process it in onRecive method of you AppWidgetProvider.
HTH.

Android hidden application

I'm writing a (legal) spy program. I want to make this program hidden on the launcher (so that no icon is shown). I tried to remove <category android:name="android.intent.category.LAUNCHER" /> line from AndroidManifest.xml, but then the user can't launch the application in first start mode (configuration). Who have any ideas ?
How can I do it?
You need to make your app into a service. Here is Androids take on creating services components:
http://developer.android.com/guide/components/services.html
Found this as well on MobiWare:
When you want to track the usage of the mobile or gather some data without user knowledge,this might help you.
Step1: Create an application with No icon.
Normally,an activity is declared as follows in manifest.
<activity
android:label="#string/app_name"
android:name="org.security.tracker.Tracker-activity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Remove the Category TAG ,you wont get app icon anymore.
Now,you don't need activity anymore. so remove this segment.
BUt you might think,how the app will run without any trigger or what is the starting point of the application.
This is the solution.
<!-- Start the Service if applicable on boot -->
<receiver android:name="org.security.tracker.ServiceStarter" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
This triggers your code that written in Receiver there by you can run service to implement your thoughts.
<service android:name="org.security.tracker.serviceCode" />
You need to add this permission,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Your code runs when the phone reboots only.
Step 2. Write your code
On Reboot,the recevier will fire ,there you can start your service.
class ServiceStarter extends BroadcastReceiver {
#Override
public void onReceive(Context _context, Intent _intent) {
Intent i = new Intent("com.prac.test.MyPersistingService");
i.setClass(_context, ServiceCode.class);
_context.startService(i);
}
}
You can remove the <category android:name="android.intent.category.LAUNCHER"/> from the AndroidManifest.xml file.
But remember to add <category android:name="android.intent.category.LEANBACK_LAUNCHER"/> so that Android studio will be able to compile your app (yet hidden from launcher) :) :D
remove
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
from the manifest file
The app can be hidden programmatically, Below is the code which will hide the app from the Launcher menu. this works fine android 10 as well
// App will be hidden when this method will be called from menu
private fun hideApp() {
val packageManager =packageManager
val name =ComponentName(this,MainActivity::class.java)
packageManager.setComponentEnabledSetting(name,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
Log.d("TAG", "hideApp: success")
}
For more information, you can check this link https://developer.android.com/reference/android/content/pm/PackageManager#setComponentEnabledSetting(android.content.ComponentName,%20int,%20int)

How to know if the system clock has changed?

In my application I have a service that after for example 30 seconds, runs another activity. I did this process with Alarm Manager.
But the problem is, if the user changes the system time it affects 30 seconds. What is your suggestion? Is there any way to know if the user changes the system time?
You can listen to Intent.ACTION_DATE_CHANGED broadcast. Your ApplicationManifest file should contain something like
<receiver android:name="com.test.YouBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
</intent-filter>
</receiver>
For broadcast receivers refer:
http://developer.android.com/reference/android/content/BroadcastReceiver.html

How to get "all" (or the MAIN/LAUNCHER) android intent

i want receive all start app intents (i think MAIN/LAUNCHER, see below) to log how often i used the application. So i do not want create an activity... I tried several receiver blocks, but for now nothing works:
with, without priority, only the action, both, only the category and so on..
<receiver android:name=".Receiver" android:enabled="true"
android:process=".e">
<intent-filter priority="100000" android:priority="100000">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
Have anyone an idea?
Thanks
I want receive all start app intents
You cannot do that, sorry.

Categories

Resources