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

Very unusual error while dismissing ProgressDialog in AsyncTask
Making Android apps accessible (for people with disabilities) with PhoneGap
How to pass login screen activity when using onBackPressed
NoSuchMethodError Exception with ActionBar
Unable to show keyboard automatically in the SearchView
Setting contentDescription from label for android accessibility
Android Flashlight force closing on return from other activity
App Launcher Icon Is Wrong
Scroll Background Like Lunar Lander or Ninja Jump Game - Android
Using string inside ShareActionProvider share intent
How to make sliding drawer to overlay other elements in Android?
How to retrieve an ID of the selected item in a dynamic Spinner?
thread executing before
Android ListView NullPointerException when inflating View
Does the android emulator always return null for URL on APKExpansionPolicy check?
how to populate listview from arraylist returned from ormlite?

Categories

HOME
gridview
webdriver
jax-rs
pda
datastore
flex
zend-framework
solver
spring-data-mongodb
rom
scripting
rcloud
mql5
dkim
fhir
startup
mod-security
xcodebuild
speech-synthesis
do-while
azure-iot-hub
null-pointer
google-data-studio
imessage
shortest-path
r-mice
react-toolbox
xunit
expressionengine3
google-cloud-print
jquery-multiselect
bulletphysics
android-sharedpreferences
nstimer
gp
playstation-portable
android-gridview
biztalk-rule-engine
sendbird
arduino-ide
lubridate
google-knowledge-graph
xcode7.3
watchman
filesystemwatcher
railstutorial.org
verifiable-c
hackintosh
linqpad
dapper-simplecrud
snapchat
double-click
xbmc
spring-integration-sftp
openblas
singleinstance
mta
beamer
hclust
avspeechsynthesizer
xdoclet
cfchart
ellucian-scribe
asyncdisplaykit
computer-architecture
dnssec
uvc
mmwormhole
beatsmusic
viewer
sonarqube-5.0
strawberry-perl
ray
tinyxml
dot42
terminate
clickbank
http-patch
oocss
nebula
route-provider
node-blade
pclzip
onload-event
android-sdk-2.3
idn
frameworkelementfactory
qtconcurrent
objectquery
azman
update-statement
isapi-extension
data-mapping
lalr
wordprocessingml
windows-identity
information-management
pnrp
idatareader

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