如何开始我的应用程序的市场搜索

时间:2011-08-30 07:57:54

标签: android button android-intent google-play

我正试图从我的活动中启动我的应用程序在Android市场的页面。我是新手,也许我正在编写错误的代码,这是我在note.class中写的

 import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class Note extends Activity{
    WebView mWebView;
    WebView tWebView;
    @Override
     protected void onCreate(Bundle savedInstanceState) {
                    // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.note);

            mWebView = (WebView) findViewById(R.id.webview);    

               String text = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>" + "<p align=\"justify\">"                
                     + getString(R.string.fulldescription)+ "</p> " + "</body></html>";

                    mWebView.loadData(text, "text/html", "utf-8");

                    //seconda webview dove dormire-mangiare

                    tWebView = (WebView) findViewById(R.id.webview2);    

                       String text2 = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>" + "<p align=\"justify\">" + getString(R.string.descriptionspart2) + "</p> " 
                                     + "</body></html>";       

                            tWebView.loadData(text2, "text/html", "utf-8");

            Button bnt = (Button)findViewById(R.id.back1);

            bnt.setOnClickListener(new View.OnClickListener() {

       public void onClick(View view) {

                    // avvia la prossima activity del primo video

           Intent i = new Intent(view.getContext(), Clipvideo1.class);

           view.getContext().startActivity(i);

                }

            });
            Button app2 = (Button)findViewById(R.id.buy_app2);
            app2.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("market://details?id=com.wocmultimedia.Machu2a"));
                    startActivity(intent);
                    // TODO Auto-generated method stub

                }
            });

        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.delfino:
        Intent g = new Intent(this, Main.class);
           startActivity(g);
      return true;
    case R.id.note:
        Intent l = new Intent(this, Note.class);
    startActivity(l);
        return true;
    case R.id.clipvideo:
        Intent k = new Intent(this, Clipvideo1.class);
           startActivity(k);
         return true;
    case R.id.map:
        Intent p = new Intent(this, Map.class);
           startActivity(p);
         return true;
    default:
        return super.onOptionsItemSelected(item);
    }
    }


    }

