(共享意图)外部共享在 Android 12 中不起作用
(Share Intent) External Share Not Working in Android 12
在 Android 12 更新后共享意图在三星 S10 中不起作用 device.This 代码在以下 Android 版本 12 设备中正常工作但找不到原因
android 12 正在过滤掉。
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
// (Optional) If you want a preview title, set it with Intent.EXTRA_TITLE
sharingIntent.putExtra(Intent.EXTRA_TITLE, str_title);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://www.cyranolab.media/msg/?q=507dddd6-8e43-11ec-9d11-061d7e6be791");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, str_title);
Intent receiver = new Intent(getActivityContext, UserSelectedShareBroadcast.class);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}
Intent openInChooser = Intent.createChooser(sharingIntent, "Choose", pendingIntent.getIntentSender());
List<LabeledIntent> intentList = new ArrayList<>();
Intent externalEmailIntent = new Intent(getActivityContext, ExternalEmailShareActivity.class);
externalEmailIntent.putExtra("programId", programId);
externalEmailIntent.putExtra("sharedResourceId", sharedResourceId);
externalEmailIntent.putExtra("INBOX", "Inbox");
intentList.add(new LabeledIntent(externalEmailIntent, "Package Name", "Email to", R.drawable.ic_mail_outline));
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[0]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
int REQUEST_SHARED_URL = 2;
getActivityContext.startActivityForResult(openInChooser, REQUEST_SHARED_URL);
}
我想将我的程序分享给其他应用程序。我无法将我的程序分享给其他应用程序。 Share intent 未打开,android 12 次更新后。
失踪FLAG_IMMUTABLE
要声明给定的 PendingIntent 对象是可变的还是不可变的,请分别使用 PendingIntent.FLAG_MUTABLE 或 PendingIntent.FLAG_IMMUTABLE 标志。上面的代码只是我添加了这一行:现在工作正常
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}
在 Android 12 更新后共享意图在三星 S10 中不起作用 device.This 代码在以下 Android 版本 12 设备中正常工作但找不到原因 android 12 正在过滤掉。
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
// (Optional) If you want a preview title, set it with Intent.EXTRA_TITLE
sharingIntent.putExtra(Intent.EXTRA_TITLE, str_title);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://www.cyranolab.media/msg/?q=507dddd6-8e43-11ec-9d11-061d7e6be791");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, str_title);
Intent receiver = new Intent(getActivityContext, UserSelectedShareBroadcast.class);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}
Intent openInChooser = Intent.createChooser(sharingIntent, "Choose", pendingIntent.getIntentSender());
List<LabeledIntent> intentList = new ArrayList<>();
Intent externalEmailIntent = new Intent(getActivityContext, ExternalEmailShareActivity.class);
externalEmailIntent.putExtra("programId", programId);
externalEmailIntent.putExtra("sharedResourceId", sharedResourceId);
externalEmailIntent.putExtra("INBOX", "Inbox");
intentList.add(new LabeledIntent(externalEmailIntent, "Package Name", "Email to", R.drawable.ic_mail_outline));
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[0]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
int REQUEST_SHARED_URL = 2;
getActivityContext.startActivityForResult(openInChooser, REQUEST_SHARED_URL);
}
我想将我的程序分享给其他应用程序。我无法将我的程序分享给其他应用程序。 Share intent 未打开,android 12 次更新后。
失踪FLAG_IMMUTABLE 要声明给定的 PendingIntent 对象是可变的还是不可变的,请分别使用 PendingIntent.FLAG_MUTABLE 或 PendingIntent.FLAG_IMMUTABLE 标志。上面的代码只是我添加了这一行:现在工作正常
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}