No Activity found to handle Intent with action and data - java

I have written two different Android applications.
I wish for one application to create an intent and in turn, start an activity in the other application.
The first application which creates the intent has the following code:
Intent intent = new Intent();
intent.setAction("com.example.printtest.ACTION_PRINT");
Uri.Builder builder = new Uri.Builder();
builder.scheme("PrintAPI")
.authority("StartPrintJob")
.appendQueryParameter("appId", "aaa");
Uri uri = builder.build();
intent.setData(uri);
startActivity(intent);
The second application which I want to receive the intent has the following defined in it's manifest:
<activity android:name=".PrintActivity">
<intent-filter>
<action android:name="com.example.printtest.ACTION_PRINT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
From what I understand, the activity in the second application should be recognized as the one to start this intent. However, the same exception is thrown each time. The exception being thrown is:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp, PID: 21665
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.printtest.ACTION_PRINT dat=PrintAPI://StartPrintJob?appId=aaa }
Is there something that I'm missing?
Is it valid to start an activity in another application just by setting action and data on an intent?
Any help or advice is greatly appreciated.

You forgot to add data part
<activity android:name=".PrintActivity"
android:exported="true">
<intent-filter>
<action android:name="com.example.printtest.ACTION_PRINT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="PrintAPI"></data>
</intent-filter>
</activity>

Related

Remove my application from "Complete action using"

In my application I have two buttons, one is to open the device's camera and the other to open my applications camera. I'm giving the user the option to choose which one they would like to use.
This is how I open the devices camera:
Uri videoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", filePlusName);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, VIDEO_REQUEST_CODE);
a "Popup" will appear, asking me to choose a camera application - Complete action using.
The problem is that my applications camera is one of the options. I would like to remove my app's camera from this options.
Is it possible to remove my application from the Complete action using popup?
Check you AndroidManifest. I think one of your app activity is registered to do the capture intent action.
Look for these intent actions- if anyone exists, remove it-
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.media.action.VIDEO_CAMERA"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Intent.CATEGORY_APP_CALCULATOR: ActivityNotFoundException

I'm trying to open the default calculator app in a android application. Two calculators are installed in device: default android calculator and Google Calculator.
Intent calc = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);
This code is throwing an ActivityNotFoundException and shows this in logcat:
system_process W/IntentResolver: resolveIntent failed: found match, but none with CATEGORY_DEFAULT
This code have the same behavior:
Intent calc = new Intent(Intent.ACTION_MAIN);
calc.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);
It's a Android bug? How to open the application chooser, to let user select the default app?
Stack Trace:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] sel=act=android.intent.action.MAIN cat=[android.intent.category.APP_CALCULATOR]} }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
at android.app.Activity.startActivityForResult(Activity.java:3930)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3890)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4213)
at android.app.Activity.startActivity(Activity.java:4181)
at com.MyActivity.openCalc(MyActivity.java:202)
at com.MyActivity.onOptionsItemSelected(MyActivity.java:191)
at android.app.Activity.onMenuItemSelected(Activity.java:2914)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
at android.app.ActivityThread.main(ActivityThread.java:5461)
It seems like the way, that documentation points to doesn't work. Nevertheless, this code will normally open default calculator app.
Intent intent = new Intent();
intent.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(intent);
The above answer works, but it does not answer the question. The question is how to launch a calculator implicitly via a category. The stock calculator (not the google play version) has the following in the manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CALCULATOR" />
</intent-filter>
The problem is simple. If the intent filter is modified as shown below the calculator can be started (tested on Pixel2 running 8.1):
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CALCULATOR" />
</intent-filter>
The DEFAULT category is required (and this is clearly documented). The problem is an app that wants to start the activity has no control of the manifest in the target activity.

Android: start an activity with an Intent or an intent-filter

I always start activities with Intents, but in the book which I'm reading an activity is started with an action parameter:
Not in this classical way
Intent intent = new Intent(this,ActivityResult.class);
But in this way:
String PICK_BUS_ACTION = "com.example.utente.decompilare" + ".action.PICK_BUS_ACTION";
Intent intent = new Intent(PICK_BUS_ACTION);
And in the manifest there is an intent-filter:
<activity android:name=".ActivityResult">
<intent-filter>
<action android:name="com.example.utente.decompilare.action.PICK_BUS_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I tried both the ways but I didn't find differences. What is better? What is the difference?
The second one is used for starting of another apps.

How to use non-main activity to capture custom url in unity game?

When someone clicks on a link in a webpage of form "com.foo.bar://testtest" I want it to open my unity game and for me to get the testtest data.
I'm an experienced programmer, but when it comes to android I kind of google my way around rather than really understanding anything. Bare that in mind. :)
I can react to links on android using intent-filters. However all the resources I've found have assumed you can extend your main activity to capture the new intent. It's possible to do that with unity, but for various reasons I'd rather not. I tried creating a new activity, exporting it to a jar, and adding this to my manifest in the application tag:
<activity android:name="com.foo.ProtocolCatcher"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="com.foo.bar" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
Clicking on a link successfully launches my game, but onto a black screen.
Edit: I've also tried this format to no change:
<activity android:name="com.foo.ProtocolCatcher"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="com.foo.bar" />
</intent-filter>
</activity>
What are the magic incantations to make the whole game boot, along with my custom activity, and let my custom activity read the incoming URL, without touching the main activity?
I suppose that you are missing a part of the boot sequence; the steps required are the following:
Define the ProtocolCatcher Activity with te proper scheme (OK)
Define the MainActivty, which represents your Unity3D game main Activity (OK)
Start the MainActivity when the ProtocolCatcher Activity gets started (MISSING)
Implementing the third step is super easy; just edit your ProtocolCatcher Activity's onCreate() method:
//ProtocolCatcher
//...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
Intent gameIntent = new Intent(this, MainActivity.class);
/*
//Pass the extra data to the game if needed
Intent sourceIntent = getIntent();
Uri data = sourceIntent.getData();
gameIntent.putExtra("uriData", data != null ? data.toString(): null);
*/
startActivity(gameIntent); //start the real game
finish(); //close the ProtocolCatcher activity
}
Considering the fact that you are "injecting" the ProtocolCatcher Activity manually, if you have problem to refer MainActivity from the ProtocolCatcher onCreate() you can lookup the relative Class using reflection.

Hunch authentication on android phone redirect

I am working authentication on an android phone which sends the user to Hunch to authentication after clicking a log in button. This sets up a new intent as below:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("hunch.com/authorize/v1/?app_id=1234&next=hoosheer-hunch-app://");
intent.setData(data);
startActivity(intent);
This is my manifest file
<activity android:name="hunch" android:label="hunch">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="hoosheer-hunch-app" />
</intent-filter>
</activity>
It gives me this error:
04-12 17:04:22.574: ERROR/AndroidRuntime(838): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=hunch.com/authorize/v1/?app_id=1234&next=hoosheer-hunch-app:// }
But I have similar code working for logging in using Foursquare. The hunch.java class contains an onResume method
Hunch does not currently support custom URL schemes such as hoosheer-hunch-app://
Until we implement this functionality you should use the following URL to authenticate:
http://hunch.com/authorize/v1/?app_id=1234&next=/
After authorizing your application, the user will be redirected to
http://hunch.com/?auth_token_key=4d3d3d3d3&user_id=hn_5678&next=%2F
You should monitor the ACTION_VIEW Intent for the URL change, pull the auth_token_key out of the URL, and then exchange it for an auth_token using the get-auth-token API call.

Categories