Airbnb deeplinkdispatch can't setup to work - java

I am starter at Android, I found this library for deep links, and it's just not working.
After the example beneath, I didn't receive the deep link.
I annotate my activity as in the GitHub example
#DeepLink("http://example.com/{id}")
public class SplashActivity extends AppCompatActivity {
I setup manifest.xml
<activity
android:name="com.example.SplashActivity"
android:exported="true"
android:label="#string/app_name"
android:launchMode="singleTask">
<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:scheme="https" android:host="example.com" />
<data android:scheme="http"/>
</intent-filter>
</activity>
And I setup the rest on onCreate method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
if (getIntent().getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = getIntent().getExtras();
Log.d("TAG", "Deeplink params: " + parameters);
String idString = parameters.getString("id");
Log.d("id", idString);
link = idString;
}
I trigger the deep link via adb
adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/123"

Related

Integrating Snap-kit in android

I am trying to add snap-kit in my application and I have integrated everything as their documentation. App successfully launched Snapchat app but it's not login it shows an error Something is wrong Here is my complete code and other implementation. This is the official documentation that I have followed https://kit.snapchat.com/docs/login-kit-android
MainActivity
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private static final String TAG = "MAIN_ACTIVITY";
String query = "{me{bitmoji{avatar},displayName}}";
String variables = null;
boolean isUserLoggedIn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
isUserLoggedIn = SnapLogin.isUserLoggedIn(this);
if (isUserLoggedIn)
binding.btnLogin.setText("Logout");
else
binding.btnLogin.setText("Logout");
binding.btnLogin.setOnClickListener(v -> {
SnapLogin.getAuthTokenManager(this).startTokenGrant();
binding.progress.setVisibility(View.VISIBLE);
});
SnapLogin.getLoginStateController(this).addOnLoginStateChangedListener(mLoginStateChangedListener);
SnapLogin.fetchUserData(this, query, null, new FetchUserDataCallback() {
#Override
public void onSuccess(#Nullable UserDataResponse userDataResponse) {
if (userDataResponse == null || userDataResponse.getData() == null) {
return;
}
MeData meData = userDataResponse.getData().getMe();
if (meData == null) {
return;
}
binding.txtName.setText(userDataResponse.getData().getMe().getDisplayName());
if (meData.getBitmojiData() != null) {
Glide.with(MainActivity.this)
.load(meData.getBitmojiData().getAvatar())
.into(binding.imgProfile);
}
}
#Override
public void onFailure(boolean isNetworkError, int statusCode) {
}
});
}
final LoginStateController.OnLoginStateChangedListener mLoginStateChangedListener =
new LoginStateController.OnLoginStateChangedListener() {
#Override
public void onLoginSucceeded() {
// Here you could update UI to show login success
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginSucceeded: ");
binding.btnLogin.setText("Logout");
}
#Override
public void onLoginFailed() {
// Here you could update UI to show login failure
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginFailed: ");
}
#Override
public void onLogout() {
// Here you could update UI to reflect logged out state
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLogout: ");
}
};
}
Manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.SnapchatAndroidDemo">
<meta-data
android:name="com.snapchat.kit.sdk.clientId"
android:value="**********************" />
<meta-data
android:name="com.snapchat.kit.sdk.redirectUrl"
android:value="*********************" />
<meta-data
android:name="com.snapchat.kit.sdk.scopes"
android:resource="#array/snap_connect_scopes" />
<activity android:name=".ui.sign.SigninActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.intro.IntroActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.login.LoginActivity"
android:screenOrientation="nosensor"/>
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="nosensor"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.MainActivity"
android:screenOrientation="nosensor" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<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="lmk"
android:path="/oauth2"
android:scheme="lmk" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Dependencies
implementation([
'com.snapchat.kit.sdk:login:1.1.4',
'com.snapchat.kit.sdk:core:1.1.4'
])
You need to add these line in the application tag
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
Use like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.SnapchatAndroidDemo">
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
<activity android:name=".intro.IntroActivity"/>
<activity android:name=".login.LoginActivity"/>
<activity
android:name=".splash.SplashActivity"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<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="lmk" android:host="lmk" android:path="/oauth2"/>
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>

Branch io - No referringParams after app is installed via play store

