我想放一张我的SD卡中的图片,但它没有出现,我认为滑行库或许可证有问题,我在那里堆了2天请帮助我。
public class MainActivity extends AppCompatActivity {
public final static String PATH_SD_CARD = "/Images/Mj.jpg";
private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
@TargetApi(Build.VERSION_CODES.M)
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= getPackageManager().PERMISSION_GRANTED) {
// Should we show an explanation?
if (shouldShowRequestPermissionRationale(
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique
return;
}
ImageView img = findViewById(R.id.imageView);
Glide.with(this)
.load(Environment.getExternalStorageDirectory().getAbsolutePath()+PATH_SD_CARD)
.into(img);
}
}
答案 0 :(得分:1)
你有没有在android清单文件中添加权限,如下面的代码..
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
答案 1 :(得分:0)
调用 2018-04-25 12:44:00,018 ERROR [quartz.core.JobRunShell] [DefaultScheduler_Worker-6] Job DEFAULT.org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean#785aa4ce threw an unhandled Exception:
org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'run' on target class [class org.alfresco.module.org_alfresco_module_wcmquickstart.jobs.DynamicCollectionProcessor] failed; nested exception is org.alfresco.repo.search.impl.lucene.LuceneQueryParserException: 03253095 Request failed 404 /solr4/alfresco/alfresco?wt=json&fl=DBID%2Cscore&rows=1000&df=TEXT&start=0&locale=en_US&alternativeDic=DEFAULT_DICTIONARY&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:321)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:114)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:563)
Caused by: org.alfresco.repo.search.impl.lucene.LuceneQueryParserException: 03253095 Request failed 404 /solr4/alfresco/alfresco?wt=json&fl=DBID%2Cscore&rows=1000&df=TEXT&start=0&locale=en_US&alternativeDic=DEFAULT_DICTIONARY&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON
at org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.postQuery(SolrQueryHTTPClient.java:1159)
at org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.postSolrQuery(SolrQueryHTTPClient.java:1109)
at org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.executeQuery(SolrQueryHTTPClient.java:576)
at org.alfresco.repo.search.impl.solr.SolrQueryLanguage.executeQuery(SolrQueryLanguage.java:58)
at org.alfresco.repo.search.impl.solr.SolrSearchService.query(SolrSearchService.java:355)
at org.alfresco.repo.search.impl.solr.SolrSearchService.query(SolrSearchService.java:159)
at org.alfresco.repo.search.SearcherComponent.query(SearcherComponent.java:73)
at org.alfresco.repo.search.AbstractSearcherComponent.query(AbstractSearcherComponent.java:60)
at sun.reflect.GeneratedMethodAccessor614.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.alfresco.repo.management.subsystems.SubsystemProxyFactory$1.invoke(SubsystemProxyFactory.java:79)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy26.query(Unknown Source)
at org.alfresco.repo.search.impl.SearchServiceSubSystemDelegator.query(SearchServiceSubSystemDelegator.java:98)
at org.alfresco.module.org_alfresco_module_wcmquickstart.jobs.DynamicCollectionProcessor$1$1.execute(DynamicCollectionProcessor.java:253)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:333)
at org.alfresco.module.org_alfresco_module_wcmquickstart.jobs.DynamicCollectionProcessor$1.doWork(DynamicCollectionProcessor.java:242)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:555)
at org.alfresco.module.org_alfresco_module_wcmquickstart.jobs.DynamicCollectionProcessor.runInternal(DynamicCollectionProcessor.java:237)
at org.alfresco.module.org_alfresco_module_wcmquickstart.jobs.DynamicCollectionProcessor.run(DynamicCollectionProcessor.java:200)
at sun.reflect.GeneratedMethodAccessor860.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:312)
... 3 more
并不保证SD卡方式的外部存储,但外部一词引用“应用程序外部”。在大多数情况下,此路径会为您提供:Environment.getExternalStorageDirectory()
。
由于任何不是设备组成部分的“驱动器”的路径可以有不同的名称,因此无论设备如何,您都需要其他方式来查找它。 IMO,最有效和最安全的方法是使用一些标准查询/storage/emulated/0/
。
快速解决方案可能是使用MediaStore
女巫给你getExternalFilesDirs()
你的应用程序帽子“其”目录。该阵列的第二个元素是SDCard上的路径。如果从那里开始两个“级别”(Files[]
),您将获得对“根”SDCard目录的引用。
当然,正如已经提到的那样,请大量使用调试来了解它出错的地方。
答案 2 :(得分:-2)
测试此代码:
redux-saga