I am working on an Android app (academic purposes) and as part of the app I want to integrate a Keylogger. Following this answer Android Key logger I tried to implement it using AccessibilityService. The code for my class, called Keylogger.java, is the following:
import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
public class Keylogger extends AccessibilityService {
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
int tipo = event.getEventType();
switch(tipo) {
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_CLICKED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
default:
break;
}
}
#Override
public void onInterrupt() {
}
#Override
public void onServiceConnected() {
Log.d("Keylogger", "Starting service");
}
}
The Manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.mychat">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChatBoxActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".Keylogger"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
</application>
and finally, the Configuration file for the service:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames=""
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="" />
When I install the app on the device it works just fine (that is, I get no errors), and I can manually activate the service going to Settings >> Accessibility. But nothing happens next. I tried everything (launch other applications and type some text) but the prints that I placed on each case will not show up. The app does several things but from my understanding the service should work automatically. What am I missing and how can I get it right?
Thank you in advance.
https://github.com/bshu2/Android-Keylogger
Here's a android accessibility Keylogger I've used before , and works nice
I guess you can compare your application with that Keylogger , you might find your mistake
Related
I am developing calls and sms blocking app, I have encountered the problem where I can't get incoming number from phonestatelistener. My code looks like this:
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_RINGING:
System.out.println("incoming number PhoneStateListener:" + incomingNumber);
if (sBlockCall>0){
MuteAudio(getContext());
//reject call if number is matched to our blocking number
boolean callShouldBeBlocked = true;
for(int i = 0; i<sWhiteList.size(); i++){
if(sIncomingNumber.contains(sWhiteList.get(i).mNumber)){
UnMuteAudio(getContext());
System.out.println("CONTACT IS IN WHITE LIST");
callShouldBeBlocked = false;
break;
}
}
if(callShouldBeBlocked){
System.out.println("BLOCK CALL");
disconnectPhoneItelephony();
}
} else {
UnMuteAudio(getContext());
}
//IT WORKS
break;
}
}
So my programm works not as I expect it to work, cause it always returns null as incoming number.
My manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="oleksandr.ivanets.dontwakemeapp">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".PhoneStateReceiver"
android:enabled="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="999999999">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
try adding this permissions, in my case this worked.
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
For my app I use pushbullet to send push messages to my device. On this device, I have an app, that should display this message. Therefore I use the pushbullet - API, described here: https://docs.pushbullet.com/extensions/messaging/guide/
So I add a service to my manifest file and implemented a class, that only should write a Log message.
my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stfgorbitzapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.pushbullet.android.permission.READ_MESSAGING_EXTENSION_DATA" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".SampleMessagingExtension"
android:permission="com.pushbullet.android.permission.READ_MESSAGING_EXTENSION_DATA">
<intent-filter>
<action android:name="com.pushbullet.android.extension.MessagingExtension" />
</intent-filter>
<meta-data
android:name="protocolVersion"
android:value="1" />
</service>
</application>
</manifest>
my basic activity, only showing "Hello World"
package com.example.stfgorbitzapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
}
}
my class, that should be executed when receiving the intent:
package com.example.stfgorbitzapp;
import android.content.Intent;
import android.util.Log;
import com.pushbullet.android.extension.MessagingExtension;
public class SampleMessagingExtension extends MessagingExtension{
private static final String TAG = "SampleMessagingExtension";
#Override
protected void onMessageReceived(final String conversationIden, final String message) {
Log.i(TAG, "Pushbullet MessagingExtension: onMessageReceived(" + conversationIden + ", " + message + ")");
}
#Override
protected void onConversationDismissed(final String conversationIden) {
Log.i(TAG, "Pushbullet MessagingExtension: onConversationDismissed(" + conversationIden + ")");
}
}
but when I send a push message, I could not read the Log message. Can onyone help me? Did I forget something? I.e. specific permissions?
Maybe do you need also Network state and Wifi permissions?
Pushbullet should use network to exchange notifications..
About the log: the priority is set to INFO level. Maybe do you filter them?
Do you use Android Studio or Eclipse?
I know there are similar question in statckoverflow, but they just do NOT work for me.
Broadcast receiver(staticly registe via manifest.xml) can NOT receive package_remove event after installing on device (without running main activity)
But the receiver works if main activity is running.
To register broadcastreceiver staticly in AndroidManifest.xml as followings
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceivertesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.broadcastreceivertesting.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.broadcastreceivertesting.PackageBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
PackageBroadcastReceiver as a receiver are like following:
public class PackageBroadcastReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
final String action = intent.getAction();
if (Intent.ACTION_PACKAGE_REMOVED.equals(action))
{
File file = new File("/storage/sdcard0/zzz/yyy");
if (file.exists())
{
file.delete();
}
boolean createDir = new File("/storage/sdcard0/zzz/").mkdirs();
Log.d("XXX", "XXXX createDir=" + createDir);
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
Do I miss something ?
Try changing this...
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
to this...
<intent-filter>
<action android:value="android.intent.action.PACKAGE_REMOVED" />
<scheme android:value="package" />
For more information, see this link on receiving package broadcast intents...
https://groups.google.com/forum/#!topic/android-developers/aX5-fMbdPR8
When user want to uninstall app from android device, I want user uninstall button click event for that application.
I am getting event of application is removed from device, but I want to show pop-up before application is removed. I am trying to achieve same like doing in 'App Lock' application.
Here is my code to get application removed event through broadcast receiver. But I am totally blank about uninstall button click or before pop-up click. Please guide me in right direction.
Thanks in advance.
public class MainActivity extends Activity {
CustomBroadcastReceiver mApplicationsReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mApplicationsReceiver=new CustomBroadcastReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
filter.addAction(Intent.ACTION_PACKAGE_VERIFIED);
filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
filter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH);
filter.addAction(Intent.ACTION_DELETE);
filter.addAction(Intent.ACTION_DEFAULT);
filter.addDataScheme("package");
registerReceiver(mApplicationsReceiver, filter);
}
}
public class CustomBroadcastReceiver extends BroadcastReceiver {
/**
* This method captures the event when a package has been removed
*/
#Override
public void onReceive(Context context, Intent intent)
{
System.out.println("Hello from CustomBroadcastReceiver");
if (intent != null) {
String action = intent.getAction();
System.out.println("L1123 : "+action);
if (action.equals(intent.ACTION_PACKAGE_REMOVED)) {
//Log the event capture in the log file ...
System.out.println("The package has been removed");
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bits.uninstallappdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <receiver android:name=".CustomBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
</intent-filter>
</receiver> -->
</application>
</manifest>
Please try to get the top activity in the task via ActivityManager, and check if it is the uninstall activity.
Core code:
ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
String packageName = topActivity.getPackageName();
String className = topActivity.getClassName();
Log.v(TAG, "packageName" + packageName);
Log.v(TAG, "className" + className);
if ("com.android.packageinstaller".equals(packageName)
&& "com.android.packageinstaller.UninstallerActivity".equals(className)) {
//Do anything you want here
}
The following permissions which you are using are granted to system apps only. Make sure you have rooted device to allow such permissions.
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
Ok i am new to android development so please bear with me here. I am following the learning android book and have this problem where the refresh service wont work as it doesnt have the necessary permission. Can anyone tell me what is causing the issue? The logcat throws up runtime error: *java.lang.SecurityException: Not allowed to start service Intent { cmp=com.example.yamba/.RefreshService } without permission com.example.yamba.permission.REFRESH at com.example.yamba.TimelineActivity.onOptionsItemSelected(TimelineActivity.java:138)
*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yamba"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.example.yamba.permission.REFRESH" />
<application
android:name=".YambaApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.yamba.StatusActivity"
android:configChanges="orientation"
android:icon="#drawable/ic_launcher"
android:label="#string/status_Update" >
</activity>
<activity
android:name=".TimelineActivity"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".UpdaterService" >
</service>
<service
android:name=".RefreshService"
android:permission="com.example.yamba.permission.REFRESH" >
<intent-filter>
<action android:name="com.example.yamba.RefreshService" />
</intent-filter>
</service>
<activity
android:name=".PrefsActivity"
android:label="#string/Preferences" >
</activity>
<receiver android:name=".BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.example.yamba.REFRESH_ALARM" />
</intent-filter>
</receiver>
</application>
package com.example.yamba;
import java.util.List;
import winterwell.jtwitter.Twitter.Status;
import winterwell.jtwitter.TwitterException;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
public class RefreshService extends IntentService {
static final String TAG = "RefreshService";
public RefreshService() {
super(TAG);
}
#Override
protected void onHandleIntent(Intent intent) {
((YambaApp) getApplication()).pullAndInsert();
Log.d(TAG, "onHandleIntent");
}
#Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "OnCreated");
}
#Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "OnDestroy");
}
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Intent intentUpdater = new Intent(this, UpdaterService.class);
Intent intentRefresh = new Intent(this, RefreshService.class);
Intent intentPrefs = new Intent(this, PrefsActivity.class);
Intent intentTimeline = new Intent(this, StatusActivity.class);
switch (item.getItemId()) {
case R.id.item_start_service:
startService(intentUpdater);
return true;
case R.id.item_stop_service:
stopService(intentUpdater);
return true;
case R.id.item_refresh:
startService(intentRefresh);
return true;
case R.id.item_prefs:
startActivity(intentPrefs);
return true;
case R.id.item_status_update:
startActivity(intentTimeline);
default:
return false;
}
The onOptionsItemSelected is used to call the refresh service.
Really Appreciate the help. Thanks!!
you need to declare permission in your manifest
<permission
android:name="com.example.yamba.permission.REFRESH"
android:protectionLevel="signature"
/>
You need to declare this REFRESH Permission in the manifest as well.
here is an example code of how to declare a permission
<permission
android:name="A_PERMISSION"
android:description="#string/broadcast_permission_desc"
android:label="#string/broadcast_permission_label"
android:permissionGroup="#string/broadcast_permission_group"
android:protectionLevel="signature" />
For Reference See this Page