0

Я создал приложение для галереи. Он открывает изображения и фотографии, но System не получает его как приложение галереи. Может ли кто-нибудь помочь мне установить его в качестве приложения галереи? Спасибо!Как создать приложение для галереи Android

+0

** Система не получить его как галерея приложение ** средства? –

ответ

0

Вы должны использовать Intents and Intents Filters

В ссылке выше вы должны читать о «Получение неявной намерение»

Для рекламы, которая неявным намерения ваше приложение может получить, объявить одну или несколько намерений фильтров для каждого ваших компонентов приложения с элементом в вашем файле манифеста. Каждый фильтр намерений определяет тип намерений, которые он принимает, на основе действий, данных и категории намерения. Система предоставляет неявное намерение для вашего компонента приложения только в том случае, если намерение может проходить через один из ваших целевых фильтров.

<activity android:name="ShareActivity"> 
 
    <intent-filter> 
 
     <action android:name="android.intent.action.SEND"/> 
 
     <category android:name="android.intent.category.DEFAULT"/> 
 
     <data android:mimeType="text/plain"/> 
 
    </intent-filter> 
 
</activity>

^приведенный выше код (взято из документации) показывают, как убедиться, что ваше приложение открытым, когда другое использование активности SEND намерения.

изменить действие и mimeType, чтобы получить необходимое вам разрешение (отправка фотографии ?, отображение фотографии? И т. Д.).

1

обновления манифест, Это покажет другие приложения получать содержимое

<activity android:name=".ui.MyActivity" > 
<intent-filter> 
    <action android:name="android.intent.action.SEND" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="image/*" /> 
</intent-filter> 
<intent-filter> 
    <action android:name="android.intent.action.SEND" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 
<intent-filter> 
    <action android:name="android.intent.action.SEND_MULTIPLE" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="image/*" /> 
</intent-filter> 

обработки входящего содержимого.

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 
    } else if (type.startsWith("image/")) { 
     handleSendImage(intent); // Handle single image being sent 
    } 
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null)  { 
    if (type.startsWith("image/")) { 
     handleSendMultipleImages(intent); 
// Handle multiple images being sent 
    } 
} else { 
    // Handle other intents, such as being started from the home screen 
} 

} 

void handleSendText(Intent intent) { 
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); 
if (sharedText != null) { 
    // Update UI to reflect text being shared 
} 
} 

void handleSendImage(Intent intent) { 
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); 
if (imageUri != null) { 
    // Update UI to reflect image being shared 
} 
} 

void handleSendMultipleImages(Intent intent) { 
ArrayList<Uri> imageUris =    intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); 
if (imageUris != null) { 
    // Update UI to reflect multiple images being shared 
} 
} 

официальные документы: https://developer.android.com/training/sharing/receive.html

Смежные вопросы