相关疑难解决方法(0)

在Android Studio中添加资源文件夹

Android Studio再次改变了它的项目结构......现在它已经改变了

project
---/app-module
   ---/manifests
   ---/res
   ---/java
Run Code Online (Sandbox Code Playgroud)

我一直在网上寻找,但我找不到资产文件夹的位置.当我尝试通过Android Studio中的目录查看器(右键单击,新建......目录)创建文件夹时,"目录"选项不可用.唯一可用的选项是:

Java Class
File
Module
Package
Image Asset
Run Code Online (Sandbox Code Playgroud)

这些都不会做我想要的.

有没有人想到这个?

android android-studio

73
推荐指数
4
解决办法
10万
查看次数

Android - 文件提供程序 - 权限拒绝

我有两个应用程序:app1和app2.

App2有:

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.android.provider.ImageSharing"
        android:exported="false"
        android:grantUriPermissions="true" >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)

paths.xml:

<paths>

     <files-path name="my_images" path="images/"/>

</paths>
Run Code Online (Sandbox Code Playgroud)

App2从App1的Activity中接收请求以获取图像的URI.确定URI后,App2活动执行以下操作:

Intent intent = new Intent();

intent.setDataAndType(contentUri, getContentResolver().getType(contentUri));

int uid = Binder.getCallingUid();
String callingPackage = getPackageManager().getNameForUid(uid);

getApplicationContext().grantUriPermission(callingPackage, contentUri,
                    Intent.FLAG_GRANT_READ_URI_PERMISSION);

setResult(Activity.RESULT_OK, intent);
finish();
Run Code Online (Sandbox Code Playgroud)

从App2收到结果后,App1执行以下操作:

Uri imageUri = data.getData();
if(imageUri != null) {
    ImageView iv = (ImageView) layoutView.findViewById(R.id.imageReceived);
    iv.setImageURI(imageUri);
}
Run Code Online (Sandbox Code Playgroud)

在App1中,从App2返回时,我得到以下异常:

java.lang.SecurityException:Permission Denial:从ProcessRecord {52a99eb0 3493:com.android.App1.app/u0a57}(pid = 3493,uid = 10057)打开提供者android.support.v4.content.FileProvider uid 10058

我究竟做错了什么 ?

android android-fileprovider

58
推荐指数
5
解决办法
5万
查看次数

Intent.resolveActivity 在 API 30 中返回 null

查看intent.resolveActivity != null 但启动 Intent 会引发 ActivityNotFound 异常,我在打开浏览器或具有深度链接的应用程序时写道:

private fun openUrl(url: String) {
    val intent = Intent().apply {
        action = Intent.ACTION_VIEW
        data = Uri.parse(url)
//        setDataAndType(Uri.parse(url), "text/html")
//        component = ComponentName("com.android.browser", "com.android.browser.BrowserActivity")
//        flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + Intent.FLAG_GRANT_READ_URI_PERMISSION
    }
    val activityInfo = intent.resolveActivityInfo(packageManager, intent.flags)
    if (activityInfo?.exported == true) {
        startActivity(intent)
    } else {
        Toast.makeText(
            this,
            "No application can handle the link",
            Toast.LENGTH_SHORT
        ).show()
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用。在 API 30 模拟器中找不到浏览器,而一个常见的解决方案有效:

private fun openUrl(url: String) {
    val intent …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-intent activitynotfoundexception android-11

56
推荐指数
5
解决办法
2万
查看次数

Android共享文件,通过电子邮件或其他应用程序发送

我的Android应用程序中有一个文件列表,我希望能够获取所选项目并通过电子邮件或任何其他共享应用程序发送.这是我的代码.

Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_EMAIL, getListView().getCheckedItemIds());
                    sendIntent.setType("text/plain");
                    startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)

java android sharing android-intent

38
推荐指数
4
解决办法
4万
查看次数

Android打开pdf文件

我正在开发一个Android应用程序,我必须打开一些文件.

这是我使用intent的代码:

public class FacturaActivity extends Activity {

    (...)

    public void downloadInvoice(View view) {
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file),"application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    }
}
Run Code Online (Sandbox Code Playgroud)

文件位于SD卡的根目录中,我可以手动打开它.

问题

应用程序在到达startActivity(intent)时关闭.我认为问题出在AndroidManifest.xml文件中,但我不知道如何正确使用它.

AndroidManifest.xml中

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name="###.MyApplication" > <!--cant show complete name-->
    <activity
        android:name="###.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity 
        android:name=".FacturaActivity" >
    </activity>

</application>
Run Code Online (Sandbox Code Playgroud)

logcat的

07-03 15:49:13.094: E/AndroidRuntime(1032): FATAL EXCEPTION: …
Run Code Online (Sandbox Code Playgroud)

pdf android file android-manifest

30
推荐指数
3
解决办法
10万
查看次数

intent.resolveActivity!= null但是启动intent会抛出一个ActivityNotFound异常

我在这里发布这个问题用于教育目的,因为我无法在任何地方找到答案,最终找到了原因,即我自己.

这是有问题的代码:

// initially getting the intent from polling the PackageManager about activities resolving Search intent.

ComponentName componentName = intent.resolveActivity(pm);

if (componentName != null) {
    context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

尽管检查我得到一个ActivityNotFound异常.

编辑:显然这一点对每个人来说并不明显:为什么有一个活动解决了意图,但试图启动它会抛出一个ActivityNotFound异常 - 两个事实显然是矛盾的?

android android-intent

24
推荐指数
1
解决办法
1万
查看次数

打开pdf文件错误:无法访问此文件检查位置或网络,然后重试.Android 6 Marshmallow

我试图从外部存储器获取文件,然后我必须使用意图将该文件发送到pdf阅读器.以前下面的代码工作正常,但安装Android 6(Marshmallow更新)后,我的代码无法正常工作并获取Toast消息

" 无法访问此文件检查位置或网络,然后重试."

(这是由于新的Android运行时权限).我刚尝试了所有的解决方案(内容提供商等,但没有工作)任何解决方案?

 File file = new File(getFilesDir(), "myfile.pdf");
 Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        Intent intentChooser = Intent.createChooser(intent, "Choose Pdf Application");
        try {
            startActivity(intentChooser);
        } catch (ActivityNotFoundException e) {
            //com.adobe.reader
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.adobe.reader")));
        }
Run Code Online (Sandbox Code Playgroud)

android android-6.0-marshmallow

6
推荐指数
3
解决办法
7093
查看次数