我開發了一個相機android應用程序,它的工作正確,但是當我在android 7中運行它時,它會創建一條消息,指出「應用程序已停止」!我認爲這個問題是從我的代碼文件,這是我的畫廊文件:我的Android應用程序不適用於Android 7
public class Gallery extends Activity {
GridView gv;
ArrayList<File> list;
Context context;
private static VirtualFileSystem vfs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery2);
File f = new File("/myfiles.db");
list = imageReader(f);
gv = (GridView) findViewById(R.id.gridview);
gv.setAdapter(new GridAdapter());
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(getApplicationContext(), viewImage.class).putExtra("img", list.get(position).toString()));
}
});
}
class GridAdapter extends BaseAdapter {
public ImageView iv;
public Bitmap bmp = null;
public File file ;
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
class ViewHolder {
ImageView icon;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Log.e("sara" , "this part takes time");
LayoutInflater inflater = getLayoutInflater();
getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
convertView = getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
iv = (ImageView) convertView.findViewById(R.id.icon);
file = new File(Uri.parse(getItem(position).toString()).getPath());
new myTask(iv, file).execute();
return convertView;
}
private class myTask extends AsyncTask <Void , Void ,Bitmap> {
ImageView iv;
File file;
public myTask(ImageView iv, File file) {
this.iv=iv;
this.file= file;
}
@Override
protected Bitmap doInBackground(Void... params) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
options.inJustDecodeBounds = false;
options.inSampleSize = 2;
try {
bmp = BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return bmp;
}
@Override
protected void onPostExecute(Bitmap aVoid) {
iv.setImageBitmap(aVoid);
}
}
}
ArrayList<File> imageReader (File root) {
final ArrayList<File> a = new ArrayList<>();
File[] files = root.listFiles();
for (int i = files.length - 1; i >= 0; i--) {
if (files[i].isDirectory()) {
// input name directory to array list
a.addAll(imageReader(files[i]));
} else {
if (files[i].getName().endsWith(".jpg")) {
a.add(files[i]);
}
}
}
return a;
}
在該鏈接,它使用「getUriForFile」但我認爲它不能幫助我在這種情況下! 這是我的logcat:
08-07 02:10:21.757 2343-2343 /? E/memtrack:無法加載memtrack 模塊(無此文件或目錄)08-07 02:10:21.757 2343-2343 /? E/android.os.Debug:未能加載memtrack模塊:-2 08-07 02:10:21.913 2349-2349 /? E/memtrack:無法加載memtrack模塊(沒有 這樣的文件或目錄)08-07 02:10:21.913 2349-2349 /? E/android.os.Debug:未能加載memtrack模塊:-2 08-07 02:10:22.220 2370-2370 /? E/cutils-trace:打開跟蹤文件時出錯: Permission denied(13)08-07 02:10:23.334 2390-2390 /? E/memtrack: 無法加載memtrack模塊(無此文件或目錄)08-07 02:10:23.334 2390-2390 /? E/android.os.Debug:未能加載memtrack 模塊:-2 08-07 02:10:23.708 2399-2415 /? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so):dlopen失敗: 庫「/system/lib/egl/libGLES_emulation.so」找不到08-07 02:10:23.802 2399-2399 /? E/AndroidRuntime:致命異常:主 工藝:com.example.zeinab.amndoorbin,PID:2399 顯示java.lang.NullPointerException:取消()調用在android.app.AlarmManager.cancel(AlarmManager空 的PendingIntent 。 java:890) at info.guardianproject.cacheword.CacheWordService.resetTimeout(CacheWordService.java:189) at info.guardianproject.cacheword.CacheWordService.attachSubscriber(CacheWordService.java:145) at info.guardianproject.cacheword.CacheWordHandler $ 2 .onServiceConnected(CacheWordHandler.java:457) at android.app.LoadedApk $ ServiceDispatcher.doConnected(LoadedApk.java:1453) at android.app.LoadedApk $ Se rviceDispatcher $ RunConnection.run(LoadedApk.java:1481) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os。 Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os .ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)08-07 02:10:25.520 2399-2415 /? E/EGL_emulation:tid 2415: eglSurfaceAttrib(1174):error 0x3009(EGL_BAD_MATCH)08-07 02:10:25.612 706-1732 /? E/EGL_emulation:TID 1732: eglSurfaceAttrib(1174):錯誤0x3009(EGL_BAD_MATCH)
https://developer.android.com/about/versions/nougat/android-7.0 -changes.html#sharing-files –
看到這裏:https://stackoverflow.com/a/38858040/7746134 –
請詳細解釋**,**,這是什麼「它不工作」的意思。 – CommonsWare