i use this code in my activity class :
public void Sms(String s){
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", s, null));
PackageManager packageManager = getPackageManager();
List activities = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
if(isIntentSafe)
{ startActivity(intent);
}else{
Toast.makeText(MainActivity.context,getString(R.string.actionNonSupportee),Toast.LENGTH_LONG).show();
}
}
it works very well
but when i use the same code in my fragment class
public void Sms(String s){
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", s, null));
PackageManager packageManager = getActivity().getPackageManager();
List activities = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
if(isIntentSafe)
{ startActivity(intent);
}else{
Toast.makeText(MainActivity.context,getString(R.string.actionNonSupportee),Toast.LENGTH_LONG).show();
}
}
the app crashes.
The only line I changed is :
PackageManager packageManager = getActivity().getPackageManager();
Aucun commentaire:
Enregistrer un commentaire