2012-05-18 26 views
3

我有一個按鈕,用戶可以點擊它將它們發送到Google Play商店中的應用頁面。這是我使用該按鈕的代碼:Android - 將用戶發送到android play for the app的奇怪崩潰報告

 Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setData(Uri.parse("market://details?id=com.problemio")); 
     startActivity(intent);  

和包裝是在這裏:https://play.google.com/store/apps/details?id=com.problemio

,有時它工作正常,但有時我得到這樣的崩潰報告:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.problemio } 
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409) 
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 
at android.app.Activity.startActivityForResult(Activity.java:2833) 
at android.app.Activity.startActivity(Activity.java:2959) 
at com.problemio.content.BusinessIdeasActivity$5.onClick(BusinessIdeasActivity.java:107) 
at android.view.View.performClick(View.java:2538) 
at android.view.View$PerformClick.run(View.java:9152) 
at android.os.Handler.handleCallback(Handler.java:587) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:130) 
at android.app.ActivityThread.main(ActivityThread.java:3691) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:507) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 
at dalvik.system.NativeStart.main(Native Method) 

任何想法爲什麼它只是有時工作?

謝謝!

回答

5

我就嘗試了一下不同的URL爲您的軟件:

Uri uri = Uri.parse("market://search?q=pname:com.problemio"); 
    Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
    try { 
     this.startActivity(intent); 
    } catch (ActivityNotFoundException anfe) { 
     // Hmm, market is not installed 
     Log.w(TAG, "Android Market is not installed"); 
    } 
+0

謝謝 - 什麼是智能檢查,但我認爲可能有一個網絡版本的市場,我可以發送給他們......不是? – GeekedOut

+0

如果您嘗試打開以「http:// market ...」開頭的網址,如果手機安裝了Google Play,則系統會詢問用戶是想要使用瀏覽器還是市場打開,否則只會打開在瀏覽器中。你可以在catch語句中放入'http://'url,所以如果沒有市場,它應該直接在瀏覽器中打開。 – lenik

1
try{ 
    Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://market.android.com/details?id=com.problemio")); 
    startActivity(viewIntent); 
}catch (ActivityNotFoundException activityException) { 
    Log.e("helloandroid", "Call failed",activityException); 
} 

試試這個,現在你的應用不會崩潰,但可能會有例外。

+0

https://market.android.com/details?id=com.problemio將在內部導航到https://play.google .com/store/apps/details?id = com.problemio –

3

這種情況發生在沒有安裝Android Market/Google Play的設備上。實際上其中有不少,尤其是便宜的平板電腦。如果安裝了市場/遊戲應用程序以防止這種情況發生,您可以檢查例外情況。

順便說一句,如果你只是在Market/Play Store上發佈,你的應用可能已經被盜版,或者可能有人只是從根植設備上取下它,並將它推到新的el cheapo平板電腦或模擬器上。

+1

關於紮根設備的好處:)你認爲如果他們沒有安裝市場,我應該將他們帶到android商店的網絡版? – GeekedOut

+1

是的,它實際上是推薦的方法。像「market://」這樣的定製方案現在不鼓勵。順便說一句,如果市場應用程序可用,您應該得到一個對話框,以便您可以選擇是否打開與應用程序或瀏覽器的鏈接,如果格式爲https://play.google.com/store/apps/details? id = maypackagename' –