Ehsan Hasannia
Ehsan Hasannia

Reputation: 101

why package manager is always is null?

i try to show user location in my android app , but it dosnt work! package manager is always null.

private void openPrefredLocationInMap (){
    String location =
            PreferenceManager.getDefaultSharedPreferences(this)
                    .getString(getString(R.string.pref_location_key)
                            , getString(R.string.pref_defult));

    Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
            .appendQueryParameter("q", location).build();

    Intent intent= new Intent(Intent.ACTION_VIEW,geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null)
        startActivity(intent);
     else
        Log.d("package","couldnt call"+location);
}

Upvotes: 2

Views: 540

Answers (1)

Tarps
Tarps

Reputation: 1933

Your device does not have an application that could handle such intent. Install an application that can handle that intent or make one yourself. To be more specific, you might not have a map application that would be able to display geoLocation intent.

Try installing Google Maps for example.

Upvotes: 4

Related Questions