Need help in debugging NullPointerException in Android - android

I have a about class in my app to show some button and when the user click on the button it jump to a webview activity to view some webpage so I defined urls in the about class, then set onlick method to deliver them to the same webview activity to open the web page, but I keep getting a curious NullPointerException when running this activity and my logcat print nothing but
12-02 09:03:11.815: WARN/ActivityManager(51): Activity idle timeout
for HistoryRecord{44d68ea0 com.appkon.hdtvs/.About} 12-02
09:03:17.026: WARN/ActivityManager(51): Activity destroy timeout for
HistoryRecord{44e37518 com.appkon.hdtvs/.HDtvs}
Here are my code.Any help would be appreciated, thank you
About.java
public class About extends Activity{
private Button backbutton;
private Button likebutton;
private ImageView versionlogo;
private ImageButton faq;
private ImageButton forum;
private ImageButton feedback;
private ImageButton rate;
private String likepath ="http://appkon.com/hdtvs/share.html";
private String likename = "分享";
private String lpath="" ;
private String lname="" ;
private String faqpath ="http://appkon.com/hdtvs/faq.html";
private String faqname ="常见问题";
private String forumpath= "http://appkon.com/forum/" ;
private String forumname = "APP论坛";
private String fqpath="";
private String fqname="";
private String frpath="";
private String frname="";
private String ratepath ="http://appkon.com/hdtvs/";
private String ratename="评价";
private String rpath="";
private String rname="";
private String feedbackpath ="http://appkon.com/hdtvs/feedback.html";
private String feedbackname="反馈问题";
private String fdname="";
private String fdpath="";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
backbutton=(Button) findViewById(R.id.back);
likebutton=(Button) findViewById(R.id.share);
faq =(ImageButton)findViewById(R.id.faqbutton);
forum =(ImageButton)findViewById(R.id.forumbutton);
feedback =(ImageButton)findViewById(R.id.feedbackbutton);
rate =(ImageButton)findViewById(R.id.ratebutton);
backbutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, HDtvs.class);
startActivity(intent);
About.this.finish();
}
});
likebutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Renrenframe.class);
startActivity(intent);
About.this.finish();
}
});
faq.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("fqpath",faqpath);
bundle.putString("fqname",faqname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
feedback.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("fdpath",feedbackpath);
bundle.putString("fdname",feedbackname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
rate.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("rpath",ratepath);
bundle.putString("rname",ratename);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
forum.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("frpath",forumpath);
bundle.putString("frname",forumname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
}
}
Aboutframe.java
public class Aboutframe extends Activity{
private TextView namebar;
private ImageButton likebutton;
private ImageButton backbutton;
private WebView aboutframe;
private String lpath ;
private String lname ;
private String fqpath;
private String fqname;
private String frpath;
private String frname;
private String rpath;
private String rname;
private String fdname;
private String fdpath;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutframe);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar
backbutton=(ImageButton) findViewById(R.id.back);
likebutton=(ImageButton) findViewById(R.id.share);
aboutframe =(WebView)findViewById(R.id.aboutframe);
Intent intent=this.getIntent();
Bundle bunde = intent.getExtras();
lname = bunde.getString("lname");
lpath = bunde.getString("lpath");
fqname = bunde.getString("fqname");
fqpath = bunde.getString("fqpath");
frname = bunde.getString("frname");
frpath = bunde.getString("frpath");
rname = bunde.getString("rname");
rpath = bunde.getString("rpath");
fdname = bunde.getString("fdname");
fdpath = bunde.getString("fdpath");
if(lname != null&lpath!= null){
namebar.setText(lname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(lpath);
return true;
}
});
}
if(fqname != null&fqpath!= null){
namebar.setText(fqname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(fqpath);
return true;
}
});
}
if(frname != null&frpath!= null){
namebar.setText(frname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(frpath);
return true;
}
});
}
if(rname != null&rpath!= null){
namebar.setText(rname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(rpath);
return true;
}
});
}
if(fdname != null&fdpath!= null){
namebar.setText(fdname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(fdpath);
return true;
}
});
backbutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(Aboutframe.this, About.class);
startActivity(intent);
Aboutframe.this.finish();
}
});
likebutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(Aboutframe.this, Renrenframe.class);
startActivity(intent);
Aboutframe.this.finish();
}
});
}
}
}

