I am using Branch-io to share content like Text, image(from URL), and Link.
I am all done and working perfect with Facebook, Whatsapp. I mean I am able to share Text and Link on Gmail also but unable to attach image.
This problem occurred only with Gmail.
Here is my code:
BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
.setCanonicalIdentifier("item/12345")
.setTitle(title)
.setContentDescription(message)
.setContentImageUrl(image)
//.setContentImageUrl(Uri.parse("file://"+downloadedImagePath).toString())
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC);
LinkProperties linkProperties = new LinkProperties()
.addControlParameter("$always_deeplink", "true")
.setFeature("sharing")
.setStage("1");
String body = "Text Message";
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(mContext, mContext.getResources().getString(R.string.app_name), body)
.setAsFullWidthStyle(true)
.setSharingTitle("Share With");
branchUniversalObject.showShareSheet((Activity) mContext,
linkProperties,
shareSheetStyle,
new Branch.BranchLinkShareListener() {
#Override
public void onShareLinkDialogLaunched() {
LogUtils.v("Share Link", "Launched");
}
#Override
public void onShareLinkDialogDismissed() {
LogUtils.v("Share Link", "Dismissed");
}
#Override
public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
LogUtils.v("Share Link", sharedLink);
}
#Override
public void onChannelSelected(String channelName) {
LogUtils.v("Share Link", channelName);
}
});
}
}, false);
Let you know again, this code working perfect with Facebook, whatsapp but not with Gmail(only issue not attaching image).
If anyone knows then please let me know what I'am doing wrong and what is the perfect way to do this.
Thanks in advance.
I just tested this on our test application, and everything works correctly when sharing with Gmail. Here's my test link: https://appsolutely.test-app.link/Mw2qFHRMxJ
Whenever you share a link via showShareSheet(), all the Branch Universal Object (BUO) information is attached to the link. If you keep sharing links for the same data, but across different channels, the only difference between the links for each channel will be "~channel": "Gmail".
Looking at your code, I do not see any issues you could encounter with attaching the image URL, as you do call .setContentImageUrl(image) for the BUO object, so the issue may be in the way you are testing. After sharing your link via Gmail, I would suggest pasting it into the URL bar of your browser and attaching the following query parameter: ?debug=true.
E.g.: https://appsolutely.test-app.link/Mw2qFHRMxJ?debug=true
You could then view all of the data the link contains on the page that opens. If you see that the data contains the "$og_image_url" with the correct URL address, it means that the image was actually attached, as shown in the example below for my test link https://appsolutely.test-app.link/Mw2qFHRMxJ
Related
I have a problem that I want to use jsoup to grab news but always fail.
this is news website.
https://www3.nhk.or.jp/news/
this is my picture . which I circle is I wanted data.
https://drive.google.com/open?id=1KJAyOSdHO8APPD6_A9MjxkoFjekcQLXt
but no matter what I do. it always get wrong data or empty.
this is my program.
public class News extends AppCompatActivity {
Button ok;
private static final String url ="https://www3.nhk.or.jp/news/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
ok=(Button)findViewById(R.id.ok);
ok.setOnClickListener(okbtn);
}
private Button.OnClickListener okbtn=new Button.OnClickListener(){
public void onClick(View v){
try{
Connection.Response response = Jsoup.connect(url).execute();
String body = response.body();
Document data = Jsoup.parse(body);//visible-phone print_hide
Elements country=data.select("main");
Elements main=data.select("div[id=module module--news-main index-main]");
for(Element e1: country)
{
mytoast(e1+"");
}
}
catch(Exception ex){ex.printStackTrace() ;}
}
};
private void mytoast(String str)
{
Toast toast=Toast.makeText(this, str, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
please help me
thanks
You can try to see it's HTML first.
If you can't see it, you don't use jsoup.
There's a small hint in its comment:
このページではJavaScriptを使用しています
=>This is generated by JavaScript
If it's generated, you can't find it from Jsoup.
In this case, I'll use Chrome's tool to monitor the XHR tab
Look into each XHR request, and find the most possible one,
for example, I see this
https://www3.nhk.or.jp/news/json16/syuyo.json?_=1559183885640
A part of the response:
"id":"193411",
"title":"三菱UFJ銀行 新規口座は原則デジタル通帳に",
"pubDate":"Thu, 30 May 2019 04:03:11 +0900",
"cate":"5",
...
"id":"193437",
"title":"エアレース世界選手権 今季限りで終了",
"pubDate":"Thu, 30 May 2019 09:40:37 +0900",
So this is exactly what you want. It comes from another link!
You don't need Jsoup, just HttpGet the link
https://www3.nhk.or.jp/news/json16/syuyo.json?_=1559183885640
And I think the numbers looks like UnixTime,
So I check the current time is : 1559184830782, that's it.
Just use that link as API and time as parameter.
I'm successful in creating a deeplink and posting it to facebook with all the relevant metadata attached:
TextView.OnClickListener inviteClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
// The identifier is what Branch will use to de-dupe the content across many different Universal Objects
.setCanonicalIdentifier("item/12345")
// This is where you define the open graph structure and how the object will appear on Facebook or in a deepview
.setTitle("Suits")
.setContentDescription("Great suits here")
.setContentImageUrl("http://steezo.com/wp-content/uploads/2012/12/man-in-suit.jpg")
// You use this to specify whether this content can be discovered publicly - default is public
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
// Here is where you can add custom keys/values to the deep link data
.addContentMetadata("picurl", "http://steezo.com/wp-content/uploads/2012/12/man-in-suit.jpg");
LinkProperties linkProperties = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.addControlParameter("$desktop_url", "http://www.yahoo.com")
.addControlParameter("$ios_url", "http://www.microsoft.com");
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(PlaceDetailsActivity.this, "Check this out!", "This stuff is awesome: ")
.setMoreOptionStyle(getResources().getDrawable(android.R.drawable.ic_menu_search), "Show more")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL);
branchUniversalObject.showShareSheet(PlaceDetailsActivity.this,
linkProperties,
shareSheetStyle,
new Branch.BranchLinkShareListener() {
#Override
public void onShareLinkDialogLaunched() {
}
#Override
public void onShareLinkDialogDismissed() {
}
#Override
public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
Log.e("LinkShared", "success");
}
#Override
public void onChannelSelected(String channelName) {
}
});
branchUniversalObject.generateShortUrl(PlaceDetailsActivity.this, linkProperties, new Branch.BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("MyApp", "got my Branch link to share: " + url);
}
}
});
}
};
What I'm not successful at doing is to ensure that when the link is clicked, it goes to the correct activity within my app. I followed the guide closely but at points I found the guide to be a bit vague - https://dev.branch.io/references/android_sdk/#branch-universal-object-for-deep-links-content-analytics-and-indexing.
In the activity that I want to call, I put this in the manifest:
<activity
android:name=".SuitActivity"
android:label=""
android:windowSoftInputMode="adjustResize">
<meta-data android:name="io.branch.sdk.auto_link_keys_6" android:value="picurl" />
</activity>
Inside the SuitActivity class, I put in the following:
#Override
protected void onResume() {
super.onResume();
if (Branch.isAutoDeepLinkLaunch(this)) {
try {
action.setPicurl(Branch.getInstance().getLatestReferringParams().getString("picurl"));
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("nondeeplink","Launched by normal application flow");
}
}
That appeared to be all that needs to be done to click on a link in Facebook and open my SuitActivity instead of my MainActivity but it doesn't seem to work. When I click on a branch link, it opens MainActivity.
When I create the link on Branch, this is what is returned in the logs:
2-16 19:44:38.019 24086-24086/com.example I/MyApp: got my Branch link to share: https://bnc.lt/cByh/7d3u8enomp
12-16 19:44:38.021 24086-24129/com.example I/BranchSDK: posting to https://api.branch.io/v1/url
12-16 19:44:38.021 24086-24129/com.example I/BranchSDK: Post value = {
"identity_id": "20569XXX",
"device_fingerprint_id": "20519XXX",
"session_id": "2057XXX",
"tags": [],
"alias": "",
"channel": "Add to Facebook",
"feature": "sharing",
"stage": "",
"data": "{\"$og_title\":\"Suits\",\"$canonical_identifier\":\"item\\\/12345\",\"$keywords\":[],\"$og_description\":\"Great suits here\",\"$og_image_url\":\"http:\\\/\\\/steezo.com\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/man-in-suit.jpg\",\"$content_type\":\"\",\"$exp_date\":\"0\",\"picurl\":\"http:\\\/\\\/steezo.com\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/man-in-suit.jpg\",\"$desktop_url\":\"http:\\\/\\\/www.yahoo.com\",\"$ios_url\":\"http:\\\/\\\/www.microsoft.com\",\"source\":\"android\"}",
"sdk": "android1.10.1",
"retryNumber": 0,
"branch_key": "key_test_XXX"
}
EDIT:
I have even added a GitHub sample now for you to test this: https://github.com/Winghin2517/BranchIOTestDeepLink
It includes two activities:
MainActivity with a FAB - it is the standard template for a new app created through Android Studios. If you click on the FAB, Branch.io will launch and ask you to add to facebook, copy link etc.
SecondActivity - once you have shared it on facebook and click on facebook on the link, the SecondActivity should start. Currently, when you click on the link on facebook or everywhere you have shared it, the link still opens MainActivity.
For this sample to work, please also replace your branch.IO key with your key from your profile in the manifest as currently, they are just XXX's:
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_XXX" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_XXX" />
Thanks!
The Github repo is now a working example of android with Branch.io after several days liaising back and forth with branch.io I finally got it to work:
https://github.com/Winghin2517/BranchIOTestDeepLink
The app will open the 'SecondActivity', and not the 'MainActivity', if you click on the link in facebook or wherever you decided to send the link to. If you click back from the 'SecondActivity', it will close the app as the onActivityResult method will be called in the 'MainActivity' with the correct activity code and the finish() method is called in 'MainActivity' to close the app.
When I invite friends from facebook it displays Toast invitation was send but not display in friends notification.
I use Simple Facebook SDK for Android in my app. My invite is sent, but it isn`t displayed in friends wall.
I asked the same question here: https://github.com/sromku/android-simple-facebook/issues/13
Can you tell me why I need Canvas?
Can you explain what is Canvas and why we need it to make invites work?
I read facebook Canvas explanation.
It is written that: "A Canvas Page is quite literally a blank canvas within Facebook on which to run your app. You populate the Canvas Page by providing a Canvas URL that contains the HTML, JavaScript and CSS that make up your app. When a user requests the Canvas Page, we load the Canvas URL within an iframe on that page. This results in your app being displayed within the standard Facebook chrome."
I don`t want my app to run from page, or it just will have a link to playstore?
What permissions I should ask?
Today I ask for: "user_friends","publish_actions".
Can you give me an example of invite friends that work with people that don`t have the app installed?
public void invite(String message, final OnInviteListener onInviteListener, String data) {
InviteAction inviteAction = new InviteAction(mSessionManager);
inviteAction.setMessage(message);
inviteAction.setData(data);
inviteAction.setOnInviteListener(onInviteListener);
inviteAction.execute();
}
#Override
protected void executeImpl() {
if (sessionManager.isLogin(true)) {
Bundle params = new Bundle();
if (mMessage != null) {
params.putString(PARAM_MESSAGE, mMessage);
}
if (mData != null) {
params.putString(PARAM_DATA, mData);
}
if (mTo != null) {
params.putString(PARAM_TO, mTo);
}
else if (mSuggestions != null) {
params.putString(PARAM_SUGGESTIONS, TextUtils.join(",", mSuggestions));
}
openInviteDialog(sessionManager.getActivity(), params, mOnInviteListener);
}
else {
String reason = Errors.getError(ErrorMsg.LOGIN);
Logger.logError(InviteAction.class, reason, null);
mOnInviteListener.onFail(reason);
}
}
The code is taken from Simple Facebook implementation. Am I missing something?
Thanks
In Android i have a webview that lead to an google authentication form. When the authentication form is loaded in the webview it will call onReceivedLoginRequest:
public void onReceivedLoginRequest(final AuthenticationWebView client, final WebView view, final String realm,
final String account, final String args) {
...
}
When this method is called i get the Accounts stored on the device and let the user choose one and use that one to retrieve an authtoken:
mAccountManager.getAuthToken(account, mAuthToken, null, mWebViewActivity, this, null);
It all works perfectly fine (i think) and the next step looks good also:
final String result = bundle.getResult().getString(AccountManager.KEY_AUTHTOKEN);
if (result != null) {
// authentication succeeded, new url given as result for redirection
mWebView.loadUrl(result);
} else {
onLoginFailed();
}
A new method is called and returns the new url for redirection which i load in the webview. The result String returns a new adress which looks good but does nothing, it doens't log in but i don't get any message error either from the webview.
Url:
https://accounts.google.com/MergeSession?args=..&uberauth=WILL_NOT_SIGN_IN&source=AndroidWebLogin
I modified the url a bit with (triple)dots, don't know how secure it is and it was not such an interesting part of the url.
Anyone know why the url will not redirect me to the website behind it? When i use this url in my browser it recognizes my account, i only have to fill in my password and it redirects me correctly.
I use a native Android webview and i inject it with javascript but this only happens on the page after the login.
The settings i added to the webview are:
mSettings = getSettings();
mSettings.setJavaScriptEnabled(true);
mSettings.setDomStorageEnabled(true);
mSettings.setAllowFileAccess(true);
mSettings.setGeolocationEnabled(true);
Ok once again, I am in way over my head here while learning android. After finally developing my simple little app, I am trying to use some of the benefits of having a native app.
So, project one, make a page which can send images via email (either from the gallery or camera)
Essentially its a select and send via email, but I don't even know where to start.
I found some code that somebody else was asking about at;
Android App Take/ Email Photo
I tried this, but get all sorts of errors from eclipse, replating to downloadedPic section.
If somebody could please take a look and advise me on the best way to do this, that would be amazing. As usual sorry for my beginers stupidity, but I guess everyone has to learn somewhere
THIS IS MY .JAVA AT PRESENT
public class Photos extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photos);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_photos, menu);
return true;
}
THIS IS MY .XML AT PRESENT
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please chose the options below to select and upload photos into the
DCC for the selected project..."
tools:context=".Photos"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
First what should you do is get the image storage path by using the file,
File *photo = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/Fault", imagename+".png");
Then Convert that file path in to Uri
Uri imageuri = Uri.fromFile(photo);
Finally send it the image via email using your imageuri
Intent send_report = new Intent(Intent.ACTION_SEND);
send_report.putExtra(Intent.EXTRA_EMAIL, new String[]{ email_emailid});
send_report.putExtra(Intent.EXTRA_SUBJECT, email_subject);
send_report.putExtra(Intent.EXTRA_STREAM, imageuri);
send_report.putExtra(Intent.EXTRA_TEXT, email_body);
send_report.setType("text/plain");
send_report.setType("image/png");
startActivityForResult(Intent.createChooser(send_report, "Choose an Email client"), 77);
Hope it helps.
Get Your Image First :
// Get Image form mnt/sdcard/YOUR_FLODER/my_image.png
ImageView my_Image = (ImageView)findViewById(R.id.my_Image);
Imagepath="/sdcard/YOUR_FLODER/"+my_iamge+".png";
bitmap = BitmapFactory.decodeFile(Imagepath);
Fetch mail address:
// This Will fetch merchant's Email id from Deivce.
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
AccountManager manager =(AccountManager)getSystemService(ACCOUNT_SERVICE);
//Account[] accounts = AccountManager.get(getApplicationContext()).getAccounts();
Account[] accounts = manager.getAccounts();
for (Account account : accounts)
{
if (emailPattern.matcher(account.name).matches())
{
possibleEmail = account.name;
}
}
Send Click Event :
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("image/png");
i.putExtra(Intent.EXTRA_CC,new String[]{possibleEmail});
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail With Image attachment");
startActivity(Intent.createChooser(i2, "Send Email..."));
At The End Photos.java
public class Photos extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.Activity_Photos);
// your image fetching code
// fetch mail code
// write button click event
// put intent code in click event
}
}
So Hope Now you Get Full Code.