Autore Topic: Share non funziona  (Letto 114 volte)

Offline Jekan

  • Nuovo arrivato
  • *
  • Post: 24
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Sony Experia M
  • Sistema operativo:
    Windows 7
Share non funziona
« il: 22 Settembre 2016, 19:42:12 CEST »
0
Salve ragazzi ho un ploblema con il sistema di share il mio obiettivo e quello che quando uno clicca su share e sceglie il social su quale vuole fare lo share lo porti su quel social ed esca il link della mia app.
Ho seguito diverse guide ma non funziona ogni volta che faccio partire l'app si blocca spero che mi saprete aiutare come sempre
Main
Codice (Java): [Seleziona]
package jekan.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ShareActionProvider;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

import im.delight.apprater.AppRater;


public class MainActivity extends AppCompatActivity {

    private AdView mAdView;
    private ShareActionProvider mShareActionProvider;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, "ca-app-pub-8991982181019575~xxxxxxxxxxxxx");

        mAdView = (AdView) findViewById(R.id.adView);

        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
        mAdView.loadAd(adRequest);


        Button weapons = (Button) findViewById(R.id.weapons);
        weapons.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage1 = new Intent(MainActivity.this, weaponsActivity.class);
                startActivity(openpage1);
            }
        });
        Button armorandshields = (Button) findViewById(R.id.Armor_and_Shields);
        armorandshields.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage2 = new Intent(MainActivity.this, ArmorandShieldsActivity.class);
                startActivity(openpage2);
            }
        });
        Button Magic_Items = (Button) findViewById(R.id.Magic_Items);
        Magic_Items.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage19 = new Intent(MainActivity.this, Magic_Items.class);
                startActivity(openpage19);
            }
        });
        Button poison_activity = (Button) findViewById(R.id.Drugs_poison_activity);
        poison_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage20 = new Intent(MainActivity.this, drugs_poison_iniziale.class);
                startActivity(openpage20);
            }
        });
        Button Items = (Button) findViewById(R.id.Items);
        Items.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage21 = new Intent(MainActivity.this, item_activity.class);
                startActivity(openpage21);
            }
        });
        Button musical_instrument = (Button) findViewById(R.id.musical_instrument);
        musical_instrument.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage22 = new Intent(MainActivity.this, musical_instrument.class);
                startActivity(openpage22);
            }
        });
        Button Clothing = (Button) findViewById(R.id.Clothing);
        Clothing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent openpage23 = new Intent(MainActivity.this, clothing_normali.class);
                startActivity(openpage23);
            }
        });


        AppRater appRater = new AppRater(this);
        appRater.setDaysBeforePrompt(0);
        appRater.setLaunchesBeforePrompt(0);
        appRater.setPhrases(R.string.rate_title, R.string.rate_explanation, R.string.rate_now, R.string.rate_later, R.string.rate_never);
        appRater.setPhrases("Rate this app", "Has this convinced you?\n" +
                "We would be very happy if you could rate our application on Google Play. Thanks for your support!", "Rate now", "Later", "No, thanks");
        appRater.setTargetUri("https://play.google.com/store/apps/details?id=%1$s");
        appRater.setPreferenceKeys("app_rater", "flag_dont_show", "launch_count", "first_launch_time");
        appRater.show();

        TextView share = (TextView) findViewById(R.id.Share);
        share.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_out_right));


    }
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar_share_menu, menu);
        MenuItem item = menu.findItem(R.id.menu_item_share);
        ShareActionProvider myShareActionProvider = (ShareActionProvider) item.getActionProvider();
        Intent myIntent = new Intent();
        myIntent.setAction(Intent.ACTION_SEND);
        myIntent.putExtra(Intent.EXTRA_TEXT, "TESTO EXTRA");
        myIntent.setType("text/plain");

        myShareActionProvider.setShareIntent(myIntent);

        return true;
    }

}

menu

Codice (Java): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_item_share"
        android:showAsAction="ifRoom"
        android:title="Share"
        android:actionProviderClass="android.widget.ShareActionProvider"
        tools:ignore="AppCompatResource" />

</menu>
Grazie in anticipo  :-) :-) :-)