Reputation: 1696
I am trying to get the location of app by passing package name to check if its installed on internal or external storage. Please help.
Upvotes: 3
Views: 1888
Reputation: 115
PackageManager pm = context.getPackageManager();
ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
if ((applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
// installed on sdcard
}
Upvotes: 0
Reputation: 51
U can check this code and see whether we have installed on internal or external storage
(Note: u can use it in oncreate or any where)
ApplicationInfo io = getApplicationContext().getApplicationInfo();
if(io.sourceDir.startsWith("/data/")) {
Toast.makeText(this,"your app is in internal storage",Toast.LENGTH_LONG).show();
//application is installed in internal memory
} else if(io.sourceDir.startsWith("/mnt/") || io.sourceDir.startsWith("/sdcard/")) {
Toast.makeText(this,"your app is in external storage",Toast.LENGTH_LONG).show();
//application is installed in sdcard(external memory)
}
Upvotes: 1
Reputation: 759
check this out
public class Example extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put the package name here...
boolean installed = appInstalledOrNot("com.packagename");
if(installed)
{
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.packagename");
startActivity(LaunchIntent);
System.out.println("App already installed om your phone");
}
else
{
System.out.println("App is not installed om your phone");
}
}
private boolean appInstalledOrNot(String uri)
{
PackageManager pm = getPackageManager();
boolean app_installed = false;
try
{
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e)
{
app_installed = false;
}
return app_installed ;
}
}
Upvotes: 0