0

使用以下操作 Intent.ACTION_SEARCH 发送意图时出现错误。

private void showMessagingSearch(Resources resources) {
        View v;
        ImageView appimage;
        v = getLayoutInflater().inflate(R.layout.app_label_item, null);
        TextView appName = (TextView) v.findViewById(R.id.app_name);
        appName.setText("Messaging Search");

        appimage = (ImageView) v.findViewById(R.id.app_image);
        /*
         * Bitmap messagingSearchBitmap =
         * BitmapFactory.decodeResource(resources,
         * R.drawable.messaging_tushar_search);
         * appimage.setImageBitmap(messagingSearchBitmap);
         */
        appimage.setImageResource(R.drawable.messaging_search);
        appimage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                saveDatatoFile(MESSAGING_SEARCH);
                if (!TextUtils.isEmpty(mText)) {
                    Intent intent = new Intent(Intent.ACTION_SEARCH);
                    intent.setPackage("com.android.sms");
                    intent.putExtra("query", mText);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    finish();
                }

            }
        });
        mParent.addView(v);
    }

单击 imageButton(调用 onClick 时)时,出现以下错误:

08-03 14:55:28.045: E/AndroidRuntime(28170): FATAL EXCEPTION: main
08-03 14:55:28.045: E/AndroidRuntime(28170): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEARCH flg=0x10000000 pkg=com.android.sms (has extras) }
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Activity.startActivityForResult(Activity.java:3389)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Activity.startActivityForResult(Activity.java:3350)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Activity.startActivity(Activity.java:3562)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.Activity.startActivity(Activity.java:3528)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at com.example.smartlauncher.DataDrivenAcitivity$7.onClick(DataDrivenAcitivity.java:718)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.view.View.performClick(View.java:4091)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.view.View$PerformClick.run(View.java:17036)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.os.Handler.handleCallback(Handler.java:615)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.os.Looper.loop(Looper.java:137)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at android.app.ActivityThread.main(ActivityThread.java:4922)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at java.lang.reflect.Method.invokeNative(Native Method)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at java.lang.reflect.Method.invoke(Method.java:511)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
08-03 14:55:28.045: E/AndroidRuntime(28170):    at dalvik.system.NativeStart.main(Native Method)

以下是我在清单中提到的权限:

<uses-permission android:name="android.permission.READ_SMS" />

Manifest File:
<uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="12" />

    <supports-screens
        android:largeScreens="false"
        android:normalScreens="true"
        android:smallScreens="false" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_SMS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/magic_slate"
    android:label="@string/app_name" >
    <activity
        android:name="com.example.magicslate.AppSwitch"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.magicslate.Launch"
        android:label="@string/app_name"
        android:theme="@style/Theme.Transparent" />
    <activity
        android:name="com.example.smartlauncher.DataDrivenAcitivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:excludeFromRecents="true"
        android:label="@string/app_name"
        android:launchMode="singleInstance"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
        android:windowSoftInputMode="stateVisible" />
    <activity
        android:name="com.example.applaunch.GestureBuilderActivity"
        android:icon="@drawable/ic_gesturebuilder"
        android:label="@string/application_name" />
    <activity
        android:name="com.example.applaunch.CreateGestureActivity"
        android:label="@string/label_create_gesture" />

    <service android:name="com.example.magicslate.MainService" />

    <receiver android:name="LongPressReceiver" >
        <intent-filter>
            <action android:name="com.android.magicslate.broadcast" >
            </action>
        </intent-filter>
    </receiver>
</application>
4

0 回答 0