How to add an service accessibility Android that registre Alert Dialog - accessibilityservice

I would Like to listen to Alert Dialog, and i have adding an exemple but it dont work, and i cant follow the starting and capturing the event like Key Up ..etc by using Log.d.
I confirm that the Accessibility Service has Enabled, but i would like to to assure that is executing
here is my code
public class MyService extends AccessibilityService {
public static String TAG = "USD";
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.i(TAG, "onAccessibilityEvent: gettting");
String text = event.getText().toString();
if (event.getClassName().equals("android.app.AlertDialog")) {
Log.i(TAG, " Getting USSD"+text);
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
}
}
and the Manifest code
<service android:name=".MyService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:label=""
android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
and the config XML
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames="com.android.phone"
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>

Related

Not able to run when injecting dependencies with Hilt into Android Classes

I'm in the process of making an application using Hilt. But my question is, am I only able to run my app through AndroidManifest.xml? I'd like to run it through another class, but it keeps giving me a blank page.
My Classes:
Application class using #HiltAndroidApp
#HiltAndroidApp
class ExampleApplication : Application()
Activity class using #AndroidEntryPoint
#AndroidEntryPoint
class ExampleActivity : ComponentActivity() {
#RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(instance: Bundle?) {
super.onCreate(instance)
setContent {
AppTheme {
Surface() {
......
Manifest.xml
(This is the only way I can run the class, ExampleActivity).
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".ui.ExampleApplication"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.App"
tools:targetApi="31">
<activity
android:name=".ExampleActivity"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/Theme.App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
So, I've tried calling my application from another class, but I can't call ExampleActivity.kt alone, so I tried calling two classes, but it keeps giving me a blank page.
Here's what I've tried:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AppTheme {
ExampleApplication()
ExampleActivity()
}
}
}
}
It gives a blank screen.
I will create another class and make it my start class, where I will then call ExampleApplication and ExampleActivity.
How am I supposed to call two classes using Hilt dependencies from another class?
Of course, I have updated the manifest.xml so that it says .MainActivity.
First of all, why do you need Hilt? What are you trying to Inject and where?
ExampleApplication() is just a place where you configure app-wide settings, you are never supposed to call it from somewhere else, so you don't need that line.
Furthermore, Which activity are you trying to start? MainActivity or ExampleActivity()? Calling ExampleActivity within MainActivity won't have any effect.
SetContent { ... } is the place where you create the UI.
If you want to open another activity from MainActivity then you need to implement navigation or use Intents.

How Can I Use BroadcastReceiver on API 26 and Higher?

I'm developing an Android App. Users can chat each other. I fetch the messages on PushReceiver class. App opened or closed I mean foreground or background; the code block working from API 19 to API 26 but not working higher than API 26. I try to debug onReceive function but it's not call on Android O.
I want to say again. My code block working API 25 and lower versions.
I'm using pushy.me service.
My BroadcastReceiver Class:
public class PushReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String notificationTitle = "Title";
String notificationText = "Text";
Bundle bundle = intent.getExtras();
JSONObject jsonObject = new JSONObject();
for (String key : bundle.keySet()) {
try {
jsonObject.put(key, wrap(bundle.get(key)));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
notificationText = jsonObject.get("body").toString();
notificationTitle = jsonObject.get("title").toString();
} catch (Exception e) {}
// Prepare a notification with vibration, sound and lights
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setLights(Color.RED, 1000, 1000)
.setVibrate(new long[]{0, 400, 250, 400})
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
// Automatically configure a Notification Channel for devices running Android O+
Pushy.setNotificationChannel(builder, context);
// Get an instance of the NotificationManager service
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
// Build the notification and display it
notificationManager.notify(1, builder.build());
}
}
My Manifest:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
...
<receiver
android:name=".Notification.PushReceiver"
android:exported="false">
<intent-filter>
<!-- Do not modify this -->
<action android:name="pushy.me" />
</intent-filter>
</receiver> <!-- Pushy Update Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver
android:name="me.pushy.sdk.receivers.PushyUpdateReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver> <!-- Pushy Boot Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver
android:name="me.pushy.sdk.receivers.PushyBootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> <!-- Pushy Socket Service -->
<!-- Do not modify - internal service -->
<service android:name="me.pushy.sdk.services.PushySocketService" /> <!-- Pushy Job Service (added in Pushy SDK 1.0.35) -->
<!-- Do not modify - internal service -->
<service
android:name="me.pushy.sdk.services.PushyJobService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
Edit: pushy.me Android Demo here
The latest Pushy Android SDK has added support for Android O power saving optimizations (App Standby / deprecation of Service), please update by following the instructions on this page:
https://pushy.me/docs/android/get-sdk
Also, make sure to add the following new JobService declaration to your AndroidManifest.xml, under the <application> tag:
<!-- Pushy Job Service (added in Pushy SDK 1.0.35) -->
<!-- Do not modify - internal service -->
<service android:name="me.pushy.sdk.services.PushyJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true" />

