在使用ACTION_SEND意图时,如何过滤掉特定应用? 这个问题已经以各种方式提出,但我无法根据给出的答案收集解决方案.希望有人可以提供帮助.我想提供在应用程序内共享的功能.根据Android Dev Alexander Lucas的建议,我更倾向于使用意图并且不使用Facebook/Twitter API.

使用ACTION_SEND意图共享非常好,但问题是(1)我不希望每个共享选项,我宁愿将其限制为FB,Twitter和电子邮件,以及(2)我不想分享每个共享应用程序都是一样的.例如,在我的推特分享中,我将包括一些提及和主题标签限制为140或更少,而Facebook分享将包括链接和功能图像.
是否可以限制ACTION_SEND(共享)意图的选项?我已经看到了使用PackageManager和queryIntentActivities的一些事情,但是却无法弄清楚PackageManager和ACTION_SEND意图之间的联系.
要么
如果我可以使用ACTION_SEND意图直接进入Facebook或Twitter而不是弹出对话框,而不是过滤共享应用程序,我的问题也可以解决.如果是这种情况,那么我可以创建自己的对话框,当他们点击"Facebook"创建一个特定于Facebook的意图,然后将它们一直发送到Facebook.与Twitter相同.
或者是不可能的?Facebook和Twitter API是唯一的方式吗?
我有一个Android应用程序,它支持通过其他应用程序发送文本.因此,它使用ACTION_SEND意图和EXTRA_TEXT字段.选择器向我提供了可以处理这种意图的所有应用程序.这些是推特,电子邮件,...和Facebook.但是当我选择Facebook时,它会打开浏览器并转到以下页面:
http://m.facebook.com/sharer.php?u=mytext
它显示我的文本和提交按钮.但是,当我按下提交按钮时,没有任何事情发生.该页面再次加载.我想也许只能通过Facebook应用程序发送URL.可能是吗?
有没有人设法通过Facebook Android应用程序通过ACTION_SEND发送文本?
我想在android中使用ACTION_SEND共享Text + Image,我使用下面的代码,我只能共享Image但我不能与它共享Text,
private Uri imageUri;
private Intent intent;
imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher");
intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.setType("image/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
对此有何帮助?
我试图允许用户将图像共享到设备上的其他应用程序.该图像位于我的应用程序内部存储区域的files /子目录中.它适用于Gmail,但Facebook和Twitter在响应我的意图时都崩溃了.
编辑:Google+也可以.
以下是相关的代码部分.
在Application.xml中
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.iforce2d.myapp.MyActivity"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
XML/filepaths.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="shared" path="shared"/>
</paths>
Run Code Online (Sandbox Code Playgroud)
以下是我的活动中的共享代码:
File imagePath = new File(getContext().getFilesDir(), "shared");
File newFile = new File(imagePath, "snapshot.jpg");
Uri contentUri = FileProvider.getUriForFile(getContext(),
"org.iforce2d.myapp.MyActivity", newFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfos =
getPackageManager().queryIntentActivities(shareIntent,
PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo info : resInfos) {
getContext().grantUriPermission(info.activityInfo.packageName,
contentUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
startActivity(Intent.createChooser(shareIntent, "Share image..."));
Run Code Online (Sandbox Code Playgroud)
contentUri记录时的值是:
content://org.iforce2d.myapp.MyActivity/shared/snapshot.jpg
我只使用Gmail,Facebook和Twitter作为接收应用程序进行了检查,但结果在各种操作系统版本(从2.2.1到4.4.3)中都非常一致,7个设备包含Kindle.
Gmail效果很好.图像缩略图显示在邮件撰写中,并在发送时成功附加到邮件.
Twitter和Facebook都崩溃了,如下所示.
以下是来自logcat的堆栈跟踪,显示了这两个应用程序所遇到的问题,对于它们来说似乎是同样的问题(这取自4.4.3,但错误实际上一直回到2.2. 1尽管错误消息的措辞略有不同):
Caused by:
java.lang.IllegalStateException: …Run Code Online (Sandbox Code Playgroud) 我打算分享图像的意图.这适用于大多数提供商,但适用于Google+.Google+会在没有图片的情况下打开帖子活动并显示祝词"您只能发布存储在设备上的照片".同时.
File f = storeImage(image); // f = /data/data/com.myapp/files/1333070776978.jpg
Uri uri = Uri.fromFile(f);
Intent share = new Intent(Intent.ACTION_SEND);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TITLE,"Share that title");
share.putExtra(Intent.EXTRA_SUBJECT,"Share that subject");
share.putExtra(Intent.EXTRA_TEXT,"Check that out...");
share.putExtra("sms_body", "sms body");
startActivity(Intent.createChooser(share, "Share Image"));
Run Code Online (Sandbox Code Playgroud)
我保存图像
Context.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
Run Code Online (Sandbox Code Playgroud)
我的理解是,通过设置FLAG_GRANT_READ_URI_PERMISSION,我授予Google+特定访问权限.
当我将图像存储到MediaStore时它可以工作,但我实际上不想弄乱用户图像库.
ContentValues values = new ContentValues(2);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.Images.Media.DATA, f.getAbsolutePath());
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏
西蒙
任何试图通过Android分享到Facebook的人都知道,Facebook团队决定忽略共享协议并忽略共享意图中提供的文本(请参阅:通过ACTION_SEND从Android应用程序在Facebook上共享文本)
然而,看来Twitter应用程序已经找到了如何规避这一点.当你在看推文时:

您可以单击推文下方的共享图标,它会显示包含Facebook的应用列表的正常共享对话框:

如果您点击Facebook,您会看到以下视图:

这看起来很完美,显然twitter发送的不仅仅是其他答案似乎提出的链接.此外,如果您分享到消息:

您可以看到文本已正确添加且没有任何问题.twitter是如何让这个工作的?
我试图制作一个应用程序,要求用户选择一个图像文件,然后通过意图发送到另一个应用程序(在这种情况下Whatsapp,但这应该与其他应用程序一起使用)
我这样做是为了请求文件:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
这将返回"content://"URI,但在通过intent发送时:
if (isPackageExisted(whatsAppPackage)) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sendIntent.setType("image/*");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.setPackage(whatsAppPackage);
startActivity(sendIntent);
}else{
goToGooglePlay(whatsAppPackage);
}
Run Code Online (Sandbox Code Playgroud)
Whatsapp显示吐司说不支持文件格式,我可以在logcat上看到堆栈跟踪
java.lang.ClassCastException: android.net.Uri$StringUri cannot be cast to java.util.ArrayList
at android.os.Bundle.getParcelableArrayList(Bundle.java:838)
at android.content.Intent.getParcelableArrayListExtra(Intent.java:5405)
at com.whatsapp.ContactPicker.c(ContactPicker.java:12)
at com.whatsapp.ContactPicker.onCreate(ContactPicker.java:526)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java) …Run Code Online (Sandbox Code Playgroud) 我试图过滤和处理android.intent.action.SEND我Service的一个动作中的意图.我在下面写了以下内容AndroidManifest.xml:
<service
android:name=".app.ScreamerService"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
现在,问题是我没有在"共享通过"选项列表中看到我的应用程序,例如,尝试从浏览器共享网页或联系人列表中的联系人.但是,如果我将intent过滤器移动到主<activity>标签(而不是<service>),我的应用程序名称和图标会出现在"share via"选项列表中.
我在这做错了什么?无法将某个SEND操作定向到服务?
android intentfilter android-manifest android-intent android-sharing
我在将内容分享到我的应用程序之后就得到了这个例外,就在应用程序已经启动的情况下.如果我直接启动应用程序,所有的工作都很好.如果我与我的应用程序分享内容并且应用程序尚未运行,则所有内容都能正常运行.它们不适用于第一种情况.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_real_debrid);
LoginStore.init(getApplicationContext());
AnalyticsManager.init(getApplicationContext());
RDDownloadManager.init(this);
ResponseHandlerManager.init(this);
AppRater.app_launched(this, getString(R.string.app_name));
layout = findViewById(R.id.drawer_layout);
supportActionBar = getSupportActionBar();
mTitle = mDrawerTitle = getTitle();
setFragment(FragmentList.findFragmentById(0).getFragment(), false);
if (layout instanceof DrawerLayout) {
mDrawerLayout = (DrawerLayout) layout;
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
supportActionBar.setDisplayHomeAsUpEnabled(true);
supportActionBar.setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
if (supportActionBar.getTitle().equals(mDrawerTitle))
supportActionBar.setTitle(mTitle);
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
mTitle = supportActionBar.getTitle();
supportActionBar.setTitle(mDrawerTitle);
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
} else {
getSupportActionBar().setHomeButtonEnabled(false);
}
Credentials c …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的SDK中的Facebook新的SharePhoto和SharePhotoContent类共享照片.我想使用图像URL而不是本地存储的图像.
我可以使用本地存储的可绘制资源共享图像:
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.carrots);
SharePhoto photo = new SharePhoto.Builder()
.setImageBitmap(image)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(content);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用图片网址时:
SharePhoto photo = new SharePhoto.Builder()
.setImageUrl(Uri.parse("http://s3-ak.buzzfed.com/static/images/public/verticals/food-title.png?v=201504021353"))
.build();
Run Code Online (Sandbox Code Playgroud)
我所看到的只是Facebook shareDialog中的空白帖子.
有没有其他人尝试过这个并让它发挥作用?
非常感谢!
android ×10
android-sharing ×10
facebook ×3
intentfilter ×2
google-plus ×1
image ×1
twitter ×1
whatsapp ×1