-1

This code run on 4.4.2 when i run this on Marshmallow crash not shared location.

shar_btn = (Button) findViewById(R.id.shrbtn);

    shar_btn.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {



                        link = formatLocation(getLocation(), getResources().getStringArray(R.array.link_templates)[0]);
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_SEND);
                        intent.putExtra(Intent.EXTRA_TEXT, link);
                        intent.setType("text/plain");
                        startActivity(Intent.createChooser(intent, getString(R.string.share_location_via)));
                    }

                });
      }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • you need permission at runtime. – Ratilal Chopda Dec 07 '17 at 07:47
  • Apps that have `targetSdkVersion` above 22 (so Marshmallow and newer) need to ask for some permissions during runtime. Read the [relevant Android docs](https://developer.android.com/training/permissions/requesting.html). Just make sure not to reduce the `targetSdkVersion` to 22 because then users will need to accept permissions when they download the app and you won't have to make any other changes. That would be the quick, lazy and wrong way to do it. – TimSim Dec 07 '17 at 07:55

1 Answers1

1

I think it will help you Ask for permission at runtime

if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.M){
        if (ActivityCompat.checkSelfPermission(AboutProduct.this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED){
            requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);

            return;
        }
// write your code here 
link = formatLocation(getLocation(), getResources().getStringArray(R.array.link_templates)[0]);
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_SEND);
                    intent.putExtra(Intent.EXTRA_TEXT, link);
                    intent.setType("text/plain");
                    startActivity(Intent.createChooser(intent, getString(R.string.share_location_via)));

    }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);



}
Teja
  • 787
  • 7
  • 21