Recieving Sms using a broadcast receiver-xamarin

My last question was not a great question.
so here my new one.
I want to write an app that has and activity which get some info(like a phone number) from the user and then It is destroyed and the app icon is also hidden from the user.but i want to continuously receive sms from that phone number and do some stuff.
until now i have learned that if i register my broadcast receiver in the manifest it can still receive even though my app is not running or hidden.
so here is my app which i'm using xamarin (mono android):
my simple activity (it is not complete yet):
my main XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="#+id/linearLayout1">
<EditText
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="#+id/txt_phone" />
<Button
p1:text="OK"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="#+id/btn_ok" />
</LinearLayout>
and the activity class:
namespace SmsBroadcastReceiver
{
[Activity (Label = "SmsBroadcastReceiver", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
EditText txt_number = FindViewById<EditText> (Resource.Id.txt_phone);
Button btn_ok = FindViewById<Button> (Resource.Id.btn_ok);
btn_ok.Click += delegate {
//save the number in the sharedpreference and then...
Toast.MakeText (Context, "Your App Will be Closed now", ToastLength.Short).Show ();
};
}
}
}
now my broadcast receiver:
namespace SmsBroadcastReceiver
{
[BroadcastReceiver]
public class SmsReceiver : BroadcastReceiver
{
public override void OnReceive (Context context, Intent intent)
{
Toast.MakeText (context, "sms rec", ToastLength.Long).Show ();
//get the sharedpreference and then do stuff
}
}
}
and my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="SmsBroadcastReceiver.SmsBroadcastReceiver">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18" />
<application android:label="SmsBroadcastReceiver">
</application>
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
</manifest>
I know that the using a toast in a BR is not ideal but i just want to see that it is working which is not,everytime i send and sms to my phone it doesn't show anything.
where is my problem?
I think, you created BroadcastReceiver in the wrong way.
You should create it entirely with xamarin attributes.
Mono for Android translates each IntentFilterAttribute into an <intent-filter/> element.
[BroadcastReceiver]
[IntentFilter(new string[] { "android.provider.Telephony.SMS_RECEIVED" })]
public class SmsReceiver : BroadcastReceiver
{
...
}
therefore there is no need to write receiver tags manually in your AndroidManifest file.
You can also use attribute's named parameters for Priority, Categories, etc.
[IntentFilter(new string[] { "android.provider.Telephony.SMS_RECEIVED" }, Priority = Int32.MaxValue)]

Trace WCF call from client