这是note.xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:orientation="vertical"
    android:layout_height="wrap_content">


    <RelativeLayout android:id="@+id/relativeLayout3"
        android:layout_width="match_parent" android:layout_height="25dip">
        <TextView android:textStyle="bold" android:textColor="#000000"
            android:text="@string/forewordtitle" android:background="#FFCC00"
            android:layout_width="match_parent" android:layout_height="fill_parent"
            android:paddingLeft="6dip" android:gravity="center" />
    </RelativeLayout>

    <ScrollView android:id="@+id/scrollView2"
        android:background="#E5E5C9" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <RelativeLayout android:layout_width="fill_parent"
            android:id="@+id/linearLayout2" android:layout_height="match_parent">
            <ImageView android:id="@+id/foto1" android:layout_width="match_parent"
                android:layout_height="200dip" android:adjustViewBounds="true"
                android:layout_alignParentTop="false" android:background="#E5E5C9"
                android:layout_marginTop="10dip" android:layout_marginBottom="8dip"
                android:src="@drawable/foto1" />
            <TextView android:textStyle="bold" android:textColor="#000000"
                android:text="@string/informazioni" android:background="#E5E5C9"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:paddingBottom="6dip" android:paddingLeft="6dip"
                android:gravity="center" android:id="@+id/textinfo"
                android:layout_below="@+id/foto1" />
            <WebView android:layout_width="fill_parent"
                android:paddingLeft="6dip" android:layout_height="wrap_content"
                android:id="@+id/webview" android:layout_below="@+id/textinfo"
                android:paddingRight="4dip" android:textColor="#000000"
                android:textSize="18dip" android:gravity="fill_horizontal" />

            <ImageView android:id="@+id/foto2" android:layout_width="fill_parent"
                android:layout_height="200dip" android:adjustViewBounds="true"
                android:layout_alignParentTop="false" android:layout_below="@+id/webview"
                android:background="#E5E5C9" android:paddingTop="8dip"
                android:layout_marginBottom="10dip" android:src="@drawable/foto2" />
            <WebView android:layout_width="fill_parent"
                android:paddingLeft="6dip" android:layout_height="wrap_content"
                android:id="@+id/webview2" android:layout_below="@+id/foto2"
                android:paddingRight="4dip" android:textColor="#000000"
                android:textSize="18dip" android:gravity="fill_horizontal"
                android:clickable="true" />
            <TextView android:id="@+id/text_touroperator"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_below="@+id/webview2" android:paddingRight="4dip"
                android:textColor="#000000" android:textSize="18dip"
                android:gravity="fill_horizontal" android:autoLink="web|email"
                android:linksClickable="true" android:textColorLink="#669900"
                android:text="@string/touroperator"
                android:layout_marginBottom="6dip"
                android:background="#E5E5C9" />
            <TextView android:id="@+id/text_contact"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_below="@id/text_touroperator" android:paddingRight="4dip"
                android:textColor="#000000" android:textSize="18dip"
                android:gravity="fill_horizontal" android:autoLink="web|email"
                android:linksClickable="true" android:textColorLink="#669900"
                android:background="@android:color/white" android:text="@string/contact" />
            <ImageView android:layout_width="fill_parent"
                android:layout_height="200dip" android:adjustViewBounds="true"
                android:id="@+id/ImageView3" android:background="#E5E5C9"
                android:layout_below="@+id/text_contact"
                android:layout_alignParentLeft="true" android:src="@drawable/foto3"
                android:paddingTop="10dip" android:layout_marginBottom="6dip"></ImageView>

            <LinearLayout android:id="@+id/linearLayout3"
                android:layout_height="wrap_content" android:layout_width="fill_parent"
                android:orientation="vertical" android:layout_below="@+id/ImageView3">
                <Button android:text="@string/playbutton" android:gravity="right"
                android:layout_width="match_parent" android:id="@+id/back1"
                android:textSize="8dip" android:layout_height="30dip"
                ></Button>
                <Button android:id="@+id/buy_app2"
            android:layout_width="match_parent" 
            android:layout_height="30dip"
            android:textSize="8dip"
            android:text="@string/buyapp2"></Button>
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>
</LinearLayout>

感谢您帮助我运行它的工作但如果我点击第二个按钮启动市场我得到错误应用程序...已意外停止。 Plaese,再试一次

这是LOG CAT

