Android : How to use implicit intent from non activity class and in fragment

on Monday, January 19, 2015



public class HomeFragment extends Fragment {
ShareLink statLoc;

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

statLoc = new ShareLink();
statLoc.execute();
}


The above code is my fragment and am executing a class named ShareLink(). In that ShareLink class I used implicit intent to send data like below



public class ShareLink extends AsyncTask<String, String, String> {

String urlShare = DeviceIdGen.hmUrl;

String statusLoc = null;
public static String locLink = null;
private static String loc = null;
Context context;
String locUrl;

protected String doInBackground(String... params) {

WebServiceTasks wstShare = new WebServiceTasks();
return wstShare.getMethod(urlShare);
}

protected void onPostExecute(String result) {
super.onPostExecute(result);

try {
JSONObject jResult = new JSONObject(result);
statusLoc = jResult.getString("status");

if (statusLoc.equals("success")) {
loc = jResult.getString("link");
locUrl = "My Current Location :" + locLink + "\n\n"
+ "My Key : " + loc;

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
startActivity((emailIntent).putExtra(
android.content.Intent.EXTRA_TEXT, locUrl));
}
} catch (JSONException e) {

e.printStackTrace();
}}}


But am not able to achieve it. Please help as am a newbie


0 comments:

Post a Comment