I've built a windows forms client application which makes a WCF call. I'd like to be able to display the actual request and response, includeing SOAP header, and information about the POST/Get, from within the application. Is there a way to configure a trace listener on the client and consume it from within the client, displaying the contents in a text box?
I've configured tracing which outputs messages to a file. This configuration is on my client application, so it's logging all calls it is making to the wcf service and the response. So the sources have been added and for each source is an XmlTraceListener, which handles writing to an xml log file. What I'm looking to do now is utilize a trace listener from within the client application itself and write to a textbox control.
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All">
<listeners>
<add name="xmlTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging"
switchValue="All">
<listeners>
<add name="xmlTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xmlTraceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="ClientLogBasic.svclog" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<!-- child of the <system.serviceModel> element -->
<diagnostics>
<messageLogging maxMessagesToLog="10000"
logEntireMessage="true"
logMessagesAtServiceLevel="true"
logMalformedMessages="true"
logMessagesAtTransportLevel="true">
<filters>
<clear/>
</filters>
</messageLogging>
</diagnostics>
So now that I've got message logging working, I create my own trace listener that can write to a textbox:
public class MyTraceListender : System.Diagnostics.TraceListener
{
private TextBox txt_m;
public MyTraceListender(TextBox txt)
: base()
{
txt_m = txt;
}
private delegate void delWrite(string sText);
public override void Write(string message)
{
txt_m.Invoke(new delWrite(AsyncWrite), message);
}
public override void WriteLine(string message)
{
this.Write(message + System.Environment.NewLine);
}
private void AsyncWrite(string sMessage)
{
this.txt_m.AppendText(sMessage);
}
}
Now that I've got my trace listener, I want to try using it from my windows forms client application.
public partial class Form1 : Form
{
private MyTraceListender listener_m;
public Form1()
{
InitializeComponent();
listener_m = new MyTraceListender(this.txtOutput);
System.Diagnostics.Trace.Listeners.Add(listener_m);
}
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
string sValue = client.GetData(1234);
}
}
At this point, I'm still not seeing logging to the textbox control. I'm thinking that the listener is not associated to the source, so I tried the following:
public partial class Form1 : Form
{
private MyTraceListender listener_m;
public static System.Diagnostics.TraceSource source = new System.Diagnostics.TraceSource("System.ServiceModel.MessageLogging", System.Diagnostics.SourceLevels.All);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
string sValue = client.GetData(1234);
}
private void Form1_Load(object sender, EventArgs e)
{
listener_m = new MyTraceListender("test", this.txtOutput);
source.Listeners.Add(listener_m);
}
}
After all of this, messages are not being logged to the textbox on the form. They are being logged to the file via the XmlTraceListener, so I'm assuming the issue is how I'm adding my custom listener via System.Diagnostics.Trace.Listeners.Add(). Is this the correct approach?
Edit the Configuration file using WCF Configuration Editor, and enable tracing as shown below
This solution is mostly through app.config. Let me know if you prefer a code-based solution.
In app.config, add your listener to the list of shared listeners, as well as a listener for the message logging source. In 'listeners' list, the name must match the name later on in the 'sharedListeners' list. In 'sharedListeners' list, the 'type' must include full class name with namespace, as well as assembly name:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All">
<listeners>
<add name="xmlTraceListener"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xmlTraceListener"/>
<add name="textBoxListener"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xmlTraceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="ClientLogBasic.svclog"/>
<add name="textBoxListener" type="WinTransmitterClient.MyTraceListener, WinTransmitterClient" initializeData=""/>
</sharedListeners>
<trace autoflush="true"/>
Because MyTraceListener will be constructed by the framework, its constructor must match the base class. So instead, make the textbox a property that can be set when needed.
In MyTraceListener.cs:
public class MyTraceListener : System.Diagnostics.TraceListener
{
public TextBox txt_m
{
get;set;
}
public MyTraceListener()
: base()
{}
// rest as before ...
In Form1.cs, grab the custom listener after the client is created, and set the text box. No other code is needed. This is the entire Form1.cs, excluding 'using' and 'namespace' lines:
public partial class Form1 : Form
{
public static System.Diagnostics.TraceSource source = new System.Diagnostics.TraceSource("System.ServiceModel.MessageLogging", System.Diagnostics.SourceLevels.All);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.ContactManagerTextServiceClient client = new ServiceReference1.ContactManagerTextServiceClient();
// identifier in quotes must match name from config file
MyTraceListener mtl = source.Listeners["textBoxListener"] as MyTraceListener;
// of course this doesn't need to be done at every button click, but you get the idea
mtl.txt_m = this.txtOutput;
string sValue = client.GetData(1234);
}
}
Try creating a message inspector. On the client side you'd have to implement IClientMessageInspector which will allow you to intercept the message before it is being sent as well as the response which is received prior to passing it further into the application. You'll find more information on MSDN

How to access exported service protected with permission in Android

I created one remote service as follows:-
<service android:name=".XYZService"
android:permission="com.xyz.service"
android:exported="true">
<intent-filter>
<action android:name="com.abc.def.XYZService"/>
</intent-filter>
</service>
I am trying to bind with this service by using client application service as follows:-
//client service onStartCommand code :
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
boolean ret;
try {
Intent i = new Intent("com.abc.def.XYZService");
ret = getApplicationContext().bindService(i, serviceConnection,
Context.BIND_AUTO_CREATE);
if (ret == false) {
//log error
}
} catch (SecurityException e) {
e.printStackTrace();
}
return super.onStartCommand(intent, flags, startId);
}
client application manifest has following permission:-
<uses-permission android:name="com.xyz.service" />
Still, I am getting following exception:-
Security Exception: The client Service does not have permission to bind to the xyz service.
My intention here is to protect my exported service with some permission and use that permission in client application to access exported service.
Any help will be appreciated.
Use this.
<permission
android:name="myPermission"
android:description="#string/myPermissionDescription"
android:label="#string/myPermissionLabel">
</permission>
more info:
page 1 --
page 2