AnchorFreePartner / hydrasdk-demo-android

Hydra VPN SDK demo app for Android
https://developer.anchorfree.com/
60 stars 31 forks source link

Notification click intent #18

Closed dariyanto closed 4 years ago

dariyanto commented 4 years ago

To configure action when user click's on notification use clickAction method. You must have Activity responds to specified action. Action will be used to create Intent. If clickAction not specified, sdk will open application launch activity on notification click.

How to start specific activity from notification ? the documentation is unclear, please provide example

timoshenkoav commented 4 years ago

Hello! You need to register for any activity to handle this action. https://developer.android.com/guide/components/intents-filters If you need more information, fill free to reopen the issue

dariyanto commented 4 years ago

still won't work

AndroidManifest.xml

<activity
    android:name=".vpn.activity.MainActivity"
    android:exported="true" >
    <intent-filter>
        <action android:name="com.example.ACTION_MAIN" />
    </intent-filter>
</activity>

MyApplication.java

public class MyApplication extends Application {

    private static final String CHANNEL_ID = "my_vpn";
    static final String ACTION_MAIN = "com.example.ACTION_MAIN";

    @Override
    public void onCreate() {
        super.onCreate();
        initHydraSdk();
    }
    public void initHydraSdk() {
        createNotificationChannel();
        SharedPreferences prefs = getPrefs();
        ClientInfo clientInfo = ClientInfo.newBuilder()
                .baseUrl(BuildConfig.BASE_HOST)
                .carrierId(BuildConfig.BASE_CARRIER_ID)
                .build();

        NotificationConfig notificationConfig = NotificationConfig.newBuilder()
                .title(getResources().getString(R.string.app_name))
                .clickAction(ACTION_MAIN)
                .inConnected("Connected","Connected to our server")
                .inConnecting("Connecting...","Connecting to our server")
                .smallIconId(R.drawable.ic_notification)
                .channelId(CHANNEL_ID)
                .build();

        HydraSdk.setLoggingLevel(Log.VERBOSE);

        HydraSDKConfig config = HydraSDKConfig.newBuilder()
                .observeNetworkChanges(true)
                .captivePortal(true)
                .moveToIdleOnPause(false)
                .build();
        HydraSdk.init(this, clientInfo, notificationConfig, config);
    }
    //rest of code
}
timoshenkoav commented 4 years ago

Add category to your intent-filter `

`