简体   繁体   中英

Can't launch Activity via Intent from AccessibilityService

I'm trying to launch an Activity from an AccessibilityService using an Intent with Extras.

Here's the Activity declaration in the manifest:

<activity android:name="com.mydomain.accessApp.AccessibleLauncher" >
        <intent-filter>
            <action android:name="@string/INTENT_MY_SEARCH_QUERY" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

Here's the code in the AccessibilityService:

                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addCategory(Intent.CATEGORY_DEFAULT);
                intent.putExtra(Intent.EXTRA_TEXT, question);
                intent.setAction(getString(R.string.INTENT_MY_SEARCH_QUERY));
                getApplicationContext().startActivity(intent);
                startActivity(intent);

Here is what my error catching code gets from the ActivityNotFoundException:

No Activity found to handle Intent { act=com.mydomain.accessApp.AccessibleLauncher cat=[android.intent.category.DEFAULT] flg=0x10000000 (has extras) }

Why am I receiving this error? I'm pulling the intent filter data from the strings.xml file (pulling the Accessibility Service intent filter data from there as well)

define the source and destination class while creating intent object..

take a look at this:

Intent intent = new Intent(this, yourActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM