Custom URI navigation from Notification and from browser
Asked Answered
A

0

2

I am working with Custom URIs to show the appropriate content in android app.

Naviation flow from Notification :

onMessage() method of GCMBaseIntentService I have call to generateNotification() method.

 private void generateNotification(Context context, String message,
                        String uri) {
    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);

    Uri deepLinkUri = Uri.parse(uri);

    String scheme = deepLinkUri.getScheme();

    Intent notificationIntent = null ;

    String appPackageName = getApplicationContext().getPackageName();

    if(scheme.equals("market")){

    try {
    notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" +appPackageName));
        } catch (android.content.ActivityNotFoundException anfe) {
        //redirect to browser url to download/update
                        }

    }else{

    notificationIntent = new Intent(context,
    com.play.android.SplashScreen.class);
    }



    notificationIntent.setData(deepLinkUri);
    /* notificationIntent.setData(Uri.parse(uri)); */
    // set intent so it does not start a new activity
                    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent intent = PendingIntent.getActivity(context, 0,
    notificationIntent, 0);

    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    long notify_ID = System.currentTimeMillis();
    notificationManager.notify((int) notify_ID, notification);
                }

If I have 2 notifications(different page content but same URIs with different IDs). If I click notification 1,showing exact page with data and left as it is now and click the notification 2 again showing appropriate content.

Now I am back pressing, moving to home page second back press close the app.

Navigation flow from Browser :

From mobile site, clicking a button gives the same URIs its navigating to appropriate page.

For example, 2 different button - 2 different URIs - 2 different page content loading as NOTIFICATION flow.

But when back pressing, Its not start the Activity as fresh one. So that,back press flow executes as

first back press --- >URI2 page content close - home page show
second back press----> home page close - URI 1 page content show
third back press ----->  URI 1 page content close - home page show
fourth back press ----> App closing.

In the Manifest file, the Activity declared as like follows:

<activity
            android:name="com.play.android.SongsTabs"
            android:configChanges="orientation|keyboardHidden"
            android:exported="true"
            android:screenOrientation="portrait" >
            <intent-filter>
                <data
                    android:pathPrefix="music/*"
                    android:scheme="myscheme" />
                <data
                    android:pathPrefix="playlist/*"
                    android:scheme="myscheme" />
                <data android:scheme="myscheme" />

                <category android:name="android.intent.category.DEFAULT" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />

                <action android:name="android.intent.action.ALL_APPS" />
            </intent-filter>
        </activity>

From notification the Activity starts as new one, so that the back press working fine. But not in the browser flow. What I missed ? What should to do? If you need more details , kindly let me know.

Aquamanile answered 31/3, 2015 at 9:2 Comment(1)
Did you manage to resolve this? The fact it works from the notification is because of this line: notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); Running using custom uri doesn't work because the intent doesn't have those flags.Hence

© 2022 - 2024 — McMap. All rights reserved.