标签: android-intent-chooser

忽略来自意图过滤器的特定网址

如何忽略来自意图过滤器的特定 URL 集。现有过滤器。

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:host="www.example.com" android:scheme="http" />
    <data android:host="www.example.com" android:scheme="https" />
    <data android:host="example.com" android:scheme="http" />
    <data android:host="example.com" android:scheme="https" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

使用上述过滤器,所有 URL 都会在应用程序中打开。我想忽略几个 URL,它必须使用浏览器打开。要忽略的示例网址。

https://www.example.com/privacy-policy
https://www.example.com/tos
https://www.example.com/faq
Run Code Online (Sandbox Code Playgroud)

下面的代码直接打开应用程序。

Uri uri = Uri.parse("https://www.example.com/privacy-policy");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent); // Opens the app directly.
// startActivity(Intent.createChooser(intent, "Select browser")); // Shows current app only.
Run Code Online (Sandbox Code Playgroud)

android intentfilter android-intent android-intent-chooser

5
推荐指数
0
解决办法
1041
查看次数

使用自定义意图操作仅在特定应用程序上下文中启动活动

我需要使用意图过滤器指定我的登录活动:

    <activity
        android:name=".view.LoginActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.example.sdk.LOGIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

我想这样做的原因是我正在开发一个我想在几个项目中使用的 SDK,这是我能弄清楚如何通知 SDK 是登录活动的最好方法,而它是仅在 app 模块中定义。

在我做这样的声明后,我开始像这样的登录活动(在库和应用程序中):

    Intent intent = new Intent();
    intent.setAction("com.example.sdk.LOGIN");
    context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

有可能在同一设备上同时安装两个或多个依赖于同一个 SDK 的应用程序。如果我理解正确,在这种情况下,在这些应用程序中的每一个中,Activity start 将启动一个随机登录活动(应用程序 A 中的调用可能会启动应用程序 B 的登录)。

  1. 我对自定义意图过滤器的工作原理的理解是否正确?
  2. 有没有办法告诉应用程序 A 中的调用只使用应用程序 A 中的意图过滤器声明

也欢迎提出重用登录相关逻辑的替代方法的建议,而不是依赖意图过滤器。

android intentfilter android-intent android-activity android-intent-chooser

5
推荐指数
1
解决办法
4684
查看次数

自定义选择器活动:SecurityException UID n 无权访问 content:// uri

我正在构建一个替代本机 Android 共享对话框的选择器应用程序。它工作正常,除非我尝试通过长按图像> 共享图像从 Chrome 共享图像。

我发现 Google+ 没有捕获异常(它崩溃了),所以我可以通过 Logcat 查看它:

  • 在 Google 上进行图片搜索。
  • 选择一个图像(这应该显示预览)
  • 长按图片
  • 选择“分享图片”
  • 我的选择器活动弹出
  • 选择 Google+
  • Google+ 因以下错误而崩溃:

java.lang.SecurityException: UID 10130 没有权限 content://com.android.chrome.FileProvider/images/screenshot/15307295588677864462883877407218.jpg [user 0]

我的代码(简化):

@Override
public void onCreate() {
    handleIntent();
}

