I am looking to find the first Install time of different applications installed on my device using my app. The very basic PackageManager->PackageInfo->firstInstallTime field will suffice but it is always returning NameNotFoundException even though I have tried multiple app's(correct) package names.
package com.example.testingpackageinfo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.pm.PackageInfoCompat;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button button ;
TextView textView;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
button = findViewById(R.id.button);
textView = findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
PackageManager pm = context.getPackageManager();
PackageInfo pInfo = pm.getPackageInfo("com.google.android.youtube", 0);
long installTime = pInfo.firstInstallTime;
textView.setText(String.valueOf(installTime));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
textView.setText("Package Not found");
}
}
});
}
}