0

我正在创建一个应用程序来检查软件包的安装,然后使用它的 id 启动市场。

当我尝试通过使用 url:market://details?id=com.mybrowser.android 抛出意图 android.intent.action.VIEW 来启动具有应用程序 ID 的市场时说 com.mybrowser.android,市场应用程序确实启动但启动后崩溃。

注意:应用程序 com.mybrowser.android 在市场中不存在。

MyApplication 是我的应用程序。

$ adb logcat

I/ActivityManager( 1030): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=myapp.testapp/.MyApplication }
I/ActivityManager( 1030): Start proc myapp.testapp for activity myapp.testapp/.MyApplication: pid=3858 uid=10047 gids={1015, 3003}
I/MyApplication( 3858): [ Activity CREATED ]
I/MyApplication( 3858): [ Activity STARTED ]
I/MyApplication( 3858): onResume
D/dalvikvm( 1109): GC freed 6571 objects / 423480 bytes in 73ms
I/MyApplication( 3858): Pressed OK button
I/MyApplication( 3858): Broadcasting Intent: android.intent.action.VIEW, data: market://details?id=com.mybrowser.android
I/ActivityManager( 1030): Starting activity: Intent { act=android.intent.action.VIEW dat=market://details?id=com.mybrowser.android flg=0x10000000 cmp=com.android.ven
ding/.AssetInfoActivity }
I/MyApplication( 3858): onPause
I/ActivityManager( 1030): Start proc com.android.vending for activity com.android.vending/.AssetInfoActivity: pid=3865 uid=10023 gids={3003}
I/ActivityThread( 3865): Publishing provider com.android.vending.SuggestionsProvider: com.android.vending.SuggestionsProvider
D/dalvikvm( 1030): GREF has increased to 701
I/vending ( 3865): com.android.vending.api.RadioHttpClient$1.handleMessage(): Handle DATA_STATE_CHANGED event: NetworkInfo: type: WIFI[], state: CONNECTED/CO
NNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
I/ActivityManager( 1030): Displayed activity com.android.vending/.AssetInfoActivity: 609 ms (total 7678 ms)
D/dalvikvm( 1030): GC freed 10458 objects / 676440 bytes in 128ms
I/MyApplication( 3858): [ Activity STOPPED ]
D/dalvikvm( 3865): GC freed 3538 objects / 254008 bytes in 84ms
W/dalvikvm( 3865): threadid=19: thread exiting with uncaught exception (group=0x4001b180)
E/AndroidRuntime( 3865): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
E/AndroidRuntime( 3865): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime( 3865):        at android.os.AsyncTask$3.done(AsyncTask.java:200)
E/AndroidRuntime( 3865):        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime( 3865):        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime( 3865):        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime( 3865):        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime( 3865):        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
E/AndroidRuntime( 3865):        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
E/AndroidRuntime( 3865):        at java.lang.Thread.run(Thread.java:1096)
E/AndroidRuntime( 3865): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3865):        at com.android.vending.AssetItemAdapter$ReloadLocalAssetInformationTask.doInBackground(AssetItemAdapter.java:845)
E/AndroidRuntime( 3865):        at com.android.vending.AssetItemAdapter$ReloadLocalAssetInformationTask.doInBackground(AssetItemAdapter.java:831)
E/AndroidRuntime( 3865):        at android.os.AsyncTask$2.call(AsyncTask.java:185)
E/AndroidRuntime( 3865):        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/AndroidRuntime( 3865):        ... 4 more
I/Process ( 1030): Sending signal. PID: 3865 SIG: 3
I/dalvikvm( 3865): threadid=7: reacting to signal 3
I/dalvikvm( 3865): Wrote stack trace to '/data/anr/traces.txt'
I/DumpStateReceiver( 1030): Added state dump to 1 crashes
D/AndroidRuntime( 3865): Shutting down VM
W/dalvikvm( 3865): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
E/AndroidRuntime( 3865): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3865): java.lang.NullPointerException
E/AndroidRuntime( 3865):        at com.android.vending.controller.AssetInfoActivityController.getIdDeferToLocal(AssetInfoActivityController.java:637)
E/AndroidRuntime( 3865):        at com.android.vending.AssetInfoActivity.displayAssetInfo(AssetInfoActivity.java:556)
E/AndroidRuntime( 3865):        at com.android.vending.AssetInfoActivity.access$800(AssetInfoActivity.java:74)
E/AndroidRuntime( 3865):        at com.android.vending.AssetInfoActivity$LoadAssetInfoAction$1.run(AssetInfoActivity.java:917)
E/AndroidRuntime( 3865):        at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 3865):        at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3865):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3865):        at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 3865):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3865):        at java.lang.reflect.Method.invoke(Method.java:521)   
E/AndroidRuntime( 3865):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 3865):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 3865):        at dalvik.system.NativeStart.main(Native Method)
I/Process ( 1030): Sending signal. PID: 3865 SIG: 3
W/ActivityManager( 1030): Process com.android.vending has crashed too many times: killing!
D/ActivityManager( 1030):   Force finishing activity com.android.vending/.AssetInfoActivity
I/dalvikvm( 3865): threadid=7: reacting to signal 3
D/ActivityManager( 1030): Force removing process ProcessRecord{44e48548 3865:com.android.vending/10023} (com.android.vending/10023)

