Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of running services in Android? [closed]

How can I get a list of running services in android code and send it via SMS using SMSManager?

like image 645
user2304058 Avatar asked Dec 02 '22 19:12

user2304058


1 Answers

Include the following permission in your AndroidManifest.xml file

<uses-permission android:name="android.permission.SEND_SMS" />

This method shows both tasks:

public void sendSMS {
    // This is the code to find the running services
    ActivityManager am = (ActivityManager)this.getSystemService(Activity.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> rs = am.getRunningServices(50);
    String message = null;

    for (int i=0; i<rs.size(); i++) {
        ActivityManager.RunningServiceInfo rsi = rs.get(i);
        Log.i("Service", "Process " + rsi.process + " with component " + rsi.service.getClassName());
        message =message+rsi.process ;
    }

    //This is the code to send sms.
    String phoneNumber = "0123456789";
    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}

The method detail.

public void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
like image 186
anjaly Avatar answered Dec 05 '22 10:12

anjaly