i have 2 issues:
the major issue is that if the app is not installed on my phone (android), then the branch link sents me to install it via play store, but then after i install and open it from there i dont have the deep link data.
if the app is already installed and i click the branch link, i need to choose between to open it via chrome or via app,
if i choose chrome -> again no deep link data.
this is the source code:
MainApp.java
public class MainApp extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override public void onStart() {
super.onStart();
try {
Branch.sessionBuilder(this).withCallback(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// option 3: navigate to page
Intent intent = new Intent(MainApp.this, Main2Activity.class);
startActivity(intent);
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}).withData(this.getIntent().getData()).init();
}
catch (Exception e) {
e.printStackTrace();
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
try {
setIntent(intent);
// if activity is in foreground (or in backstack but partially visible) launching the same
// activity will skip onStart, handle this case with reInitSession
Branch.sessionBuilder(this).withCallback(branchReferralInitListener).reInit();
}
catch (Exception ignored) { }
}
private Branch.BranchReferralInitListener branchReferralInitListener = new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject linkProperties, BranchError error) {
// do stuff with deep link data (nav to page, display content, etc)
}
};
}
Main2Activity.java
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
#Override public void onStart() {
super.onStart();
try{
// Branch logging for debugging
Branch.enableLogging();
// Branch object initialization
Branch.getAutoInstance(this);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".MainApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="hello" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_jeVWU2AYfrIjpJmslgNxZgjeAwcUzcqK" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use Branch_Test_Key (useful when simulating installs and/or switching between debug and production flavors) -->
<activity android:name=".MainActivity" />
<activity android:name=".Main2Activity" >
<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="2rerz.app.link" />
<!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website. -->
<data android:scheme="https" android:host="2rerz-alternate.app.link" />
</intent-filter>
</activity>
</application>
CustomApplication.java
import android.app.Application;
import io.branch.referral.Branch;
public class CustomApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Branch logging for debugging
//Branch.enableLogging();
// Branch object initialization
Branch.getAutoInstance(this);
}
}
The correct Manifest.xml file should be like this -
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".MainApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="hello" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="2rerz.app.link" />
<!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website. -->
<data android:scheme="https" android:host="2rerz-alternate.app.link" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_jeVWU2AYfrIjpJmslgNxZgjeAwcUzcqK" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use Branch_Test_Key (useful when simulating installs and/or switching between debug and production flavors) -->
<activity android:name=".MainActivity" />
<activity android:name=".Main2Activity" >
</activity>
Also, ensure that you are using the correct API Key with the links you are using. If it's a Live Link, then use the Live API key and vice versa.

Other activity on the start

I have 2 activity in my app - first and second. Currenly my default is first.
<activity
android:name=".FirstActivity"
android:label="randomlabel"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
Now i want to change default activity so i change like this:
<activity
android:name=".FirstActivity"
android:label="randomlabel"
>
</activity>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity
and app now didn't work, what is bad here ?
error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.russian.app/ru.russian.app.FirstActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Edit2:
FirstActivity
public class FirstActivity extends AppCompatActivity {
Button button10;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
button10.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
goToSecond();
}
});
}
private void goToSecond() {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
}
It looks like from your stacktrace that you forgot to bind the button in FirstActivity. You need to bind it by calling
button10 = (Button) findViewById(R.id.my_button_id);
Replace my_button_id with the id that you set for the button in your activity_first layout.
Try this:
<activity
android:name=".FirstActivity"
android:label="randomlabel">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity
it looks like you are trying to set a onClick() listener in your activity on a view that hasn't been initialised correctly.
you need to initialise the button from the inflated view.
add
button10 = (Button) findViewById(R.id.button10);

Android Parse notification issues

I have a Parse notification in my app. If I open my app. then it will receive the notification.
If I restart my phone. No notification will be received, until I open my app.
My question is:
How Can I initiate / run, my ParsePushBroadcastReceiver whenever the phone has been restarted. or how can I make this Receiver to be always running even if user close the app / kill the app ?
I though by adding android.intent.action.BOOT_COMPLETED would work. but it don't
Here is my manifest:
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.my.app.core.MyParseReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.my.app" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher" />
My Class
....
public class MyParseReceiver extends ParsePushBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.i(TAG, "onReceive Called");
if (intent == null) {
Log.e(TAG, "Receiver intent null");
}
else {
// Parse push message and handle accordingly
Log.d(TAG, "Receiver intent data => " + intent.toString());
}
}//end onReceive
#Override
public void onPushOpen(Context context, Intent intent) {
...
I wouldn't recommend it but you could make an onBacKeyPressed() method and just make it look like the app has been killed.

New Intent not Starting on button click

On the app I am making, on the home menu screen that you get to after the splash screen, when you click one of the buttons, nothing happens. I don't know what the problem is?
Here is the src file, it implements View.OnClickListener:
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bPlay:
Intent ourIntentPlay = new Intent(PartyActivity.this, Play.class);
startActivity(ourIntentPlay);
break;
case R.id.bFacts:
Intent ourIntentFacts = new Intent(PartyActivity.this, Facts.class);
startActivity(ourIntentFacts);
break;
case R.id.bInfo:
Intent ourIntentInfo = new Intent(PartyActivity.this, Info.class);
startActivity(ourIntentInfo);
break;
case R.id.bHelp:
Intent ourIntentHelp = new Intent(PartyActivity.this, Help.class);
startActivity(ourIntentHelp);
break;
}
}
And here is the manifest, inside the application tags:
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PartyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.PARTYACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Info"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.INFO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Help"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="w.m.HELP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Thanks
Are you assigning a listener to your buttons? Do this in your onCreate() method:
findViewById(R.id.bPlay).setOnClickListener(clickListener);
If your activity implements OnClickListener, then clickListener will be this. Do this for all of your buttons.

Categories