- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我在另一个应用程序中使用了一个模块。在我实现该模块之前,我将其设置为 API 级别 23(编译和目标),就像我的主项目一样这工作正常,除了这个错误。问题是,自 marshmellow 以来,Google 已经更改了权限管理。最后,我不知道应该如何以及在何处设置权限。
启动应用程序时出现此错误:
java.lang.SecurityException: Client must have ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to perform any operations location.
你能帮我简单解释一下(我需要什么样的代码以及在哪里插入)以避免这个错误吗?
来自模块的 list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cs.android.weminder">
<!--
android:versionCode="3"
android:versionName="1.2.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
-->
<!-- Grant the network access permission -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- Grant the location access permission -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- android:name="com.cs.android.weminder.MyApplication"
android:label="@string/app_name">-->
<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Required for creating dialog of the ACRA report -->
<activity
android:name="org.acra.CrashReportDialog"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:theme="@style/AcraDialog" />
<activity
android:name="com.cs.android.weminder.MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
<activity android:name="com.cs.android.weminder.BaseScreen" />
<activity android:name="com.cs.android.weminder.LocationBaseScreen" />
<activity android:name="com.cs.android.weminder.SettingsActivity" />
<activity android:name="com.cs.android.weminder.WeminderApplication" />
<!-- Required by the AdMob Ads SDK -->
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<receiver
android:name="com.cs.android.weminder.AlarmReceiver"
android:process=":remote" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.cs.android.weminder.AlarmService" >
</service>
</application>
模块的主要 Activity :
public class MainActivity extends SettingsActivity implements ActionTypes,
ResultType {
private TextView tvLocation, tvHTemp, tvLTemp, tvCurrentTemp, tvTimestamp,
tvDate, tvWindSpeed, tvPressure;
private ImageView ivCurrentWeather, ivRefresh, ivUnit, ivSearch, ivRemind,
ivMyLocation;
private HorizontalViewGallery forecastGallery;
// Search field
private MyCustomEditText etSearch;
// holding different weather icons presenting weather condition
// alternatively.
private IconFinder mIconFinder;
private ApiCallQueue requestsQueue = new ApiCallQueue();
// Ads View
private AdView adView;
private void setupUI(View view) {
// Set up touch listener for non-text box views to hide keyboard.
if (!(view instanceof EditText)) {
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Hide the search field if the user is touching anywhere
// except the search field
if (etSearch.isShown()) {
etSearch.startDeflation();
return true;
}
return false;
}
});
}
// If a layout container, iterate over children and seed recursion.
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setupUI(innerView);
}
}
}
/**
* Initial the UI of current screen Initial variables;
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void initialActivity() {
setupUI(findViewById(R.id.parent));
// display the name of location
tvLocation = (TextView) findViewById(R.id.tvLocation);
// Set the location icon
tvLocation.setCompoundDrawablesWithIntrinsicBounds(getResources()
.getDrawable(R.drawable.icon_marker), null, null, null);
// display today highest temperature
tvHTemp = (TextView) findViewById(R.id.tvHTemp);
// Set the highest temperature icon
tvHTemp.setCompoundDrawablesWithIntrinsicBounds(getResources()
.getDrawable(R.drawable.icon_highest), null, null, null);
// display today lowest temperature
tvLTemp = (TextView) findViewById(R.id.tvLTemp);
// Set the lowest temperature icon
tvLTemp.setCompoundDrawablesWithIntrinsicBounds(getResources()
.getDrawable(R.drawable.icon_lowest), null, null, null);
// display the current temperature
tvCurrentTemp = (TextView) findViewById(R.id.tvCurrentTemp);
// display the update time stamp
tvTimestamp = (TextView) findViewById(R.id.tvTimestamp);
// display the date of today
tvDate = (TextView) findViewById(R.id.tvDate);
// display the wind speed
tvWindSpeed = (TextView) findViewById(R.id.tvWindSpeed);
// Set wind speed icon
tvWindSpeed.setCompoundDrawablesWithIntrinsicBounds(getResources()
.getDrawable(R.drawable.icon_wind), null, null, null);
// display the pressure
tvPressure = (TextView) findViewById(R.id.tvPressure);
// Set wind speed icon
tvPressure.setCompoundDrawablesWithIntrinsicBounds(getResources()
.getDrawable(R.drawable.icon_pressure), null, null, null);
// visualize the current weather condition
ivCurrentWeather = (ImageView) findViewById(R.id.ivCurrentWeather);
// Scrollable forecast
forecastGallery = (HorizontalViewGallery) findViewById(R.id.gForcast);
// Search city button
ivSearch = (ImageView) findViewById(R.id.ivSearch);
// Setting button
ivRemind = (ImageView) findViewById(R.id.ivRemind);
// My location button
ivMyLocation = (ImageView) findViewById(R.id.ivMyLocation);
// Temp unit setting Button
ivUnit = (ImageView) findViewById(R.id.ivUnit);
if (getTempUnit().equals(PARAM_TEMP_UNIT_C))
ivUnit.setImageDrawable(getResources().getDrawable(
R.drawable.button_unit_f));
else if (getTempUnit().equals(PARAM_TEMP_UNIT_F))
ivUnit.setImageDrawable(getResources().getDrawable(
R.drawable.button_unit_c));
// Refresh button
ivRefresh = (ImageView) findViewById(R.id.ivRefresh);
// Search field
etSearch = (MyCustomEditText) findViewById(R.id.etSearch);
// set the animation of search field
// Animation Duration in milliseconds;
int duration = 500;
// Inflate animation
final AnimationSet inflate = new AnimationSet(true);
ScaleAnimation scaleIn = new ScaleAnimation(0f, 1.0f, 1.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF,
0.5f);
scaleIn.setDuration(duration);
inflate.addAnimation(scaleIn);
inflate.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
etSearch.setVisibility(View.VISIBLE);
etSearch.requestFocus();
showSoftKeyboard(etSearch);
}
});
// Deflate animation
final AnimationSet deflate = new AnimationSet(true);
ScaleAnimation scaleDe = new ScaleAnimation(1.0f, 0f, 1.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF,
0.5f);
scaleDe.setDuration(duration);
deflate.addAnimation(scaleDe);
deflate.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
etSearch.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
hideSoftKeyboard(etSearch);
}
});
etSearch.setInflation(inflate);
etSearch.setDeflation(deflate);
// Running the change of digital clock on separate UI thread
// to avoid any delay of other action on UI.
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!Utils.androidMinimum(API_JELLY_BEAN_MR1)) {
// Using the widget class {@code DigitalClock} if the
// android api is less than 17
DigitalClock dcClock = (DigitalClock) findViewById(R.id.dcClock);
dcClock.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s,
int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
// Removed seconds
if (s.length() >= 5) {
if (s.charAt(4) == ':') {
s.delete(4, s.length());
} else if (s.length() >= 6
&& s.charAt(5) == ':') {
s.delete(5, s.length());
}
}
}
});
} else {
// Using the widget class {@code TextClock} if the android
// api is greater than or equal to 17
TextClock dcClock = (TextClock) findViewById(R.id.dcClock);
dcClock.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s,
int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
// Removed seconds
if (s.length() >= 5) {
if (s.charAt(4) == ':') {
s.delete(4, s.length());
} else if (s.length() >= 6
&& s.charAt(5) == ':') {
s.delete(5, s.length());
}
}
}
});
}
}
});
mIconFinder = new IconFinder(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* Create a new location client, using the enclosing class to handle
* callbacks.
*/
mLocationClient = new LocationClient(this, this, this);
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(UPDATE_INTERVAL);
// Set the fastest update interval to 1 second
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
setContentView(R.layout.activity_main);
.
.
.
您能否解释一下管理新权限系统的最佳方式是什么?请用简单的方式向我解释
我正在使用权限 ACCESS_FINE_LOCATION 但是当运行时出现错误:需要 ACCESS_FINE_LOCATION 权限为什么? 提前致谢。 最佳答案 ACCESS_FINE_LOCAT
我是 android 开发的新手,现在我很难获取当前用户位置。 list : 主要 Activity : int permissionCheck = ContextCompat.checkSel
下面是我的AndroidManifest.xml... 如您所见,我添加了获取位置信息所需的适当权限。但
我有这个代码 if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != Pack
我有点害羞。但是找不到问题所在。 这是我的 list 。这是我的代码: pub
我只在使用模拟器时遇到了一个奇怪的错误。我发现了一个 9 个月前有相同问题的问题,但根本没有答案... 我正在使用谷歌播放服务位置来获取我的应用程序中的位置,并且我确定我的 list 权限并且一切都在
我在我的应用程序中请求 FINE_LOCATION 时遇到了一些问题。我试图阅读一些关于 ACCESS_FINE_LOCATION 的内容,我知道我应该将它与 ACCESS_COARSE_LOCATI
我在我的应用程序中请求 FINE_LOCATION 时遇到了一些问题。我试图阅读一些关于 ACCESS_FINE_LOCATION 的内容,我知道我应该将它与 ACCESS_COARSE_LOCATI
我正在使用 SDK-23,每次运行应用程序时,我的 SecurityException 都会被抛出,调试器的错误如下所示: java.lang.SecurityException: "gps" loc
我最近收到来自 Google 的通知,要求更新我们声明在应用内使用原生地理定位的方式。 在 Ionic (v1) 中,安装了 cordova-plugin-geolocation 2.3.0 “Geo
我正在更新我的应用程序以使用新的 Android Marshmallow 权限框架,看起来用户在运行时授予 ACCESS_FINE_LOCATION 权限就足以使应用程序正常工作。这就是我所做的: p
我正在尝试在 Android(2.2 和 2.3)中使用 GPS,但在尝试使用 LocationManager 对象时出现以下错误: WARN/System.err(522): java.lang.S
向我的 list 文件添加权限时,以下 xml 有效。 但是,这个 xml 不起作用。 我应该使用哪一个?如果是第一个,为什么不工作?我该如何解决? 另外,我收到了一个与 Android 6.0
有很多类似的问题被问到,但似乎没有一个能解决我的问题。 我已经应用了文档中提到的运行时权限,但仍然收到运行时错误 LocationServices.FusedLocationApi.requestLo
这个问题在这里已经有了答案: Android permission doesn't work even if I have declared it (12 个答案) 关闭2 年前。 我在另一个应用程
我想从 NETWORK_PROVIDER 获取准确位置,同时关闭 GPS 以节省电量。这似乎是不可能的,因为 android,当指定 ACCESS_FINE_LOCATION 时,即使没有向 GPS_
我目前正在尝试获取用户当前位置的纬度和经度。我在 list 中启用了以下权限。 TargetSDK和min sdk都是23
我有一个 GPS 应用程序已经在 list 中请求 ACCESS_FINE_LOCATION 权限,现在我想添加一个需要 ACCESS_COARSE_LOCATION 的库 (MoPub)。 我是否正
我设置了beacon后台扫描using this tutorial在 BaseApplication 类中,但在 Marshmallow 运行设备中,它显示此日志: Caught a RuntimeE
我的应用正在尝试访问设备的位置,并且我在 AndroidManifest.xml 中包含了以下内容: 我已经按如下方式实现了 Google
我是一名优秀的程序员,十分优秀!