That error means your activity timed out.
I don't understand why you call:
aboutframe.setWebViewClient
multiple times. You can try to replace if's with if else's:
/*...*/
else if(frname != null&frpath!= null){
/*...*/
else if(rname != null&rpath!= null){
/*...*/

put all your code between
try
{
your Code here...
}
catch(NullPointerException e)
{
e.printStackTrace();
}

You better use && instead of &. The latter is "binary and", you want to use "logical and".

Related

How to open WebView when click on Card View

I trying to open WebView when I click on Card View. The WebView is implemented in Main Activity. It is not working. I am new in coding. This is the Dashboard Activity 👇. Please tell me how can I solve the problem.
public class DashBoardActivity extends MainActivity implements View.OnClickListener {
public CardView card1, card2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( activity_dashboard );
card1 = findViewById( R.id.c1 );
card2 = findViewById( R.id.c2 );
card1.setOnClickListener( this );
card2.setOnClickListener( this );
}
#Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.nav_home1) {
web_view( "example1.com" );
} else if (id == R.id.nav_home2) {
web_view( "example2.com");
}
}
}
You don't need to extend your Main Activity.
Just pass the URL in Intent Extras to your Main Activity and start it there.
#Override
public void onClick(View v) {
Intent intent = new Intent(this, MainActivity.class);
String example1 = "example1.com";
String example2="example2.com";
int id = v.getId();
if (id == R.id.nav_home1) {
intent.putExtra("URL", example1);
} else if (id == R.id.nav_home2) {
intent.putExtra("URL", example2);
}
startActivity(intent);
}
Then retrieve these extras in your onCreate MainActivity
private WebView wv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url;
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
url= null;
} else {
url= extras.getString("URL");
}
} else {
url= (String) savedInstanceState.getSerializable("URL");
}
wv1=(WebView)findViewById(R.id.webView);
wv1.setWebViewClient(new MyBrowser());
wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.loadUrl(url);
}

How to get the data from server and upload data to server using Json

How to get the data from server and upload data to server using JSON?
please tell me.
This is QRActivity------------------------------------------------
final View.OnClickListener listener = new View.OnClickListener() {
#Override
public
void onClick(View v) {
btnSearch.setClickable(true);
// Server call with record_id
//DistributionDetails detDis <-- response json object from server call
QrActivityViewDetails detDis = new
QrActivityViewDetails(1002,"NORORG147530","No2,abcd Road , Colombo 03","0112233456");
Intent myIntent = new Intent(QrActivity.this, DistributionDetails.class);
myIntent.putExtra("QrActivityViewDetails", detDis);
startActivity(myIntent);
}
};
This is QrActivityViewDetails Class file
public class QrActivityViewDetails implements Serializable {
#SerializedName("DistributionID")
private int DistributionID;
#SerializedName("full_name")
private String full_name;
#SerializedName("full_address")
private String full_address;
#SerializedName("contact")
private String contact;
public QrActivityViewDetails(int DistributionID, String full_name, String full_address, String contact_number)
{
this.DistributionID = DistributionID;
this.full_name = full_name;
this.full_address = full_address;
this.contact = contact_number;
}
public
int getRecord_id() {
return DistributionID;
}
public
void setRecord_id(int record_id) {
this.DistributionID = record_id;
}
public
String getFull_name() {
return full_name;
}
public
void setFull_name(String full_name) {
this.full_name = full_name;
}
public
String getFull_address() {
return full_address;
}
public
void setFull_address(String full_address) {
this.full_address = full_address;
}
public
String getContact() {
return contact;
}
public
void setContact(String contact) {
this.contact = contact;
}
}
This is View Data Activity called DistributionDetails---------------
public class DistributionDetails extends AppCompatActivity {
private QrActivityViewDetails detQRV;
TextView ID ,Address ,name,contact;
Button btnDIR;
#Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distribution_details);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ID = (TextView) findViewById(R.id.lblID);
Address = (TextView) findViewById(R.id.lblAddress);
name = (TextView) findViewById(R.id.lblUname);
contact = (TextView) findViewById(R.id.lblTelenum);
btnDIR = (Button) findViewById(R.id.btnDelivered);
IntendFill();
btnDIR.setOnClickListener(new View.OnClickListener() {
#Override
public
void onClick(View v) {
Intent intent = new Intent(DistributionDetails.this, FinalActivity.class);
startActivity(intent);
}
});
}
public void IntendFill() {
Intent intent = getIntent();
if (intent.hasExtra("QrActivityViewDetails")) {
detQRV = (QrActivityViewDetails) intent.getSerializableExtra("QrActivityViewDetails");
ID.setText(String.valueOf(detQRV.getRecord_id()));
Address.setText(String.valueOf(detQRV.getFull_address()));
name.setText(String.valueOf(detQRV.getFull_name()));
contact.setText(String.valueOf(detQRV.getContact()));
}
}
}

