android


How to get the starting time of an app in android


I create an android application, i have to create a notification about apps running in background with there staring time, i'll successfully get the running apps but cant generate that the app is running from how long time. For example-> Talking Tom is running from last 3 hours etc.
public class ListAdapter extends ArrayAdapter {
// List context
private final Context context;
// List values
private final List<RunningAppProcessInfo> values;
public ListAdapter(Context context, List<RunningAppProcessInfo> values) {
super(context, R.layout.activity_main, values);
this.context = context;
this.values = values;
}
/**
* Constructing list element view
*/
#Override
public View getView(int position, View convertView, ViewGroup parent) {
long re = MainActivity.recived;
long sd = MainActivity.send;
System.out.println("hii");
long po=MainActivity.pos;
/* if(position!=po)
return null; */
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_main, parent, false);
TextView appName = (TextView) rowView.findViewById(R.id.appNameText);
appName.setText(values.get(position).processName);
TextView sendtxt = (TextView) rowView.findViewById(R.id.sendtv);
sendtxt.setText(String.valueOf(re/1024));
// sendtxt.setText(b1.getString("passed2"));
TextView receivetxt = (TextView) rowView.findViewById(R.id.receivetv);
receivetxt.setText(String.valueOf(sd/1024));
// receivetxt.setText(b1.getString("passed1"));
return rowView;
}
}
MY SECOND CLASS IS:->
public class ApplicationAdapter extends ArrayAdapter {
private List<ApplicationInfo> appsList = null;
private Context context;
private PackageManager packageManager;
public ApplicationAdapter(Context context, int textViewResourceId,
List<ApplicationInfo> appsList) {
super(context, textViewResourceId, appsList);
this.context = context;
this.appsList = appsList;
packageManager = context.getPackageManager();
}
#Override
public int getCount() {
return ((null != appsList) ? appsList.size() : 0);
}
#Override
public ApplicationInfo getItem(int position) {
return ((null != appsList) ? appsList.get(position) : null);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (null == view) {
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.snippet, null);
}
ApplicationInfo data = appsList.get(position);
if (null != data) {
TextView appName = (TextView) view.findViewById(R.id.app_name);
TextView packageName = (TextView) view.findViewById(R.id.app_paackage);
ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);
appName.setText(data.loadLabel(packageManager));
packageName.setText(data.packageName);
iconview.setImageDrawable(data.loadIcon(packageManager));
}
return view;
}
};
// get time value of all the processes (in Milliseconds)
long millisSinceBoot = SystemClock.elapsedRealtime();
long time = ((millisSinceBoot - values.get(position).activeSince)/1000);
//Log.i("HRHHRHRHRHR", "%%%%%%%%%%%%%%%%"+time);
String time1 = String.valueOf(time);
time_list.add(time);
int seconds = (int) (time / 1000) % 60 ;
int minutes = (int) ((time / (1000*60)) % 60);
int hours = (int) ((time / (1000*60*60)) % 24);
String time11 = hours+":"+minutes+":"+seconds;
Log.i("Time", "Secs:- "+seconds+" "+"Mins:- "+minutes+" "+"Hours:- "+hours);
timer.setText(time1);
EDITED
You can get a list of each service's start time using ActivityManager.RunningServiceInfo.activeSince, described here. Here's a snippet that retrieves the times for up all service processes.
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
long currentMillis = Calendar.getInstance().getTimeInMillis();
Calendar cal = Calendar.getInstance();
for (ActivityManager.RunningServiceInfo info : services) {
cal.setTimeInMillis(currentMillis-info.activeSince);
Log.i(TAG, String.format("Process %s with component %s has been running since %s (%d milliseconds)",
info.process, info.service.getClassName(), cal.getTime().toString(), info.activeSince));
}

Related Links

React Native : Network request failed
Realm Authentication OkHttp call gets interrupted
draw a circle in a map
Sync Android SDKs failed [Android Studio 2.1.1]
How is scroll position saved when the screen is rotated?
How to get active minutes from Google-Fit
Android service and utils package
Firebase handleIntent AbstractMethodError
Sending FCM message from client not working
Decoding an mp3 file using FFmpeg but sound is glitchy
Get a JSON from URL after authroization Android
android - Unable to mmap new swap file chunk
By long clicking on listview delete its contents from SQLite and listview that is clicked
How to use Geofence refer data from Mysql?
Libgdx AssetsManager as static variable
Could not catch Firebase exceptions

Categories

HOME
django
asp.net-web-api
google-app-engine
xml
search
cobalt
spark-streaming
c++11
pagination
powerpoint
3d
zend-framework
interface
fftw
appcelerator
access
static-site
google-apps
permissions
gembox-spreadsheet
babeljs
nuget-package
discrete-mathematics
arangodb
minecraft-forge
google-chrome-app
dkim
plist
siddhi
angular-dart
favicon
comsol
do-while
job-scheduling
vuejs
forgot-password
nodemcu
windows-xp
breadth-first-search
ios10.2
comparator
tiki-wiki
jasmine-node
delimiter
8051
card.io
sammy.js
reverse
browser-extension
openerp-7
ideascript
filesystemwatcher
css-position
xv6
logback-groovy
smoothstate.js
angular-http
strftime
getchar
fwrite
user-defined-fields
tf
google-cse
pair-programming
context-switch
cd-burning
filenet
pure-css
meteor-packages
segment-io
file-uri
x-tag
observablecollection
google-query-language
deep
nullable
httpruntime.cache
assertion
wiredep
forwarding
django-urls
canalyzer
jsvc
avahi
aspectj-maven-plugin
zxspectrum
cakephp-2.7
cosine-similarity
iiop
primitive-types
psr-4
tweenlite
paste
cfcache
getopt
mysql-error-2013
virtual-pc
twisted.web
bjyauthorize
android-sdk-2.3
web-notifications
patricia-trie
fragmenttransaction
web-farm
jsr286
gobject-introspection
denied
htdocs
landscape-portrait
mysql-error-1205
cdonts
svk
metaweblog
squishit
addchild
openfaces
cuda.net
google-wave
perl5.12
technical-debt

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App