正如我在Android文档中所看到的,在将用户发送到另一个应用程序时尝试构建隐式意图。这是避免ActivityNotFoundException的两种方法。
第一 :
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
Run Code Online (Sandbox Code Playgroud)
第二个 :
Intent chooser = Intent.createChooser(intent, title);
if (intent.resolveActivity(getPackageManager()) != null) {
}
Run Code Online (Sandbox Code Playgroud)
现在,我的疑问是区别是什么,我应该使用哪一个?
android android-intent android-activity android-implicit-intent
我阅读了有关接收简单数据的文档。我想接收一个 URL,即来自其他应用程序的文本/纯文本。
所以,我只声明了这个意图过滤器:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
在我的MainActivity.class 中:
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
Run Code Online (Sandbox Code Playgroud)
我将收到的文本处理为:
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI …Run Code Online (Sandbox Code Playgroud) java android intentfilter android-intent android-implicit-intent
我使用了隐式意图,以便在有人单击其他应用程序中的 URL 时打开我的应用程序,我无法看到已部署的应用程序的图标。部署我的应用程序后,如果我返回并尝试找到我的应用程序,我将无法找到它。但它在最近的应用程序中。这是android清单中的代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mindtree.calender">
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<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.calender.com" android:scheme="http"></data>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud) android android-manifest android-intent android-implicit-intent
我正在开发一个图像编辑应用程序,当调用相机时,我可以手动将图片大小更改为 16:9,是否可以通过以编程方式将图片大小设置为 16:9 来打开相机。
下面的代码调用相机
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivityForResult(intent, REQUEST_CAMERA);
Run Code Online (Sandbox Code Playgroud) 我有两个类似的应用程序(一个免费,一个付费).
活动定义为 exported="false"
<activity
android:name=".MyActivity"
android:exported="false"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.mine" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
当我startActivity使用免费应用程序中的相应隐含意图调用时,将显示活动选择器.
我不明白为什么付费应用程序的活动会出现,因为它是 exported="false"
我想我可以添加基于URL的intent过滤器,但我的问题是:为什么当doc读取时,来自其他应用程序的活动会出现
是否可以由其他应用程序的组件启动该活动
android android-manifest android-intent android-activity android-implicit-intent
我有一个应该在后台上传照片的服务.但是,当我尝试启动它时,它无法启动.在logcat中,我注意到我收到了警告Implicit intents with startService are not safe : Intent { .....}.我已经三倍检查了清单中的动作字符串是否相同以及我的开始.我的代码:
清单:
<service android:name=".photosupload.services.PhtosUploadService"
android:exported="false" android:process=":uploadPhotosServiceProcess">
<intent-filter>
<action android:name="com.yoovi.app.photosupload.services.action.START_UPLOAD" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
启动服务代码:
Intent i = new Intent(PhtosUploadService.ACTION_START_UPLOAD);
i.putExtra(PhtosUploadService.ALBUM_ID, albumID);
context.startService(i);
Run Code Online (Sandbox Code Playgroud) 我想在设置屏幕中显示已安装的日历列表,并在其中选择一个.我在Android应用程序Cal中看到了这个功能.可在此处找到Cal app中已安装日历列表的屏幕截图.
我想知道的是"是否可以使用res/XML下的<preference>显示日历列表"?
要么
我是否必须使用PackageManager选择日历列表以查找所有已安装应用程序的列表并仅显示日历应用程序?
我尝试使用以下方法使用<preference>
<Preference android:title="@string/pref_select_calendar" >
<intent
android:action="android.intent.action.PICK"
android:data="content://calendar/calendars" />
</Preference>
Run Code Online (Sandbox Code Playgroud)
但我有android.content.ActivityNotFoundException:找不到处理Intent的Activity
{ act=android.intent.action.PICK dat=content://calendar/calenders }
Run Code Online (Sandbox Code Playgroud)
我错过了什么?或者我正在尝试的方法不正确?任何指针都会非常有用.谢谢.
android calendar android-intent android-calendar android-implicit-intent
String x="Hello World";
String y="You Rock!!!";
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", x);
sendIntent.putExtra("sms_body", y);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过短信发送多个邮件正文,但只有"你摇滚!!!" 被展示.我想要做的是能够显示多个消息并预先格式化(在不同的行上).
所以例如......
Hello World
You Rock!!!
Run Code Online (Sandbox Code Playgroud) 我们需要在应用程序从 Google Play 自动更新后重新启动应用程序的前台服务。对于 SDK < 26,我们在 PACKAGE_REPLACED actoin 上注册了接收器,一切正常。如果隐式意图被禁止,我们如何在 SDK 26 中做同样的事情?谢谢。
我在 android 11 上使用字符串“com.android.camera.action.CROP”开始隐式裁剪意图。首次安装应用程序时无法通过此代码解析其活动。
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
//to check whether there is an cropping app present or not
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(
intent, MATCH_DEFAULT_ONLY);
Run Code Online (Sandbox Code Playgroud)
它不是第一次解析,而是第二次运行,它获取可以处理意图的活动。
在我的Android应用程序中,我使用下面的代码实现了发送短信.
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", "Hello World!");
smsIntent.putExtra("address", "0123456789");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我在设备上有多个SMS应用程序,它会打开选择器以选择发件人应用程序.我不希望打开选择器; 我想从Android的原生短信应用程序发送,而无需打开选择器.所以任何帮助实现这一点将不胜感激.
我尝试从 android/data/mypackage/files/file.pdf 共享 pdf 文件我也在这个应用程序中生成这些 pdf,当我尝试共享它时,pdf 没有出现在电子邮件的附件中,或者谷歌驱动器说:“没有数据共享”。这是我分享pdf的代码:
val aName = intent.getStringExtra("iName")
val file = File(this.getExternalFilesDir(null)?.absolutePath.toString(), "$aName")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, file)
shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
shareIntent.type = "application/pdf"
startActivity(Intent.createChooser(shareIntent, "share.."))
Toast.makeText(this,"$file",Toast.LENGTH_SHORT).show()
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过发送以下意图对 Deezer 进行搜索:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.deezer.com/search/" + query));
this.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在以前的版本中,Web 浏览器打开时带有一个链接,上面写着“在 Deezer 中打开”(或类似内容)。但在当前版本中,这不再起作用。
有没有办法打开 Deezer 应用程序并执行搜索?我已经尝试了以下(没有成功):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://search/" + query));
this.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)