【发布时间】:2017-12-07 07:45:07
【问题描述】:
当我在Marshmallow 上运行此代码时,此代码在 4.4.2 上运行,崩溃未共享位置。
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)));
}
});
}
【问题讨论】:
-
您需要在运行时获得许可。
-
targetSdkVersion大于 22 的应用程序(因此 Marshmallow 和更新版本)需要在运行时请求一些权限。阅读relevant Android docs。只需确保不要将targetSdkVersion减少到 22,因为这样用户在下载应用程序时将需要接受权限,而您无需进行任何其他更改。那将是快速、懒惰和错误的做法。
标签: java android permissions android-6.0-marshmallow