Я создал плавающую кнопку и назначил ей идентификатор fab. Когда люди нажимают на нее, сразу появляется каждый параметр общего доступа, установленный на мобильном телефоне, и пользователь может выбрать, куда поделиться URL-адресом.Я создал это через намерение, но это не работает, скорее сбой.Помогите мне, пожалуйста.Дайте мне небольшой кусочек кода.
main_activity java
Button buttonDonor;
Button buttonInfo;
Button needBlood;
public static String donorId = "no";
SharedPreferences sharedPreferences;
public static Double lat = 0.0;
public static Double lng = 0.0;
private final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 1;
GoogleApiClient mGoogleApiClient;
LocationManager locationManager;
LocationListener locationListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Connecting to the database
database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("donors");
/**
* Wiring up every thing
*/
//sharebutton
buttonInfo = (Button) findViewById(R.id.fab);
buttonInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i.putExtra(Intent.EXTRA_TEXT, "http://google.com");
startActivity(Intent.createChooser(i, "Share URL"));
}
});
buttonInfo = (Button) findViewById(R.id.btn_info);
Animation slideUpAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.information);
buttonInfo.startAnimation(slideUpAnimation);
buttonInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Information.class));
}
});
buttonInfo = (Button) findViewById(R.id.developer);
Animation slideUpAnimation1 = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.developer);
buttonInfo.startAnimation(slideUpAnimation1);
buttonInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, About.class));
}
});
buttonInfo = (Button) findViewById(R.id.request);
Animation slideUpAnimation2 = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.request_blood);
buttonInfo.startAnimation(slideUpAnimation2);
buttonInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, RequestBlood.class));
}
});
buttonInfo = (Button) findViewById(R.id.check_request);
Animation slideUpAnimation3 = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.check_request);
buttonInfo.startAnimation(slideUpAnimation3);
buttonInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, RequestList.class));
}
});
needBlood = (Button) findViewById(R.id.btn_need_blood);
Animation slideUpAnimation4 = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.need_blood);
needBlood.startAnimation(slideUpAnimation4);
needBlood.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NeedBlood.class));
}
});
buttonDonor = (Button) findViewById(R.id.btn_donor_profile);
Animation slideUpAnimation6 = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.be_donor);
buttonDonor.startAnimation(slideUpAnimation6);
if (donorId.toString().equals("no")) {
buttonDonor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DonorForm.class));
}
});
} else {
}
/**
* Initializing variable
*/
try {
donorId = sharedPreferences.getString("id", "no");
} catch (Exception e) {
e.printStackTrace();
}
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
lat = location.getLatitude();
lng = location.getLongitude();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!locationManager.isProviderEnabled(GPS_PROVIDER)) {
Toast.makeText(MainActivity.this, "Please Turn on Location", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
MainActivity.this.startActivity(myIntent);
}
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
/**
* Crating a location request
*/
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
return;
}
locationManager.requestLocationUpdates(GPS_PROVIDER, 1000, 1, locationListener);
}
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
boolean doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please click Back twice to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
}