如何更改 android 中图库的共享照片选项?
How can I changing shared photo options from gallery in android?
我有分享意向。用户可以分享来自其他应用程序的图像、视频和文本。我不希望用户从用户的照片库中 select 超过 10 张图像。
我已经在 ShareActivity 中编写了这个函数 (sharedMessagesControl),但我想检查它的另一个实用解决方案。我如何才能在 activity 屏幕打开之前进行检查?在照片库屏幕上有没有办法控制它?我该怎么做?
清单:
<activity
android:name=".share.ShareActivity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/plain" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
方法如下:
ShareActivity(){
private void sharedMessagesControl() {
sharedIntent = getIntent();
try {
if ((sharedIntent != null) && (sharedIntent.getType() != null) &&
((sharedIntent.getPackage() == null) || (!sharedIntent.getPackage().equals(getPackageName())))) {
String receivedType = sharedIntent.getType();
String action = sharedIntent.getAction();
if (action != null && (action.equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE) || action.equalsIgnoreCase("android.intent.action.SEND_MULTIPLE"))) {
ArrayList<Uri> uris = sharedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null && receivedType.contains("image/")) {
if (uris.size() > MAX_IMAGE_MEDIA_LIMIT) {
sharedIntent = null;
new MyToast(R.string.max_limit_image, MyToast.Length.Short);
}
}
}
}
} catch (Exception e) {
Mylog.printStackTrace(TAG + " shareMessageControl error ", e);
}
}
首先您需要阅读this了解如何从其他应用程序接收数据。你需要单独处理:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
所有不同类型的数据。
我通过 ShareActivity 的 onCreate 方法解决了控制它的问题。
public class ShareActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState, int count) {
if (!sharedMessageControl()) {
finishAffinity();
}
setContentView(R.layout.share_activity);
}
}
private boolean sharedMessageControl() {
sharedIntent = getIntent();
try {
if ((sharedIntent != null) && (sharedIntent.getType() != null) &&
((sharedIntent.getPackage() == null) || (!sharedIntent.getPackage().equals(getPackageName())))) {
String receivedType = sharedIntent.getType();
String action = sharedIntent.getAction();
if (action != null && (action.equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE) || action.equalsIgnoreCase("android.intent.action.SEND_MULTIPLE"))) {
ArrayList<Uri> uris = sharedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null && receivedType.contains("image/")) {
if (uris.size() > MAX_IMAGE_MEDIA_LIMIT) {
sharedIntent = null;
new MyToast(R.string.max_limit_image, MyToast.Length.Long);
return false;
} else {
return true;
}
}//image
}
}
return true;
} catch (Exception e) {
Mylog.printStackTrace(TAG + " sharedMessageControl error ", e);
return false;
}
}
我有分享意向。用户可以分享来自其他应用程序的图像、视频和文本。我不希望用户从用户的照片库中 select 超过 10 张图像。
我已经在 ShareActivity 中编写了这个函数 (sharedMessagesControl),但我想检查它的另一个实用解决方案。我如何才能在 activity 屏幕打开之前进行检查?在照片库屏幕上有没有办法控制它?我该怎么做?
清单:
<activity
android:name=".share.ShareActivity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/plain" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
方法如下:
ShareActivity(){
private void sharedMessagesControl() {
sharedIntent = getIntent();
try {
if ((sharedIntent != null) && (sharedIntent.getType() != null) &&
((sharedIntent.getPackage() == null) || (!sharedIntent.getPackage().equals(getPackageName())))) {
String receivedType = sharedIntent.getType();
String action = sharedIntent.getAction();
if (action != null && (action.equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE) || action.equalsIgnoreCase("android.intent.action.SEND_MULTIPLE"))) {
ArrayList<Uri> uris = sharedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null && receivedType.contains("image/")) {
if (uris.size() > MAX_IMAGE_MEDIA_LIMIT) {
sharedIntent = null;
new MyToast(R.string.max_limit_image, MyToast.Length.Short);
}
}
}
}
} catch (Exception e) {
Mylog.printStackTrace(TAG + " shareMessageControl error ", e);
}
}
首先您需要阅读this了解如何从其他应用程序接收数据。你需要单独处理:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
所有不同类型的数据。
我通过 ShareActivity 的 onCreate 方法解决了控制它的问题。
public class ShareActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState, int count) {
if (!sharedMessageControl()) {
finishAffinity();
}
setContentView(R.layout.share_activity);
}
}
private boolean sharedMessageControl() {
sharedIntent = getIntent();
try {
if ((sharedIntent != null) && (sharedIntent.getType() != null) &&
((sharedIntent.getPackage() == null) || (!sharedIntent.getPackage().equals(getPackageName())))) {
String receivedType = sharedIntent.getType();
String action = sharedIntent.getAction();
if (action != null && (action.equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE) || action.equalsIgnoreCase("android.intent.action.SEND_MULTIPLE"))) {
ArrayList<Uri> uris = sharedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null && receivedType.contains("image/")) {
if (uris.size() > MAX_IMAGE_MEDIA_LIMIT) {
sharedIntent = null;
new MyToast(R.string.max_limit_image, MyToast.Length.Long);
return false;
} else {
return true;
}
}//image
}
}
return true;
} catch (Exception e) {
Mylog.printStackTrace(TAG + " sharedMessageControl error ", e);
return false;
}
}