我在我的应用程序中有一个共享按钮,我想同时共享图像和文本.Gmail中工作正常,但在WhatsApp的,只有图像被发送和Facebook的应用程序崩溃.
我使用共享代码是这样的:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Message");
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/drawable/ford_focus_2014");
try {
InputStream stream = getContentResolver().openInputStream(uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Run Code Online (Sandbox Code Playgroud)
如果我使用"shareIntent.setType("*/*")"Facebook和WhatsApp崩溃.
有办法做到这一点吗?也许同时发送两条消息(WhatsApp).
提前致谢.
如何在 Android 中将图像或视频发送到 WhatsApp 状态(或故事)。
我们可以使用以下方式将图像发送给联系人:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_STREAM, imageURI);
sendIntent.putExtra("jid", "91"+mobile + "@s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT, "whatsapp image caption");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage("com.whatsapp");
sendIntent.setType("image/*");
Run Code Online (Sandbox Code Playgroud)
但如何将其发送到我的 Whatsapp 状态呢?
我正在创建一个社交媒体应用程序,用户可以在其中共享图像、视频、音频等。通过在清单文件中添加以下代码,我成功地接收了从第三方应用程序共享的媒体。
<activity
android:name=".activity.SendToActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
现在,当用户尝试从他们的图库(如 facebook)(设置为个人资料图片)共享图片以直接上传个人资料图片时,我想显示我的应用程序的多个图标。请看截图
当用户尝试从他们的图库中共享图像时,请有人帮助我显示我的应用程序的多个图标。
我有一个视频文件路径,想在社交媒体上共享视频,但是无法共享视频。我正在尝试遵循Android Studio 2.2中的代码,但是无法正常工作。
程式码片段:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button shareBtn = (Button) findViewById(R.id.sharebutton);
shareBtn .setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
File f = new File("/sdcard/VID_20161201123613.mp4");
Uri uriPath = Uri.parse(f.getPath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text");
shareIntent.putExtra(Intent.EXTRA_STREAM, uriPath);
shareIntent.setType("video/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
}
}
);
}
Run Code Online (Sandbox Code Playgroud) 我想使用CustomTabs库,我需要添加一个共享菜单项.该库只接受PendingIntent实例作为菜单项的Action.我想使用以下代码确保在没有Just Once和Always按钮的情况下始终向用户建议列表:
Intent shareIntent = Intent.createChooser(intent, "Choose the application to share.");
Run Code Online (Sandbox Code Playgroud)
但问题是,如果我使用此选择器Intent创建PendingIntent,则CustomTabs for Chrome不会为用户激活选择器:
PendingIntent pendingIntent = PendingIntent.getActivity(context,
requestCode,
shareIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)
有没有办法使用Chooser的Intent作为PendingIntent?
我不能使用以下行来启动Intent,因为库是这样做的,它只接受PendingIntents:
startActivity(Intent.createChooser(i, getString()));
Run Code Online (Sandbox Code Playgroud) android android-pendingintent chrome-custom-tabs share-intent
我想使用kotlin使用共享Intent 在我的CardView中共享文本但是kotlin代码中的最后一行有问题代码
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, "ali")
shareIntent.type = "text/plain"
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))
Run Code Online (Sandbox Code Playgroud)
这是代码中的问题
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))
Run Code Online (Sandbox Code Playgroud)
请帮我
看图像了解我
图片
适配器完整代码
class MyAdapter(context: Context, listItem: ArrayList<com.EliteTeam.comedytaste.Model.Movie>) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
var Context = context
var movieList = listItem;
var layoutInflator = LayoutInflater.from(context)
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder {
var inflateView = layoutInflator.inflate(R.layout.single_item, parent, false)
return MyViewHolder(inflateView)
}
override fun onBindViewHolder(holder: MyViewHolder?, position: Int) {
holder?.moviewTitle?.text = movieList[position].name
holder?.movieDescription!!.text= movieList[position].description
//holder!!.cardImageView!!.background= …Run Code Online (Sandbox Code Playgroud) 我正在开发一个自定义相机应用程序,它捕获图片并将其存储在图库中.当我使用Intent.ACTION_SEND共享该图像时,除了具有API 26的设备(即OREO)之外,它在所有设备上都能正常工作.
我分享图片的代码是:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
Uri uriShare = Uri.fromFile(outFile);
//outfile is the path of the image stored in the gallery
shareIntent.putExtra(Intent.EXTRA_STREAM, uriShare);
startActivity(Intent.createChooser(shareIntent, ""));
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?
在这里,下面的代码将分享 onclick 的内容。通过其他应用分享内容时,有两种内容:一种是标题,另一种是描述。我想在分享时将标题加粗。那可能吗?
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
TextView de = (TextView) v.findViewById(R.id.lblListItem);
TextView ti = (TextView) v.findViewById(R.id.lblListHeader);
String selected = ti.getText().toString() + de.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, selected);
startActivity(Intent.createChooser(intent, "Share via"));
return false;
}
});
Run Code Online (Sandbox Code Playgroud) 我正在内部存储上保存文件.它只是一个.txt文件,其中包含有关对象的一些信息:
FileOutputStream outputStream;
String filename = "file.txt";
File cacheDir = context.getCacheDir();
File outFile = new File(cacheDir, filename);
outputStream = new FileOutputStream(outFile.getAbsolutePath());
outputStream.write(myString.getBytes());
outputStream.flush();
outputStream.close();
Run Code Online (Sandbox Code Playgroud)
然后我创建一个"shareIntent"来共享这个文件:
Uri notificationUri = Uri.parse("content://com.package.example/file.txt");
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, notificationUri);
shareIntent.setType("text/plain");
context.startActivity(Intent.createChooser(shareIntent, context.getResources().getText(R.string.chooser)));
Run Code Online (Sandbox Code Playgroud)
所选应用程序现在需要访问私有文件,因此我创建了一个内容提供程序.我刚刚更改了openFile方法:
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File privateFile = new File(getContext().getCacheDir(), uri.getPath());
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
Run Code Online (Sandbox Code Playgroud)
清单:
<provider
android:name=".ShareContentProvider"
android:authorities="com.package.example"
android:grantUriPermissions="true"
android:exported="true">
</provider>
Run Code Online (Sandbox Code Playgroud)
打开邮件应用程序以共享它所说的文件时,它无法附加文件,因为它只有0字节.通过蓝牙共享它也失败了.但是我可以privateFile在内容提供商中读出它,因此它存在且具有内容.问题是什么?
android android-contentprovider internal-storage share-intent android-internal-storage
所以我想用来Intent.ACTION_SEND从我的应用程序共享图像。
这是我正在使用的代码
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, shareImgURI);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
Run Code Online (Sandbox Code Playgroud)
并且shareImgURI是content://com.android.providers.media.documents/document/image%3A298
它会打开选择器,但是当我选择一个选项时没有任何反应。我错过了什么吗?
android ×11
share-intent ×11
java ×2
whatsapp ×2
facebook ×1
google-play ×1
image ×1
kotlin ×1
video ×1