簡體   English   中英

沒有操作欄的自定義共享圖標

[英]Custom share icon without Action bar

我不想在應用程序中使用操作欄。 我的活動中有自定義共享圖標。 現在單擊該圖標,我應該打開一個應用程序列表,與我們在ShareActionProvider中獲得的一樣。

如果我使用:-

context.startActivity(Intent.createChooser(myIntent, "Share Image!"));

它將打開默認選擇器活動,暫停我的活動,而選擇器活動排在最前面。

如果我使用ShareActionProvider ,它可以正常工作,但這僅適用於ActionBar。

我如何具有與ShareActionProvider相同的功能,但在Action Bar中卻沒有。

如果您正在尋找將圖像共享到設備上所有可用共享應用程序的代碼,則可能是這樣的:

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    Uri phototUri = Uri.parse(localAbsoluteFilePath);

    File file = new File(phototUri.getPath());

    Log.d(TAG, "file path: " +file.getPath());

    if(file.exists()) {
        // file create success

    } else {
        // file create fail
    }
    shareIntent.setData(phototUri);
    shareIntent.setType("image/png");
    shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
    activity.startActivityForResult(Intent.createChooser(shareIntent, "Share Image!"), Navigator.REQUEST_SHARE_ACTION);

終於我得到了解決方案。

ListView lv;
Intent share = new Intent(Intent.ACTION_SEND);

lv=(ListView)findViewById(R.id.listView1);

PackageManager pm=getPackageManager();
share.setType("image/png");
List<ResolveInfo> launchables=pm.queryIntentActivities(share, 0);
Collections.sort(launchables, new ResolveInfo.DisplayNameComparator(pm)); 

adapter=new AppAdapter(pm, launchables);
lv.setAdapter(adapter); 

在這里,啟動項列表將包含所有可用的共享應用程序。 我們可以使用適配器將其填充到listView中。

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM