i have a problem with callback after authenticate with twitter.
I get token on onNewItem but web page remain.
This is my code
public class TwitterRequest extends Activity {
private Twitter niceTwitter;
public RequestToken niceRequestToken;
private Twitter twitter;
private RequestToken requestToken;
public final static String TWIT_KEY = "dsadsdsdsads";
public final static String TWIT_SECRET = "sdsdsdsd";
public final static String TWIT_URL = "callbackapp://tweeter";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
niceTwitter = new TwitterFactory().getInstance();
niceTwitter.setOAuthConsumer(TWIT_KEY, TWIT_SECRET);
niceRequestToken = null;
try {
niceRequestToken = niceTwitter.getOAuthRequestToken(TWIT_URL);
} catch (TwitterException e) {
e.printStackTrace();
Dbg.p("niceRequestToken: " + niceRequestToken);
}
String authURL = niceRequestToken.getAuthenticationURL();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)));
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri twitURI = intent.getData();
Intent response = new Intent();
if (twitURI != null && twitURI.toString().startsWith(TWIT_URL)) {
String oaVerifier = twitURI.getQueryParameter("oauth_verifier");
try {
AccessToken accToken = niceTwitter.getOAuthAccessToken(
niceRequestToken, oaVerifier);
String token = accToken.getToken();
response.putExtra("token", token);
} catch (TwitterException te) {
Log.e("tag",
"Failed to get access token: " + te.getMessage());
response.putExtra("token", "error");
}
setResult(RESULT_OK, response);
finish();
}
}
}
When web page is opened i login in twitter and i receive token but browser is visible and android don't close page.
this is my manifest
<activity
android:name=".activities.twitter.TwitterRequest"
android:launchMode="singleInstance" >
<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="tweeter"
android:scheme="callbackapp" />
</intent-filter>
</activity>
The problem is is that you start an new activity that starts the browser application.
At this point you have 2 activities. And when you call finish() on the first activity, the second will still stay.
I suggest you make a WebView in your activity, this way you control the webpage's visibility
try below modified manifest activity entry
<activity
android:name=".activities.twitter.TwitterRequest"
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="callback"
android:scheme="x-oauthflow-twitter" />
</intent-filter>
</activity>
Related
Am trying to track referrals from user1 to user2 using firebase. Here is what u did.
From the person inviting am generating following link
https://play.google.com/store/apps/details?id=com.mindedges.freegiveaway.freegiveaway&invitedby=xyzuser
So the receiver receives the above link which was generated by following code:
private void sendNativeInvites(){
String email = UserUtils.getCurrentUser(this).getEmail();
String packageName = getPackageName();
String link = "https://play.google.com/store/apps/details?id="+packageName+"&invitedby=" + email;
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDomainUriPrefix("https://freegiveaway.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder(getPackageName()).build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
doSendInvite(dynamicLinkUri);
}
When the receiver clicks the link he will go to playstore and I expect that the app will be installed and launched with the above deep link.
On the main activity of the app i have following code to fetched the referrer but I cant find it.
private void fetchReferrerIfPresent(){
Log.d(TAG, "fetchReferrerIfPresent");
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
Log.d(TAG,"deepLink = " + deepLink); //Getting null
if (deepLink != null && deepLink.getBooleanQueryParameter("invitedby", false)) {
referrerEmail = deepLink.getQueryParameter("invitedby");
Log.d(TAG, "Found referrerEmail. referrerEmail = " + referrerEmail);
}else{
Log.d(TAG, "No referrer found");
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.e(TAG, "Exception while fetching referrerEmail", e);
}
});
}
In the manifest i have :
<activity
android:name="com.mindedges.freegiveaway.freegiveaway.LoginActivity"
android:label="#string/app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
-->
<data
android:host="freegiveaway.page.link"
android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I'm trying to build an app using stackexchange api and user will able to use app after authenticating them self with stackoverflow.com . But problem here i am getting is after completing authentication when app is reopened and i am looking for data in intent in onResume() so it is null but is should consist a callback url with access token. when i open url which i passed to intent for authentication into browser so with callback url access_token is associated but in app i am getting null!
MainAcitivity
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
Uri uri = new Uri.Builder()
.scheme("https")
.authority("stackoverflow.com")
.appendPath("oauth").appendPath("dialog")
.appendQueryParameter("client_id", "14910")
.appendQueryParameter("scope", "read_inbox")
.appendQueryParameter("redirect_uri", "https://stackoverflow.com/oauth/login_success")
.build();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: uri : " + uri);
Intent intent = new Intent(
Intent.ACTION_VIEW,
uri);
startActivity(intent);
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: intent: " + getIntent());
Log.d(TAG, "onResume: uri: " + getIntent().getData());
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith("stackoverflow.com/oauth/login_success")) {
String code = uri.getQueryParameter("code");
if (code != null) {
Log.d(TAG, "onResume: code:" + code);
} else if (uri.getQueryParameter("error") != null) {
Log.d(TAG, "onResume: error" + uri.getQueryParameter("error"));
}
}else{
Log.d(TAG, "onResume: else");
}
}
}
Manifest
...
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<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="stackoverflow.com"
android:pathPrefix="/oauth/login_success"
android:scheme="https" />
</intent-filter>
</activity>
...
StackExchange api setup for project
[project image]: https://github.com/chetan882777/git-training/blob/master/Screenshot_2019-04-14%20Editing%20project.png "
If i show here uri passed into intent:
https://stackoverflow.com/oauth/dialog?client_id=14910&scope=read_inbox&redirect_uri=https%3A%2F%2Fstackoverflow.com%2Foauth%2Flogin_success
and after that response url i obtained after authentication:
https://stackoverflow.com/oauth/login_success#access_token=nwIxeGi73Bf0rA9Ij4iwcQ))&expires=86400
My question is how to start app A within app B that appears app A is within app B through deep linking?
In the first picture below, the Debug app appears as a separate app from Slack (new code, Firebase deep linking). In the 2nd picture, the Debug app appears to be within the Slack app (old code, Android deep linking). I want to use Firebase deep linking and show the Debug app within other apps (Slack, Gmail etc).
Can anyone please go through my code below and let me know how I can achieve this?
Old code, Android deep linking:
AndroidManifest
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<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" />
<!-- Accepts URIs that begin with "abc://flights” -->
<data
android:host="sales"
android:scheme="abc" />
<data
android:host="deals"
android:scheme="abc" />
</intent-filter>
</activity>
Activity:
Intent intent = new Intent(SplashScreenActivity.this, BottomNavBarActivity.class);
//Deep Linking Content
Uri deepLinkData = getIntent().getData();
if (deepLinkData != null) {
intent.putExtra(EXTRA_DEEP_LINK, deepLinkData.getHost());
}
startActivity(intent);
overridePendingTransition(R.anim.splash_fade_in, R.anim.splash_fade_out);
finish();
New Code, Firebase deep linking:
AndroidManifest:
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<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="abc.app.goo.gl"
android:scheme="http"/>
<data
android:host="abc.app.goo.gl"
android:scheme="https"/>
</intent-filter>
</activity>
Activity:
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
// Start the activity through intent, same as before.
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.v(TAG, "Firebase deep link failure");
}
});
Its dependent on the app which sends the intent, for example whether they pass FLAG_ACTIVITY_NEW_TASK or not. I suspect the difference here is how Slack is handling the links - they may treat web URLs differently than other format ones (your old links have non-standard schemes).
Create a method openApp(), and call it accorrding to your need.
public void openAnApp()
{
Boolean flag=false;
try{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
final PackageManager packageManager = getActivity().getPackageManager();
Intent intent1 = new Intent(Intent.ACTION_MAIN, null);
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfos = packageManager.queryIntentActivities(intent1, 0);
ActivityInfo activity = null;
//getting package names and adding them to the hashset
for(ResolveInfo resolveInfo : resInfos) {
System.out.println("apap="+resolveInfo.activityInfo.packageName);
if(resolveInfo.activityInfo.packageName.equals("your.app.packagename"))
{
flag = true;
activity = resolveInfo.activityInfo;
break;
}
}
if (flag) {
// final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName,activity.name);
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(name);
getActivity().startActivity(intent);
//startActivity(Intent.createChooser(intent , "Send image using.."));
} else {
Uri uri=Uri.parse("market://details?id=your.app.packagename");
Intent goToMarket=new Intent(Intent.ACTION_VIEW,uri);
try{
startActivity(goToMarket);
}catch(ActivityNotFoundException e){
Toast.makeText(getActivity(),"Couldn't launch the market",Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
I'm currently having trouble where I am ingesting a deep link in my application, but after further review of the URL, I want to push the URL back to the web browser to display since my application does not provide the capability of using it. When I try to open the URL in a web browser, nothing happens since I have it defined to be a deep link. I tried sanitizing in the manifest with android:pathPrefix="/#!/foo", but the # character is not supported and causes the whole thing to not work.
AndroidManifest.xml
<activity
android:name=".activities.IntentForwardingActivity"
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="www.example.com"
android:scheme="https"
/>
</intent-filter>
</activity>
IntentForwardingActivity.java
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
handleDeepLinking(data.toString());
}
}
private void handleDeepLinking(String url) {
Intent intent;
if (url.contains("/#!/foo")) {
intent = HomeActivity.newIntentForFoo(this, url);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
startActivity(intent);
finish();
}
I want to open my application on link click instead of the browser if the application is installed on the device , and open Google play otherwise.
so after searching .. This is my manifest
<activity
android:name="example.com.MyActivity"
android:label="#string/title_activity_open_event_details" >
<intent-filter>
<data
android:host="play.google.com"
android:scheme="http"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
and this is my activity
public class MyActivity extends Activity {
private int EventId;
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_event_details);
tv = (TextView) findViewById(R.id.testtv);
Uri data = getIntent().getData();
if ( data != null )
{
String scheme = data.getScheme();
String host = data.getHost();
List<String> params = data.getPathSegments();
String first = params.get(0);
String second = params.get(1);
int size = params.size();
// EventId = params.get(size-1);
String third = params.get(size-1);
tv.setText(data.toString());
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_activity, menu);
return true;
}
}
when I click on this link https://play.google.com/store/apps/details?id=example.com&evid=117
MyActivity opens successfully but the link that appears in the textview is only https://play.google.com/store/apps/details?id=example.com without &evid=117 which I need to get some data and display it in my activity
could you please help me to know what I am missing ?
Thanks in advance
To get that id try this code:
Uri data = getIntent().getData();
if (data != null) {
String url = data.toString();
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(url), "UTF-8");
for (NameValuePair para : params)
if (para.getName().equals("evid")) {
String id = para.getValue(); //my id (117)
Log.v("myId",id);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
Also you are not including the https protocol. Add
<data android:host="play.google.com" android:scheme="https"/>
EDIT
I've tested this code and it's working. I've created a simple activity with the code I provided above and for the intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.VIEW"/>
<data android:host="play.google.com" android:scheme="http"/>
<data android:host="play.google.com" android:scheme="https"/>
</intent-filter>
The output result is, as expected, 117