PendingIntent not launching app - android

I have a service running that will put a notification on the notification bar on a particular event. In that notification I'm setting a PendingIntent to launch another application. For some reason when I act on the notification it doesn't launch the other application. Here is the code where I create the PendingIntent.
private PendingIntent externalAppStartIntent(LaunchInfo launchInfo) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(launchInfo.getPackageName(), launchInfo.getActivityName());
intent.setData(launchInfo.toUri());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(this, ZONE_SERVICE_START_EXTERNAL_APP, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
}
I am able to launch the app using a regular Intent elsewhere in my code like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(packageName, activityName);
intent.setData(data);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
ZoneUtils.launchMarketDialog(getActivity(), packageName);
}
I've checked to make sure the values of the variables I'm sending in both cases are the same.
Note that I'm trying to launch an Activity in another application outside of the one where this code lives.
EDIT:
Here is the activity definition from the other apps manifest.
<activity
android:name=".ui.GalleryActivity"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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:host="join"
android:path="/"
android:scheme="mgp" />
</intent-filter>
</activity>
EDIT2:
Here is the log I get when I act on the notification
04-20 19:05:59.151: I/ActivityManager(193): START {act=android.intent.action.VIEW cmp=com.brockoli.magnet.photoapp/.ui.GalleryFragment bnds=[128,418][720,546]} from pid -1

David Suppiger spotted it!
I was accidentally passing my GalleryFragment instead of my GalleryActivity. Working great now! Ty

Related

How to get rid of or hide `NFC detection notification` and `complete action using pop up`?

I made an app that uses NFC read.
I use singleTask for avoiding duplicate screen pop ups.
<activity
android:name=".view.main.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="example.com"
android:scheme="http">
</intent-filter>
</activity>
And I use FLAG_ACTIVITY_SINGLE_TOP
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) // or?? and??
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
I use Hauwei Mate 20 Pro. And it keeps getting NFC detection Notificaiton and sometimes get complete action using pop up.
How can I avoid that?
did you use enableForegroundDispatch(this, pendingIntent, writeTagFilters, null);
in onResume(), andnfcAdapter.disableForegroundDispatch(this);
ìn onPause()?

Firebase click_action in notification payload work fine but it causes second time to launch same activity specified in click_action

I was study about Firebase's click_action use to open activity on notification click when app was killed. It's work fine! But after closing app open app normally(Not from notification) but its open same activity as specified in click_action.
Here is the code in manifest for launch screen :
<activity
android:name=".activity.SplashScreen"
android:screenOrientation="portrait"
android:theme="#style/LoginScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
And for Firebase notification :
<activity android:name=".activity.RequestsActivity">
<intent-filter>
<action android:name="RequestsActivity" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Code for Application exit when get back to home screen then :
#Override
public void onBackPressed() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);
}
Flow of current screen
Notification->Click->RequestActivity->Back_Click->HomeScreen->BackClick->Exit_App->Reopen_App->RequestActivity(But it must be HomeScreen!).

Can not list app using intent filter in Broadcast Receiver

I want to list apps (with same intent filter). I was able to achieve this by adding intent filter to an activity
<activity
android:name=".Activities.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustNothing">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</activity>
and i could retrieve all apps having this intent with
String uri = "isApp:";
Intent intent = new Intent("com.example.identifier",
Uri.parse(uri));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
However, this launches the activity when shown in intentChoose using this snippet:
Intent zoneIntent = new Intent("com.example.identifier",
Uri.parse(uri));
Intent openInChooser = Intent.createChooser(zoneIntent, "Complete Action with").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openInChooser);
But i would want this to call a broadcast receiver. So, i moved the intent to a broadcast receiver in AndroidManifest.xml like:
<receiver
android:name=".ExampleReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</receiver>
and the snippet that returns the number of apps with this intent returns 0 now even when the app is still on this device. Could this be done with Broadcast receiver or should i consider with another approach. Thanks.
Calling queryIntentActivities() will only return Activitys. It won't return BroadcastReceivers. If you want to do this with BroadcastReceivers, then you need to call queryBroadcastReceivers() instead.

Activity not appearing on Chooser dialog when using Implicit Intent

I would like to start MyBrowser, an application that show web pages like the built-in Browser app, from another application, IntentsLab.
I followed Launch custom android application from android browser to setup the intent, and also the official Intent and Intent-filters guide which does says "You need to include CATEGORY_DEFAULT to receive implicit intents".
So my intent-filter is so written:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.categroy.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
The code of the parent activity in IntentsLab to start the new activity is:
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
String title = "Use Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
if(chooserIntent != null) startActivity(chooserIntent);
The MyBrowser application does not show up on the chooser dialog. However, when I created an Activity inside the IntentsLab and added to it a same intent-filter, this activity shows up in the chooser dialog. Is there anything wrong with the code? Or is there any difference between implicit intent towards Activities in a same Application with those in a different one?
Provided my AndroidManifest.xml for the MyBrowserActivity. It works perfectly for me. Even I am doing the coursera Android programming class :)
<activity android:name=".MyBrowserActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
</activity>

Launching custom implicit intent

Two activities are installed having the following manifest files on device respectively:
The First app's activity has in its manifest:-
where,
package="com.example.tictactoe"
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
The second app's activity has in its manifest:-
where,
package="com.example.project"
<intent-filter>
<action android:name="com.example.project.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
Now, i want to start one of these activity from third application using the following code:
i=new Intent();
i.setAction("YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
But execution shows an error:-
03-11 08:12:30.496: E/AndroidRuntime(1744): FATAL EXCEPTION: main
03-11 08:12:30.496: E/AndroidRuntime(1744): android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=ACTION_SEND (has extras) }
You need to supply the full action name; supply the mimeType you used in manifest by calling setType() in your intent.
Manifest :
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Java :
Intent i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.setType("text/plain");
i.putExtra("KEY","HI..i am from third app");
startActivity(i);
You need to supply the full action:
i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
Or (depending which project you want to launch):
i.setAction("com.example.project.YOYO");
You can do it also via: (supply action directly in constructor)
i=new Intent("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
Also loose the data mimeType or read up on how to use it. Because via putExtra is not going to work.
First of all you need to ensure that the name of the intent is the fully qualified name with the package name is the same in the intent filter and the activity firing the intent. In this case: "YOYO" should be "com.example.tictactoe.YOYO". You should also remove the mime type since you are not including data in the setData(), you are in this case using a bundle. So you should have for the activity firing the intent:
ACTIVITY FIRING INTENT
i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);
and for the receiving activity's entry in the manifest: You need to ensure you set the category as DEFAULT and remove the data type tag.
ACTIVITY RECEIVING INTENT
<intent-filter>
<action android:name="com.example.tictactoe.YOYO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Categories

Resources