private void handleIntent() {

    // Get intent and payload
    mIntent = getIntent();
    mPayloadIntent = (Intent) mIntent.getParcelableExtra(Intent.EXTRA_INTENT);

    // Nullify some things for queryIntentActivities (or no results will be found)
    mPayloadIntent.setComponent(null);
    mPayloadIntent.setPackage(null);

    // Retrieve a list of targets we can send mPayloadIntent to..
    List<ResolveInfo> targets …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-intent-chooser

5
推荐指数
1
解决办法
1471
查看次数

Android:尽管设置了MIME类型,但隐藏了PDF文件

这是我的意图:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/* , application/pdf, image/*");
Run Code Online (Sandbox Code Playgroud)

但是,当文件资源管理器显示时,PDF文件显示为灰色,即不可选择.这有什么解决方法吗?

pdf android android-intent mime-types android-intent-chooser

4
推荐指数
1
解决办法
4498
查看次数

用户取消意图选择器时会发生事件吗?

在我的Android应用程序中,我希望用户选择,如果存在多个可能的应用程序,则应使用哪个其他应用程序来显示特定图像。因此我得到以下代码:

final Intent intent = new Intent(Intent.ACTION_VIEW)
                       .setDataAndType(uri, IMAGE_MIME_TYPE)
                       .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);

 context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

按预期显示应用选择器。

在我打电话之前,我startActivity打开了一个ProgressDialog,当用户通过后退按钮取消应用选择器时,我想关闭它。识别应用选择器已取消的最佳方法是什么?换句话说-我应该在哪里关闭我的ProgressDialog

android android-intent-chooser

3
推荐指数
1
解决办法
2213
查看次数

选择 Zip 文件的意图

我有一个从 url 下载的 zip 文件,其路径设置为 /storage/emulated/0/myapp/downloadedfile.zip

现在我想通过选择意图打开这个 zip 文件以列出可用的应用程序来打开下载的文件。

我在清单中设置了这个:

 <activity
      android:name=".MyApp"
      android:alwaysRetainTaskState="true"
      android:launchMode="singleInstance"
      android:theme="@style/MyMaterialTheme">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/zip"/>
            </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

现在我调用这种方式来打开意图选择器

File downloadedfile = new File(Environment.getExternalStoragePublicDirectory(Environment.getExternalStorageDirectory() + "/myapp") + "/" + "downloadedfile.zip");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(downloadedfile), "application/zip");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

如果我ESFileExplorer已经安装在我的应用程序上,这很好用

但是我想检查是否有任何预安装的应用程序可用,否则我还需要将其显示playstore为选项之一,以便用户可以下载该应用程序并安装 ESFileExplorer 应用程序。

那么我该怎么做呢?

zip android android-intent android-intent-chooser

2
推荐指数
1
解决办法
3017
查看次数

为什么`Intent.createChooser(shareIntentWithJpgFileName)`退出工作?

图像文件不再通过选择器传递

代码startActivity(intent.createChooser(shareIntentWithJpgFileName))在我的应用程序中运行良好多年,但我注意到大约一个月前它不再将图像文件传递给用户在选择器对话框中选择的应用程序.我怀疑Android操作系统安全改组(再次!),但不知道如何继续.

如果用户在选择器对话框中选择任意数量的选项,则应用程序将打开,但不会显示该.jpg部分是意图的一部分.如果用户选择Google云端硬盘,我会通过它的吐司得到一个错误的提示:

上传失败:请求中不包含任何数据

以前的代码:

String fileName = data.getStringExtra(EXTRA_FILENAME);                    
Log.v(TAG, "Starting Share intent.  fileName: " + fileName); //This shows fileName: /storage/emulated/0/dcim/DalesApp/IMG_20190103_142555_8445288886207383328.jpg              
Intent shareIntentWithJpgFileName = new Intent(Intent.ACTION_SEND);                
shareIntentWithJpgFileName.setType("image/jpeg");                
File filePassedIn = new File(fileName); 
Log.v(TAG, "exists: " + filePassedIn.exists() + " canRead: " + filePassedIn.canRead());   // Result is exists: true canRead: true.  Thanks Mark!           
shareIntentWithJpgFileName.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", filePassedIn));                
shareIntentWithJpgFileName.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);                
startActivity(Intent.createChooser(shareIntentWithJpgFileName, "Share Image"));                
Run Code Online (Sandbox Code Playgroud)

另外,我将此作为以下内容的一部分AndroidManifest.xml:

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

这也是在AndroidManifest.xml …

android android-security android-intent-chooser

2
推荐指数
1
解决办法
371
查看次数