- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个几年前开发的 Android 应用程序。它仍在 Play 商店中,我会不断更新它以修复 Eclipse 和旧版 Android 开发工具(我从未使用过 Android Studio)的小错误。
我的应用程序在第一次启动时开始从服务器下载数据并将其保存在内部数据库中(我使用了 AyncTask,这里是源代码:https://pastebin.com/cKqXNYxm)。在大多数手机上一切顺利。
但在某些手机上下载失败,用户无法使用该应用程序。我得到了其中一部手机,并将其连接到 LogCat 以查看会发生什么。这是日志:
04-04 21:07:50.238: I/CastMediaRouteProvider(2082): in onDiscoveryRequestChanged: request=DiscoveryRequest{ selector=MediaRouteSelector{ controlCategories=[android.media.intent.category.LIVE_VIDEO, android.media.intent.category.REMOTE_PLAYBACK, com.google.android.gms.cast.CATEGORY_CAST/08FF1091, com.google.android.gms.cast.CATEGORY_CAST/4574A331] }, activeScan=false, isValid=true }
04-04 21:07:50.251: W/CastMediaRouteProvider(2082): Not a Cast compatible category: android.media.intent.category.LIVE_VIDEO
04-04 21:07:50.251: I/CastMediaRouteProvider(2082): Logging initial network connection state.
04-04 21:07:50.347: I/CastMediaRouteProvider(2082): Network connectivity changed
04-04 21:07:50.372: I/DeviceScanner(2082): [MDNS] Filter criteria: 08FF1091,CC1AD845,4574A331
04-04 21:07:50.372: I/DeviceScanner(2082): [MDNS] updateScannerState: No filter criteria was added.
04-04 21:07:50.372: I/DeviceScanner(2082): [MDNS] updateScannerState: No filter criteria was removed.
04-04 21:07:50.479: W/MdnsClient_Cast(2082): #acquireLock. Multicast lock not held. Acquiring. Subtypes:"4574A331,CC1AD845,08FF1091"
04-04 21:07:50.501: I/DeviceScanner(2082): [CastNearby] Filter criteria: 08FF1091,CC1AD845,4574A331
04-04 21:07:50.501: I/DeviceScanner(2082): [CastNearby] updateScannerState: No filter criteria was added.
04-04 21:07:50.501: I/DeviceScanner(2082): [CastNearby] updateScannerState: No filter criteria was removed.
04-04 21:08:08.860: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:08:09.020: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:08:09.063: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:08:09.085: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:08:09.100: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:08:09.135: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:08:09.265: I/art(1879): Background sticky concurrent mark sweep GC freed 49907(2MB) AllocSpace objects, 18(288KB) LOS objects, 11% free, 22MB/26MB, paused 7.887ms total 67.577ms
04-04 21:08:10.048: I/Icing(2082): Indexing 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1 from com.google.android.gms
04-04 21:08:10.078: W/Icing(2082): CLD2 bad utf8
04-04 21:08:10.114: I/Icing(2082): Indexing done 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1
04-04 21:08:10.546: I/WearableService(1879): Wear is not allowed to run on this device. Not starting Wear service.
04-04 21:08:10.547: D/WearableService(1879): callingUid 10020, callindPid: 1879
04-04 21:08:23.830: I/CastMediaRouteProvider(2082): in onDiscoveryRequestChanged: request=null
04-04 21:08:23.840: W/MdnsClient_Cast(2082): Multicast lock held. Releasing. Subtypes:"4574A331,CC1AD845,08FF1091"
04-04 21:08:23.872: W/MdnsClient(2082): unicast receiver thread is already dead.
04-04 21:09:06.643: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:09:06.814: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:06.848: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:06.881: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:06.898: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:06.958: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:09:07.841: I/Icing(2082): Indexing 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1 from com.google.android.gms
04-04 21:09:07.864: W/Icing(2082): CLD2 bad utf8
04-04 21:09:07.876: I/Icing(2082): Indexing done 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1
04-04 21:09:43.012: W/GCoreFlp(1879): No location to return for getLastLocation()
04-04 21:09:51.519: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:09:51.629: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:51.674: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:51.712: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:51.767: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:09:51.826: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:09:52.662: I/Icing(2082): Indexing 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1 from com.google.android.gms
04-04 21:09:52.682: W/Icing(2082): CLD2 bad utf8
04-04 21:09:52.699: I/Icing(2082): Indexing done 26F5DFBF7CB0FE13B1ED2D2D8BA3F397144A57D1
04-04 21:11:36.806: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:13:50.296: V/NativeCrypto(1879): Read error: ssl=0xb84d38c0: I/O error during system call, Connection reset by peer
04-04 21:13:50.315: V/NativeCrypto(1879): SSL shutdown failed: ssl=0xb84d38c0: I/O error during system call, Broken pipe
04-04 21:13:50.333: W/GCM(1879): Lowering wifi heartbeat interval 1 notch to 230000, good=0 bad=2
04-04 21:18:17.073: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:18:20.076: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:18:20.528: I/Authzen(2082): [DeviceStateSyncManager] Device state fast sync is disabled
04-04 21:18:20.581: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.582: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.582: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.582: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.582: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.583: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.583: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.583: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.583: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:18:20.586: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:27:48.016: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:29:01.013: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:29:03.196: I/Authzen(2082): [DeviceStateSyncManager] Device state fast sync is disabled
04-04 21:29:03.233: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.233: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.233: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.234: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.234: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.234: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.235: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.235: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.235: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:03.236: I/DeviceCache(2082): Unable to convert the the network interface's MAC Address to string. MAC address cannot be null.
04-04 21:29:04.014: D/BluetoothAdapter(1879): 341170672: getState() : mService = null. Returning STATE_OFF
04-04 21:29:10.297: W/GeofencerStateMachine(1879): Ignoring removeGeofence because network location is disabled.
04-04 21:29:11.075: E/WorkSourceUtil(2082): Could not find package: it.myapp.app
04-04 21:29:11.076: I/Icing(2082): doRemovePackageData it.myapp.app
04-04 21:29:11.133: I/LocationSettingsChecker(2082): Removing dialog suppression flag for package it.myapp.app
04-04 21:29:11.138: D/Wear_Controller(2082): Received broadcast action=android.intent.action.PACKAGE_REMOVED and uri=it.myapp.app
04-04 21:29:11.295: E/NetworkScheduler.SR(1879): Invalid parameter app
04-04 21:29:11.296: E/NetworkScheduler.SR(1879): Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
04-04 21:29:11.461: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:29:11.467: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:29:11.475: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:29:12.207: I/WearableService(1879): Wear is not allowed to run on this device. Not starting Wear service.
04-04 21:29:12.207: D/WearableService(1879): callingUid 10020, callindPid: 1879
04-04 21:29:12.482: I/Icing(2082): Indexing 11154CFA753891357620E30C887251401ECA34E6 from com.google.android.gms
04-04 21:29:12.517: I/Icing(2082): Indexing done 11154CFA753891357620E30C887251401ECA34E6
04-04 21:29:18.135: W/PlatformStatsUtil(2082): Could not retrieve Usage & Diagnostics setting. Giving up.
04-04 21:29:22.585: E/NetworkScheduler.SR(1879): Invalid parameter app
04-04 21:29:22.585: E/NetworkScheduler.SR(1879): Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
04-04 21:29:22.605: I/iu.Environment(2082): update battery state; isPlugged? true*
04-04 21:29:22.660: I/iu.FingerprintManager(2082): Start processing all media
04-04 21:29:22.870: I/iu.FingerprintManager(2082): Start processing media store URI: content://media/external/images/media
04-04 21:29:22.980: I/iu.UploadsManager(2082): num queued entries: 0
04-04 21:29:23.041: I/iu.UploadsManager(2082): num updated entries: 0
04-04 21:29:23.086: W/SQLiteConnectionPool(2082): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-04 21:29:23.091: W/SQLiteConnectionPool(2082): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-04 21:29:23.094: W/SQLiteConnectionPool(2082): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-04 21:29:23.107: I/iu.SyncManager(2082): NEXT; no task
04-04 21:29:23.171: W/PlatformStatsUtil(2082): Could not retrieve Usage & Diagnostics setting. Giving up.
04-04 21:29:23.208: I/iu.FingerprintManager(2082): Start processing media store URI: content://media/external/video/media
04-04 21:29:23.214: I/iu.FingerprintManager(2082): Start processing media store URI: content://media/phoneStorage/images/media
04-04 21:29:23.216: I/iu.FingerprintManager(2082): Start processing media store URI: content://media/phoneStorage/video/media
04-04 21:29:23.237: I/iu.FingerprintManager(2082): Finished generating fingerprints; 0,577 seconds
04-04 21:29:23.238: I/iu.FingerprintManager(2082): numSeen=1872 numGenerated=3 numDeleted=11 numFailed=0
04-04 21:29:33.041: W/PlatformStatsUtil(2082): Could not retrieve Usage & Diagnostics setting. Giving up.
04-04 21:29:35.099: D/Wear_Controller(2082): Received broadcast action=android.intent.action.PACKAGE_ADDED and uri=it.myapp.app
04-04 21:29:35.251: I/WearableService(1879): Wear is not allowed to run on this device. Not starting Wear service.
04-04 21:29:35.254: D/WearableService(1879): callingUid 10020, callindPid: 1879
04-04 21:29:35.279: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:29:35.295: I/Icing(2082): Usage reports 0 indexed 0 rejected 0 imm upload false
04-04 21:29:35.320: W/IcingInternalCorpora(2082): getNumBytesRead when not calculated.
04-04 21:29:36.306: I/Icing(2082): Indexing 11154CFA753891357620E30C887251401ECA34E6 from com.google.android.gms
04-04 21:29:36.402: I/Icing(2082): Indexing done 11154CFA753891357620E30C887251401ECA34E6
04-04 21:29:40.870: W/PlatformStatsUtil(2082): Could not retrieve Usage & Diagnostics setting. Giving up.
我认为问题可能出在这些消息上:
04-04 21:29:11.295: E/NetworkScheduler.SR(1879): Invalid parameter app
04-04 21:29:11.296: E/NetworkScheduler.SR(1879): Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
...或者可能与 SSL 连接有关:
04-04 21:13:50.296: V/NativeCrypto(1879): Read error: ssl=0xb84d38c0: I/O error during system call, Connection reset by peer
04-04 21:13:50.315: V/NativeCrypto(1879): SSL shutdown failed: ssl=0xb84d38c0: I/O error during system call, Broken pipe
我不知道可能是什么问题。我尝试了几种设备,结果如下:
它适用于以下手机:
它不适用于以下手机(它在 AsynTask 执行期间崩溃):
关于故障排除可能需要了解的另一件事是,大约 2 个月前,我在我的主机上启用了 SSL 证书,应用程序从中获取数据。
我已经搜索过关于这个问题的类似问题,但没有一个对我有帮助。由于在大多数手机上该应用程序都可以正常运行,所以我不明白为什么在旧版本的 Android 上它会因该 LogCat 而崩溃。有什么想法吗?
最佳答案
AsynTask 错误的原因是 DefaultHttpClient
与 SSL 连接的使用。自 API 级别 22 起,Android 已弃用 Apache 模块,其中包括 DefaultHttpClient。我解决了替换 doInBackground
方法中的一些代码的问题。
之前:
@Override
protected String doInBackground(String... urls) {
int timeout = 10;
int i, count = 0;
BasicHttpParams basicParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicParams, timeout * 1000);
HttpConnectionParams.setSoTimeout(basicParams, timeout * 1000 );
DefaultHttpClient client = new DefaultHttpClient(basicParams);
StringBuilder stringBuilder = new StringBuilder();
for (i = 0; i < urls.length; i++) {
HttpGet request = new HttpGet(urls[i]);
request.addHeader("Cache-Control", "no-cache");
try {
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStreamReader in = new InputStreamReader(entity.getContent());
BufferedReader reader = new BufferedReader(in);
String line = "";
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
count++;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
publishProgress(count * 100 / urls.length);
}
return stringBuilder.toString();
}
之后:
public static final int CONNECTON_TIMEOUT_MILLISECONDS = 60000;
@Override
protected String doInBackground(String... urls) {
int i, count = 0;
String urlsString = "";
for (i = 0; i < urls.length; i++) {
try {
urlsString += executeGetHttpRequest(urls[i]);
} catch (IOException e) {
e.printStackTrace();
return null;
}
count++;
publishProgress(count * 100 / urls.length);
}
return urlsString;
}
public static String executeGetHttpRequest(final String path) throws ClientProtocolException, IOException {
String result = null;
HttpURLConnection urlConnection = null;
try {
URL url = new URL(path);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(CONNECTON_TIMEOUT_MILLISECONDS);
urlConnection.setReadTimeout(CONNECTON_TIMEOUT_MILLISECONDS);
result = readStream(urlConnection.getInputStream());
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
return result;
}
private static String readStream(InputStream is) throws IOException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
StringBuilder total = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
total.append(line);
}
if (reader != null) {
reader.close();
}
return total.toString();
}
多亏了这个answer .
上面的代码是关于 GET 请求的。由于这个 answer,我还解决了 POST 请求时 AsyncTask 的问题.
关于android - 无法修复 AsyncTask 崩溃 : PendingIntent or SSL connection or other causes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43250241/
我想了解 PendingIntent.FLAG_NO_CREATE 的行为。我想知道它什么时候返回 null 什么时候不返回。这是事件发生的顺序: alarmIntent = new Intent(c
我正在尝试请求网络,因此我构建了 NetworkRequest 并构建了 PendingIntent, ConnectivityManager conn_manager = (Connectivit
我一直在使用警报管理器。一旦我设置了一个 PendingIntent 来触发警报,我想取消它。 How do I achieve this? 帮助将不胜感激。 最佳答案 下面这几行代码肯定可以帮助您删
我正在尝试在 Android 中创建一个 PendingIntent。这是代码 mNotificationIntent = new Intent(getApplicationContent(), My
我有三个 Activity (Home、Search、Destination),我可以用它们来描述我的用户体验流程。 Home Activity 是我的启动器 Activity ,然后是搜索 Acti
我试图从 API 中了解 PendingIntent 的用途。 有时我使用的一些方法需要这样做,但我仍然没有得到正确的想法。 谁能解释一下吗?为什么我不能只使用上下文? 谢谢 莫希克 最佳答案 Pen
我在 Android 中开发闹钟时遇到问题。当我触发包含必须在计划时间启动的 Activity 的 PendingIntent 时,它运行良好。但是,当闹钟响起并且我按贪睡 5 分钟并使用不同的请求代
我得到了一个 IntentService,它在 onHandleIntent(Intent) 中同步执行一些长时间运行的工作。因此,只要服务运行,我就会显示一个通知。现在我想在用户点击通知后停止服务。
我有这个... button = (Button) findViewById(R.id.start_repeating); button.setOnClickListener(new OnClickL
在我的应用程序中,我有一个显示 2 个选项的对话框:Copy 和 Dismiss 当用户单击 Copy 时,我希望在状态栏中收到通知。 public void showDialog(final Str
我有一个会显示通知的服务。通知显示正确,但当我点击通知时没有任何反应。它应该在我的应用程序中打开一个 Activity 。这是我的代码: public class ServiceCheckExpens
我正在我的游戏中创建一个通知。如果玩家有一段时间没有玩游戏,我想显示通知。我正在使用以下带有警报设置的 PendingIntent 来创建通知。有了这个,我就可以创建通知。 问题:如果玩家玩游戏,我需
所以这段代码是在我的服务开始在前台启动后从内部运行的。这也会创建将留在那里的通知。我有很多问题/疑问: 1) 点击通知只会打开应用信息,不会打开我的 PendingIntent。 2) 未设置我的内容
如何创建多个 PendingIntent?我有几个通知,当用户按下最后一个通知时,一切正常,但点击通知没有响应。我的代码是: Intent notificationIntent = new Inten
我正在运行一项服务,该服务会在特定事件的通知栏上发出通知。在该通知中,我设置了一个 PendingIntent 以启动另一个应用程序。出于某种原因,当我根据通知采取行动时,它不会启动其他应用程序。这是
我有一个名为 sendNotification 的方法,可以多次调用。 private PendingIntent createNotificationIntent(Context context,
我有一个导航应用程序。我想获得可能暂时不会到达的位置信息,具体取决于 GPS 锁定所需的时间——或者接收信号不好时的时间。 我计划使用 LocationManager.requestLocationU
我有一个 Android 库,它有一个创建 Notification 的 Service。据我了解,Notification 必须有一个 contentIntent (PendingIntent) 集
当我们将 0 作为标志传递给 PendingIntent 时,如下所示: PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0); does
我在尝试通过 Intent 和未决 Intent 将数据传递给 BroadcastReceiver 时遇到了一些问题,涉及接近警报。更具体地说,我试图传递一个对象,其中包括用户不断变化的位置。我已经尝
我是一名优秀的程序员,十分优秀!