pass multiple data on other activity from listview by useof firebase

I created a simple status Shayari application.
This is my first activity in which I retrieve data from Firebase in list view then I take custom text view so on text view click I open another activity name is--> Display_Full_Screen activity. In my Firebase database, there are many statuses I added and I retrieved successfully, but the problem is in other activity display only one selected status so in other Activity I put two buttons called forward and rewind. So when I click Forward button how can I get next status?
public class H_Status_Sub_Activity extends AppCompatActivity {
private static ArrayList<String> list;
private static ArrayAdapter<String> adapter;
public static DatabaseReference databaseReference;
private static TextView textView;
TextView txt_listview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_h__status__sub_);
final Bundle bundle = getIntent().getExtras();
String main_cat = bundle.getString("name");
String sub_cat = bundle.getString("name1");
mlistView = (ListView) findViewById(R.id.h_s_s_listView);
txt_listview = (TextView) findViewById(R.id.txt_listview);
databaseReference = FirebaseDatabase.getInstance().getReference("Status").child(main_cat).child(sub_cat);
list = new ArrayList<>();
adapter = new ArrayAdapter<String>(this, R.layout.item_listview, R.id.txt_listview, list);
databaseReference.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
ValueData = String.valueOf((dataSnapshot.getValue()));
list.add(ValueData);
mlistView.setAdapter(adapter);
progressDialog.dismiss();
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) { adapter.notifyDataSetChanged(); }
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) { adapter.notifyDataSetChanged(); }
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) { adapter.notifyDataSetChanged(); }
#Override
public void onCancelled(DatabaseError databaseError) { adapter.notifyDataSetChanged(); }
});
}
public void Display_Txt(View view){
txt_listview=(TextView)view.findViewById(R.id.txt_listview);
Bundle bundle = new Bundle();
bundle.putString("Full Screen Text",txt_listview.getText().toString());
bundle.putString("list", String.valueOf(list));
Intent intent = new Intent(H_Status_Sub_Activity.this, Display_Full_Screen_Activity.class);
intent.putExtras(bundle);
startActivity(intent);
}
This is my other Activity In which I display particular text in full size, but In XML file there are two buttons called forward and rewind. When I click that button next status needs to appear, but I don't know how to do that.
public class Display_Full_Screen_Activity extends AppCompatActivity {
private TextView txt_display_status;
private Button
btn_zoomin,btn_zoomout,btn_copy,btn_share,btn_forward,btn_rewind;
private int x =20;
private static DatabaseReference databaseReference = H_Status_Main_Activity.databaseReference;
String Full_Screen_Text;
String Status_List;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display__full__screen_);
init();
Bundle bundle = getIntent().getExtras();
Full_Screen_Text = bundle.getString("Full Screen Text");
Status_List = bundle.getString("list");
txt_display_status.setText(Full_Screen_Text);
}
public void Forward(View view){
txt_display_status.setText(Status_List + 1);
}
public void Rewind(View view) {
}
public void Zoom_In(View view) {
txt_display_status.getTextSize();
txt_display_status.setTextSize((x++));
txt_display_status.setTextSize(x);
}
public void Zoom_Out(View view) {
txt_display_status.getTextSize();
txt_display_status.setTextSize(x--);
txt_display_status.setTextSize(x);
}
public void Copy(View view) {
ClipboardManager clipboardManager =(ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("Lable",txt_display_status.getText().toString());
clipboardManager.setPrimaryClip(clipData);
Toast.makeText(Display_Full_Screen_Activity.this, "Text Copied" , Toast.LENGTH_SHORT).show();
}
public void Share(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "UNTOALD STORY");
String shareText = txt_display_status.getText().toString();
// shareText = shareText + "http://www.skynils.com/";
// if you have live app then you can share link like below
//shareText = shareText + "https://play.google.com/store/apps/details?id=" + context.getPackageName();
i.putExtra(Intent.EXTRA_TEXT, shareText);
startActivity(Intent.createChooser(i, "Share via"));
}
public void whatsapp(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
// i.putExtra(Intent.EXTRA_SUBJECT, "UNTOALD STORY");
String shareText = txt_display_status.getText().toString();
// shareText = shareText + "http://www.skynils.com/";
i.putExtra(Intent.EXTRA_TEXT, shareText);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, "Share via"));
}
public void init(){
txt_display_status = (TextView) findViewById(R.id.txt_display_status);
btn_zoomin = (Button) findViewById(R.id.btn_zoomin);
btn_zoomout = (Button) findViewById(R.id.btn_zoomout);
btn_copy = (Button) findViewById(R.id.btn_copy);
btn_copy = (Button) findViewById(R.id.btn_copy);
btn_share = (Button) findViewById(R.id.btn_share);
btn_forward = (Button) findViewById(R.id.btn_forward);
btn_rewind = (Button) findViewById(R.id.btn_rewind);
}
}

