我正在開發一個影像編輯器應用程式,當用戶從檔案管理器中單擊影像或...時,我希望我的應用程式位于“打開方式...”串列中(就像“照片編輯器”應用程式所做的那樣) ) :
點擊查看示例(已編輯)
問題是我不知道該怎么做。
我在 youtube 上進行了研究,發現它intent filter與Manifest.xml檔案中的有關。
我已經嘗試將一些<action/>隨機添加到我的意圖過濾器中,但沒有奏效。
uj5u.com熱心網友回復:
例如,轉到Manifest檔案并搜索您的LAUNCHER活動SplashActivity
像這樣
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//this below code help you to get image from other apps if shared
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*" />
</intent-filter>
</activity>
要在SplashActivity中獲取該資料,請執行以下操作:
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
//this will check that you are getting only image type not text
boolean isImage = Intent.ACTION_SEND.equals(action) && "image/*".equals(type);
if(getIntent().getData() != null && isImage){
// here you got the data and you can send this data or uri
// to your image editor activity
Uri imageUri = intent.getData();
}
您可以通過執行此操作將該影像發送到下一個活動
您可以將 URI 存盤為字串
intent.putExtra("imageUri", imageUri.toString());
然后只需在您的(EditorActivity)中將字串轉換回這樣的 URI
Uri myUri = Uri.parse(getIntent().getStringExtra("imageUri"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435910.html
下一篇:從字串轉換日期格式
