我试图创建一个RECORD_AUDIO运行时权限。 对于AndroidManifest,我已添加:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
和 我已添加的活动:
// Requesting Record Permission
private static final int REQUEST_RECORD=3;
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.RECORD_AUDIO)) {
Toast.makeText(getApplicationContext(), "Allow in order to use microphone for recording.", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
REQUEST_RECORD);
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
REQUEST_RECORD);
}
}
有人可以指出错误吗?权限完美,但对话框不显示应用程序的名称。为什么会这样?
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="My.Spinner.Style" parent="Base.Widget.AppCompat.Spinner.Underlined">
</style>
<style name="AppTheme.navtheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#2196F3</item>
<item name="colorAccent">#03A9F4</item>
</style>
<style name="AppTheme.popupTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
colors.xml
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="foreground_material_light">#FFFFFF</color>
<color name="abc_primary_text_material_light">#FFFFFF</color>
<color name="abc_secondary_text_material_light">#FFFFFF</color>