Android Pass string to non Activity

I have MainActivity with two String variables viz. filename & url.
I tried to use one download manager.
I dont know how to pass filename String from my Player Activity.
buttondownload = (TextView )findViewById(R.id.download);
buttondownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DownloadHelper.addNewTask(Player.this, url,
new PreDownloadStatusListener() {
#Override
public void notFoundSDCard(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "No SD Card", Toast.LENGTH_SHORT).show();
}
#Override
public void sdCardCannotWriteOrRead(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Not read and write SD card", Toast.LENGTH_SHORT).show();
}
#Override
public void moreTaskCount(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Task list is full", Toast.LENGTH_SHORT).show();
}
});
Intent intent1 = new Intent(Player.this, DownloadListActivity.class);
startActivity(intent1);
}
});
DownloadHelper.startAllTask(Player.this);
mReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadValues.Actions.BROADCAST_RECEIVER_ACTION);
registerReceiver(mReceiver, filter);
They call filename from another public class DownloadUtils.. How can i pass filname to DownloadUtils
I want Pass String from Player to ViewHolder.java
package com.download.main;
public class ViewHolder {
public static final int KEY_URL = 0;
public static final int KEY_SPEED = 1;
public static final int KEY_PROGRESS = 2;
public static final int KEY_IS_PAUSED = 3;
public TextView titleText;
public ProgressBar progressBar;
public TextView speedText;
public ImageButton pauseButton;
public ImageButton deleteButton;
public ImageButton continueButton;
private boolean hasInited = false;
public ViewHolder(View parentView) {
if (parentView != null) {
titleText = (TextView) parentView.findViewById(R.id.title);
speedText = (TextView) parentView.findViewById(R.id.speed);
progressBar = (ProgressBar) parentView.findViewById(R.id.progress_bar);
pauseButton = (ImageButton) parentView.findViewById(R.id.btn_pause);
deleteButton = (ImageButton) parentView.findViewById(R.id.btn_delete);
continueButton = (ImageButton) parentView.findViewById(R.id.btn_continue);
hasInited = true;
}
}
public static HashMap<Integer, String> getItemDataMap(String url, String speed, String progress, String isPaused) {
HashMap<Integer, String> item = new HashMap<Integer, String>();
item.put(KEY_URL, url);
item.put(KEY_SPEED, speed);
item.put(KEY_PROGRESS, progress);
item.put(KEY_IS_PAUSED, isPaused);
return item;
}
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}
public void onPause() {
if (hasInited) {
pauseButton.setVisibility(View.GONE);
continueButton.setVisibility(View.VISIBLE);
}
}
public void setData(String url, String speed, String progress) {
setData(url, speed, progress, false + "");
}
public void setData(String url, String speed, String progress, String isPaused) {
if (hasInited) {
HashMap<Integer, String> item = getItemDataMap(url, speed, progress, isPaused);
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(speed);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(item.get(KEY_PROGRESS)));
}
}
}
}
To pass any data from one activity to another use Intent. Example:-
Use below code in your Player.java class:-
Intent intent = new Intent(FromClass.this, ToClass.class);
intent.putExtra("filename", filename);
startActivity(intent);
Write the below code in the ViewHolder.java class:-
do not forget to extend Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutName);
Intent intent = getIntent();
String filename= intent.getStringExtra("filename");
}
Then you can use filename in your setData() like this:-
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(filename);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}

