Versuchen, eine App für Google Pappe zu entwickeln, habe ich die Probe aus dem offiziellen SDK heruntergeladen. In der inneren Klasse ImageLoaderTaskKartonprobe, Methode muss von UI-Thread aufgerufen werden
class ImageLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> {
/**
* Reads the bitmap from disk in the background and waits until it's loaded by pano widget.
*/
@Override
protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) {
Options panoOptions = null; // It's safe to use null VrPanoramaView.Options.
InputStream istr = null;
if (fileInformation == null || fileInformation.length < 1
|| fileInformation[0] == null || fileInformation[0].first == null) {
AssetManager assetManager = getAssets();
try {
istr = assetManager.open("andes.jpg");
panoOptions = new Options();
panoOptions.inputType = Options.TYPE_STEREO_OVER_UNDER;
} catch (IOException e) {
Log.e(TAG, "Could not decode default bitmap: " + e);
return false;
}
} else {
try {
istr = new FileInputStream(new File(fileInformation[0].first.getPath()));
panoOptions = fileInformation[0].second;
} catch (IOException e) {
Log.e(TAG, "Could not load file: " + e);
return false;
}
}
panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions);
try {
istr.close();
} catch (IOException e) {
Log.e(TAG, "Could not close input stream: " + e);
}
return true;
}
}
panoWidgetView ist das Widget für das Panorama, und es ist in der Aktivität erklärt, die diese innere Klasse umfasst (die es die Hilfsklasse zu verwalten Einfädeln sein soll). Aber Android Studio gibt mir diesen Fehler: Methode loadImageFromBitmap muss aus dem UI-Thread aufgerufen werden, derzeit abgeleitete Thread ist Worker. Jede mögliche Lösung?
Perfekt. Ich kann keine UI-Operation im Hintergrund ausführen, danke! – sgrumo
Genau! https://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result) –