08-30 08:20:00.887: DEBUG/AndroidRuntime(343): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
08-30 08:20:00.887: DEBUG/AndroidRuntime(343): CheckJNI is ON
08-30 08:20:01.687: DEBUG/AndroidRuntime(343): --- registering native functions ---
08-30 08:20:03.366: DEBUG/dalvikvm(275): GC_EXPLICIT freed 145 objects / 7736 bytes in 90ms
08-30 08:20:11.926: DEBUG/PackageParser(59): Scanning package: /data/app/vmdl18326.tmp
08-30 08:20:13.556: INFO/PackageManager(59): Removing non-system package:com.wocmultimedia.MachuNew1
08-30 08:20:13.556: INFO/ActivityManager(59): Force stopping package com.wocmultimedia.MachuNew1 uid=10053
08-30 08:20:13.897: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 14182 objects / 710320 bytes in 315ms
08-30 08:20:14.337: DEBUG/PackageManager(59): Scanning package com.wocmultimedia.MachuNew1
08-30 08:20:14.346: INFO/PackageManager(59): Package com.wocmultimedia.MachuNew1 codePath changed from /data/app/com.wocmultimedia.MachuNew1-2.apk to /data/app/com.wocmultimedia.MachuNew1-1.apk; Retaining data and using new
08-30 08:20:14.357: INFO/PackageManager(59): /data/app/com.wocmultimedia.MachuNew1-1.apk changed; unpacking
08-30 08:20:14.396: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/com.wocmultimedia.MachuNew1-1.apk' ---
08-30 08:20:15.527: DEBUG/dalvikvm(351): DexOpt: load 157ms, verify 752ms, opt 7ms
08-30 08:20:15.596: DEBUG/installd(35): DexInv: --- END '/data/app/com.wocmultimedia.MachuNew1-1.apk' (success) ---
08-30 08:20:15.627: INFO/ActivityManager(59): Force stopping package com.wocmultimedia.MachuNew1 uid=10053
08-30 08:20:15.627: WARN/PackageManager(59): Code path for pkg : com.wocmultimedia.MachuNew1 changing from /data/app/com.wocmultimedia.MachuNew1-2.apk to /data/app/com.wocmultimedia.MachuNew1-1.apk
08-30 08:20:15.636: WARN/PackageManager(59): Resource path for pkg : com.wocmultimedia.MachuNew1 changing from /data/app/com.wocmultimedia.MachuNew1-2.apk to /data/app/com.wocmultimedia.MachuNew1-1.apk
08-30 08:20:15.646: DEBUG/PackageManager(59):   Activities: com.wocmultimedia.MachuNew1.Main com.wocmultimedia.MachuNew1.Note com.wocmultimedia.MachuNew1.Clipvideo1 com.wocmultimedia.MachuNew1.Map
08-30 08:20:16.027: INFO/installd(35): move /data/dalvik-cache/data@app@com.wocmultimedia.MachuNew1-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.wocmultimedia.MachuNew1-1.apk@classes.dex
08-30 08:20:16.027: DEBUG/PackageManager(59): New package installed in /data/app/com.wocmultimedia.MachuNew1-1.apk
08-30 08:20:16.516: INFO/ActivityManager(59): Force stopping package com.wocmultimedia.MachuNew1 uid=10053
08-30 08:20:16.747: DEBUG/dalvikvm(124): GC_EXPLICIT freed 106 objects / 3928 bytes in 180ms
08-30 08:20:17.457: WARN/RecognitionManagerService(59): no available voice recognition services found
08-30 08:20:17.657: DEBUG/dalvikvm(154): GC_EXPLICIT freed 2551 objects / 134376 bytes in 878ms
08-30 08:20:18.997: WARN/dalvikvm(59): threadid=10: spin on suspend #1 threadid=8 (pcf=0)
08-30 08:20:19.541: WARN/dalvikvm(59): threadid=10: spin on suspend resolved in 1600 msec
08-30 08:20:19.856: DEBUG/dalvikvm(59): GC_EXPLICIT freed 8142 objects / 510720 bytes in 1914ms
08-30 08:20:21.516: INFO/installd(35): unlink /data/dalvik-cache/data@app@com.wocmultimedia.MachuNew1-2.apk@classes.dex
08-30 08:20:21.556: DEBUG/AndroidRuntime(343): Shutting down VM
08-30 08:20:21.566: DEBUG/dalvikvm(343): Debugger has detached; object registry had 1 entries
08-30 08:20:21.577: INFO/AndroidRuntime(343): NOTE: attach of thread 'Binder Thread #3' failed
08-30 08:20:22.787: DEBUG/AndroidRuntime(357): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
08-30 08:20:22.787: DEBUG/AndroidRuntime(357): CheckJNI is ON
08-30 08:20:23.906: DEBUG/AndroidRuntime(357): --- registering native functions ---
08-30 08:20:26.496: DEBUG/dalvikvm(284): GC_EXPLICIT freed 812 objects / 57032 bytes in 189ms
08-30 08:20:28.156: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.wocmultimedia.MachuNew1/.Main }
08-30 08:20:28.986: DEBUG/AndroidRuntime(357): Shutting down VM
08-30 08:20:29.008: DEBUG/dalvikvm(357): Debugger has detached; object registry had 1 entries
08-30 08:20:29.057: INFO/AndroidRuntime(357): NOTE: attach of thread 'Binder Thread #3' failed
08-30 08:20:29.107: INFO/ActivityManager(59): Start proc com.wocmultimedia.MachuNew1 for activity com.wocmultimedia.MachuNew1/.Main: pid=364 uid=10053 gids={}
08-30 08:20:31.336: INFO/ActivityManager(59): Displayed activity com.wocmultimedia.MachuNew1/.Main: 2372 ms (total 2372 ms)
08-30 08:20:34.767: INFO/ActivityManager(59): Starting activity: Intent { cmp=com.wocmultimedia.MachuNew1/.Note }
08-30 08:20:37.817: DEBUG/dalvikvm(364): GC_FOR_MALLOC freed 1537 objects / 290864 bytes in 349ms
08-30 08:20:38.717: INFO/ActivityManager(59): Displayed activity com.wocmultimedia.MachuNew1/.Note: 3825 ms (total 3825 ms)
08-30 08:20:38.956: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
08-30 08:20:41.256: WARN/KeyCharacterMap(364): No keyboard for id 0
08-30 08:20:41.256: WARN/KeyCharacterMap(364): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
08-30 08:20:46.457: DEBUG/dalvikvm(290): GC_EXPLICIT freed 2057 objects / 145632 bytes in 947ms
08-30 08:20:49.556: DEBUG/dalvikvm(275): GC_EXPLICIT freed 177 objects / 12728 bytes in 118ms
08-30 08:20:50.718: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.VIEW dat=market://details?id=com.wocmultimedia.Machu2a }
08-30 08:20:51.066: DEBUG/AndroidRuntime(364): Shutting down VM
08-30 08:20:51.066: WARN/dalvikvm(364): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-30 08:20:51.566: DEBUG/dalvikvm(364): GC_FOR_MALLOC freed 1927 objects / 362728 bytes in 136ms
08-30 08:20:51.576: ERROR/AndroidRuntime(364): FATAL EXCEPTION: main
08-30 08:20:51.576: ERROR/AndroidRuntime(364): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.wocmultimedia.Machu2a }
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.app.Activity.startActivityForResult(Activity.java:2817)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.app.Activity.startActivity(Activity.java:2923)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at com.wocmultimedia.MachuNew1.Note$2.onClick(Note.java:62)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.view.View.performClick(View.java:2408)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.view.View$PerformClick.run(View.java:8816)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.os.Handler.handleCallback(Handler.java:587)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.os.Looper.loop(Looper.java:123)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at java.lang.reflect.Method.invoke(Method.java:521)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-30 08:20:51.576: ERROR/AndroidRuntime(364):     at dalvik.system.NativeStart.main(Native Method)
08-30 08:20:51.606: WARN/ActivityManager(59):   Force finishing activity com.wocmultimedia.MachuNew1/.Note
08-30 08:20:52.406: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45006238 com.wocmultimedia.MachuNew1/.Note}
08-30 08:21:03.998: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{45006238 com.wocmultimedia.MachuNew1/.Note}

这是清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      android:versionName="1.0" android:versionCode="1" package="com.wocmultimedia.MachuNew1">
    <uses-sdk android:minSdkVersion="8" />
    <supports-screens android:resizeable="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"></supports-screens>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="Main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Note" android:launchMode="standard" android:label="ECOS - Non solo natura">
            <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.LAUNCHER" />  </intent-filter>
        </activity>
        <activity android:name="Clipvideo1" 
        android:launchMode="standard" 
        android:screenOrientation="landscape"></activity>
        <activity android:name=".Map"></activity>
    </application>
</manifest>

这是项目的屏幕截图 enter image description here

2 个答案:

答案 0 :(得分:6)

你是在模拟器上运行吗? 当您尝试访问市场时,模拟器没有Android Market应用程序并强制关闭。 在真实设备上试用。

答案 1 :(得分:0)

看看我的这篇文章。

http://techdroid.kbeanie.com/2010/03/youtube-intent-for-search-in-android.html

Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.android.vending");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);