Android facebook share link

I have a problem with share facebook link. All the time i click on it says
"Unfortunately, this page is not available. Did you get a broken link or page has been deleted."
public static final String FACEBOOK_SHARE_ACTION_LINK = "https://google.com"; // =)
EdiTED
publishing Image
public class FacebookActivity extends Activity {
private FacebookFacade facebook;
private FacebookEventObserver facebookEventObserver;
private TextView messageView;
private String link;
private String linkName;
private String linkDescription;
private String picture;
private Map<String, String> actionsMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_facebook);
facebook = new FacebookFacade(this, Constants.FACEBOOK_APP_ID);
facebookEventObserver = FacebookEventObserver.newInstance();
messageView = (TextView) findViewById(R.id.message);
TextView linkNameView = (TextView) findViewById(R.id.link_name);
TextView linkDescriptionView = (TextView) findViewById(R.id.link_description);
//Button postButton = (Button) findViewById(R.id.button_post);
Button postImageButton = (Button) findViewById(R.id.button_post_image);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String message = bundle.getString(Extra.POST_MESSAGE);
link = bundle.getString(Extra.POST_LINK);
linkName = bundle.getString(Extra.POST_LINK_NAME);
linkDescription = bundle.getString(Extra.POST_LINK_DESCRIPTION);
picture = bundle.getString(Extra.POST_PICTURE);
actionsMap = new HashMap<String, String>();
actionsMap.put(Constants.FACEBOOK_SHARE_ACTION_NAME, Constants.FACEBOOK_SHARE_ACTION_LINK);
messageView.setText(message);
linkNameView.setText(linkName);
linkDescriptionView.setText(linkDescription);
}
postImageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (facebook.isAuthorized()) {
publishImage();
finish();
} else {
// Start authentication dialog and publish image after successful authentication
facebook.authorize(new AuthListener() {
#Override
public void onAuthSucceed() {
publishImage();
finish();
}
#Override
public void onAuthFail(String error) { // Do noting
}
});
}
}
});
}
//private void publishMessage() {
//facebook.publishMessage(messageView.getText().toString(), link, linkName, linkDescription, picture, actionsMap);
//}
private void publishImage() {
Bitmap bmp = ((BitmapDrawable) getResources().getDrawable(R.drawable.howmuchcanufarm)).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
facebook.publishImage(bitmapdata, Constants.FACEBOOK_SHARE_IMAGE_CAPTION);
}
#Override
public void onStart() {
super.onStart();
facebookEventObserver.registerListeners(this);
if (!facebook.isAuthorized()) {
facebook.authorize();
}
}
#Override
public void onStop() {
facebookEventObserver.unregisterListeners();
super.onStop();
}
}

Categories

Resources