PendingIntent Intent 传送数据 为null

本文纠正了 PendingIntent 在 Android 中的常见错误用法,并提供了正确的 PendingIntent.getActivity 的实例,包括请求码和标志位的正确设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误写法 :PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mNotificationIntent, 0);

正确写法 : PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, mNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

2061 public void requestLocationUpdates(LocationRequest request, ILocationListener listener, 2062 PendingIntent intent, String packageName) { 2063 if (request == null) request = DEFAULT_LOCATION_REQUEST; 2064 checkPackageName(packageName); 2065 int allowedResolutionLevel = getCallerAllowedResolutionLevel(); ---> 这里指的就是 fine、coarse、no location data 三种 2066 checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, 2067 request.getProvider()); 2068 WorkSource workSource = request.getWorkSource(); 2069 if (workSource != null && !workSource.isEmpty()) { 2070 checkDeviceStatsAllowed(); 2071 } 2072 boolean hideFromAppOps = request.getHideFromAppOps(); 2073 if (hideFromAppOps) { 2074 checkUpdateAppOpsAllowed(); 2075 } 2076 boolean callerHasLocationHardwarePermission = 2077 mContext.checkCallingPermission(android.Manifest.permission.LOCATION_HARDWARE) 2078 == PERMISSION_GRANTED; 2079 LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel, 2080 callerHasLocationHardwarePermission); 2081 2082 final int pid = Binder.getCallingPid(); 2083 final int uid = Binder.getCallingUid(); 2084 // providers may use public location API's, need to clear identity 2085 long identity = Binder.clearCallingIdentity(); 2086 try { 2087 // We don't check for MODE_IGNORED here; we will do that when we go to deliver 2088 // a location. 2089 checkLocationAccess(pid, uid, packageName, allowedResolutionLevel); 2090 2091 synchronized (mLock) { 2092 Receiver recevier = checkListenerOrIntentLocked(listener, intent, pid, uid, 2093 packageName, workSource, hideFromAppOps); 2094 requestLocationUpdatesLocked(sanitizedRequest, recevier, pid, uid, packageName); ---> 继续看下这个 2095 } 2096 } finally { 2097 Binder.restoreCallingIdentity(identity); 2098 } 2099 } 解析这段代码的逻辑
最新发布
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值