但是,当我尝试为市场中存在的软件包(例如 com.opera.mini.android)启动市场时,一切正常。此案例的日志:

D/dalvikvm(  966): GC freed 2781 objects / 195056 bytes in 99ms
I/MyApplication( 1165): Pressed OK button
I/MyApplication( 1165): Broadcasting Intent: android.intent.action.VIEW, data: market://details?id=com.opera.mini.android
I/ActivityManager(   78): Starting activity: Intent { act=android.intent.action.VIEW dat=market://details?id=com.opera.mini.android flg=0x10000000 cmp=com.android.vending/.AssetInfoActivity }
I/AndroidRuntime( 1165): AndroidRuntime onExit calling exit(0)
I/WindowManager(   78): WIN DEATH: Window{44c72308 myapp.testapp/myapp.testapp.MyApplication paused=true}
I/ActivityManager(   78): Process myapp.testapp (pid 1165) has died.
I/WindowManager(   78): WIN DEATH: Window{44c72958 myapp.testapp/myapp.testapp.MyApplication paused=false}
D/dalvikvm(   78): GC freed 31778 objects / 1796368 bytes in 142ms
I/ActivityManager(   78): Displayed activity com.android.vending/.AssetInfoActivity: 214 ms (total 22866 ms)
W/KeyCharacterMap(  978): No keyboard for id 65540
W/KeyCharacterMap(  978): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
V/RenderScript_jni(  966): surfaceCreated
V/RenderScript_jni(  966): surfaceChanged
V/RenderScript(  966): setSurface 480 762 0x573430
D/ViewFlipper(  966): updateRunning() mVisible=true, mStarted=true, mUserPresent=true, mRunning=true
D/dalvikvm(  978): GC freed 10065 objects / 624440 bytes in 95ms

有任何想法吗?

4

4 回答 4

3

尝试使用应用程序中的“market://details?id=pname:org.rabold.android.puzzleblox”URL 在市场应用程序中打开详细信息页面时,我遇到了类似的问题。

我可以像这样使用 AnyCut 创建快捷方式:

动作:android.intent.action.VIEW 数据:market://details?id=pname:org.rabold.android.puzzleblox 类型:

然后它工作正常。

但是,如果我创建一个带有与上述相同 Uri 的按钮来启动 Market 的 Android 应用程序,那么我会在 Market 应用程序中收到如下错误:“注意:发生服务器错误。重试,或取消并返回上一个屏幕。”

我的按钮侦听器的代码如下所示:

okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent(Intent.ACTION_VIEW, 
            Uri.parse("market://details?id=pname:org.rabold.android.puzzleblox"));
            //Uri.parse("market://search?q=pname:org.rabold.android.puzzleblox"));
            startActivity(intent);
   }
});

请注意,在上面的代码中,如果我使用“搜索”而不是“详细信息”,那么它可以工作。我想使用“详细信息”而不是“搜索”,因为我知道我的应用程序完成后将在 Market 上可用。谢谢。

于 2010-10-05T00:10:14.813 回答
3

更新!:
不要使用“pname:”

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

完美运行。

每:http:
//developer.android.com/distribute/googleplay/promote/linking.html#android-app

☮ ♥ ☺</h1>

于 2013-01-06T01:32:56.257 回答
2

thnx Daniel,我可以确认您的解决方案在设备上运行良好。

@TPham:请尝试使用正确的 url(仅附加 id),传递正确的 id 也可以正常工作,请参见下面的示例;

static final String APP_MARKET_URL = "market://details?id=com.wareninja.android.fotolicke";
Intent intent = new Intent( Intent.ACTION_VIEW,
Uri.parse(APP_MARKET_URL));
startActivity(intent);
于 2010-12-30T03:43:11.907 回答
0

您可以尝试按包搜索,而不是使用确切的 ID 启动。

Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:com.package.package2.package3"));
开始活动(意图);

于 2010-03-26T17:13:36.473 回答