【问题标题】:Deattach app when receiving data from other apps从其他应用程序接收数据时分离应用程序
【发布时间】:2014-05-11 23:21:11
【问题描述】:

我从其他应用读取接收数据: http://developer.android.com/guide/topics/manifest/application-element.html

我将 android.intent.action.SEND 替换为 android.intent.action.VIEW

但是当我的应用程序长按主页按钮作为随身听时,我的应用程序没有与文件管理器分开。

我需要使用随身听。请帮帮我。

随身听 http://i1267.photobucket.com/albums/jj541/vannam28071988/android/Screenshot_2014-04-01-15-49-28_zps8256d10f.png

在后台运行时,我的应用不会像使用 Walkman 那样与文件管理器拆分。

这是我的代码 sn-p:

        Intent externalIntent = getIntent(); String action = externalIntent.getAction();
        String type = externalIntent.getType();
        Uri sendUri = externalIntent.getData(); Toast.makeText(this, "Type: " + type, Toast.LENGTH_SHORT).show();
        Toast.makeText(this, sendUri.getPath(), Toast.LENGTH_SHORT).show();
        Intent mainIntent = new Intent(this, MainActivity.class);
        String sendType = Util.AUDIO; if (type.startsWith("video")) { sendType = Util.VIDEO; }
        mainIntent.putExtra("path", sendUri.getPath()); mainIntent.putExtra("type", sendType);
        startActivity(mainIntent);
        finish();

【问题讨论】:

  • 问题不清楚。您想在单击音频文件时将您的应用添加到建议列表中吗?
  • 能贴出你用过的代码吗?
  • 删除最后一行“finish();”..因为它关闭了您新创建的活动..并重新运行应用程序..您得到的错误/输出是什么什么时候运行代码?
  • 当您的应用程序从其他应用程序接收数据时(按照 Google 的说明),那么您的应用程序就离不开文件管理器

标签: android android-intent intentfilter


【解决方案1】:

试试下面的代码

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File(YOUR_SONG_URI);  
intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(intent);

【讨论】:

  • 我知道你的代码。但这并不能解决我的问题。谢谢。
  • 我使用 mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 然后它解决了我的问题。
  • 太好了。请务必发布您的答案并接受它。所以它也可以帮助其他人
猜你喜欢
  • 2015-05-02
  • 2017-04-26
  • 2018-11-06
  • 2021-06-30
  • 1970-01-01
  • 1970-01-01
  • 2019-01-15
  • 1970-01-01
  • 2011-03-30
相关资源
最近更新 更多