【问题标题】:Unable to launch audio link from Android app无法从 Android 应用启动音频链接
【发布时间】:2010-12-15 23:07:25
【问题描述】:

我正在尝试从我的应用程序中启动一个意图,该意图将播放来自流服务器的音频。我有该流的 url,我正在使用 bit.ly 来简化要启动的 url(我尝试过不使用 bit.ly 并得到相同的结果)

intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "http://bit.ly/gKltQE" ) );
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); // i tried with and without this, no luck
startActivity( intent );

浏览器启动,加载 bit.ly 链接,重定向到音频链接,然后关闭并返回到我的应用程序

12-15 14:27:58.559  1259  8370 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW dat=http://bit.ly/gKltQE flg=0x10000000 cmp=com.android.browser/.BrowserActivity (has extras) }
12-15 14:14:23.903  1259  1383 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://216.235.81.102:15532/play?now=65&membername;=&session=kxlu1:0&tag=live365&s=kxlu1&d=live365&r=0&app_id=live365:BROWSER%28pro%29 cmp=com.android.browser/.BrowserActivity }
12-15 14:14:24.387  8848  8848 D webviewglue: nativeDestroy view: 0x3bb018
12-15 14:14:24.387  1259  1600 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW dat=http://216.235.81.102:15532/play?now=65&membername;=&session=kxlu1:0&tag=live365&s=kxlu1&d=live365&r=0&app_id=live365:BROWSER%28pro%29 typ=audio/mpeg cmp=com.android.music/.StreamStarter }
12-15 14:14:24.387  1259  1929 I ActivityManager: moveTaskToBack: 12

当我在浏览器中手动启动相同的 bit.ly 链接时,它工作正常(启动音频流应用):

12-15 14:26:21.403  8848  8848 D SearchDialog: launching Intent { act=android.intent.action.VIEW dat=http://bit.ly/gKltQE flg=0x10000000 cmp=com.android.browser/.BrowserActivity (has extras) }
12-15 14:26:21.411  8848  8848 I SearchDialog: Starting (as ourselves) http://bit.ly/gKltQE#Intent;action=android.intent.action.VIEW;launchFlags=0x10000000;component=com.android.browser/.BrowserActivity;S.query=http%3A%2F%2Fbit.ly%2FgKltQE;S.user_query=bit;end
12-15 14:26:21.411  1259  1259 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW dat=http://bit.ly/gKltQE flg=0x10000000 cmp=com.android.browser/.BrowserActivity (has extras) }12-15 14:26:21.879  1259  1267 V DeviceStorageMonitorService: freeMemory=6210887680
12-15 14:26:21.879  1259  1267 V DeviceStorageMonitorService: Threshold Percentage=10
12-15 14:26:21.879  1259  1267 V DeviceStorageMonitorService: mTotalMemory = 70264913
12-15 14:26:21.879  1259  1267 I DeviceStorageMonitorService: Posting Message again
12-15 14:26:21.997  8848  8864 D dalvikvm: GC_FOR_MALLOC freed 14790 objects / 467656 bytes in 85ms
12-15 14:26:22.192  1259  1436 D dalvikvm: GC_FOR_MALLOC freed 47823 objects / 2142584 bytes in 154ms
12-15 14:26:22.208  1259  1263 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://216.235.81.102:15532/play?now=65&membername;=&session=kxlu1:0&tag=live365&s=kxlu1&d=live365&r=0&app_id=live365:BROWSER%28pro%29 cmp=com.android.browser/.BrowserActivity }
12-15 14:26:22.676  1259  1259 I ActivityManager: Starting activity: Intent { act=android.intent.action.VIEW dat=http://216.235.81.102:15532/play?now=65&membername;=&session=kxlu1:0&tag=live365&s=kxlu1&d=live365&r=0&app_id=live365:BROWSER%28pro%29 typ=audio/mpeg cmp=com.android.music/.StreamStarter }
12-15 14:26:22.770  1259  8719 I AudioService:   Remote Control   registerMediaButtonEventReceiver() for ComponentInfo{com.android.music/com.android.music.MediaButtonIntentReceiver}
12-15 14:26:22.801  8217  8217 V MediaPlaybackService: reloadQueue end
12-15 14:26:22.809  8217  8217 V MediaPlaybackService: onCreate end
12-15 14:26:22.809  8217  8217 V MediaPlaybackService: onStartCommand end

我试过摆弄各种 intent.setFlags 参数,但无济于事。也许是权限问题?或者与我调用 startActivity 的方式有关?

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    不是权限问题,只是 BrowserActivity 过早结束,可能是因为没有当前选项卡。最好的办法是给 Intent 解析器一个额外的线索,它实际上不是应该处理数据的浏览器:

    intent.setType("audio/mpeg");
    

    不需要其他标志...声音播放器(或您选择的媒体播放器)现在将处理它。

    【讨论】:

    • 啊,谢谢你的提示。这并没有完全做到,但它为我指明了正确的方向......我需要调用 intent = new Intent( Intent.ACTION_VIEW );意图.addCategory(意图.CATEGORY_DEFAULT); intent.setDataAndType(uriObj, mimeType);似乎需要调用“setDataAndType”。好奇怪。
    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多