Created
March 24, 2018 13:46
-
-
Save ashishgkwd534/4f19e4de5374cfb58e09a5d1f31fc5cf to your computer and use it in GitHub Desktop.
null point exception to edit text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ags.softech.bottomnavigation.fragment; | |
import android.Manifest; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.telephony.SmsManager; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
import com.ags.softech.bottomnavigation.R; | |
import com.karumi.dexter.Dexter; | |
import com.karumi.dexter.PermissionToken; | |
import com.karumi.dexter.listener.PermissionDeniedResponse; | |
import com.karumi.dexter.listener.PermissionGrantedResponse; | |
import com.karumi.dexter.listener.PermissionRequest; | |
import com.karumi.dexter.listener.single.PermissionListener; | |
/** | |
* A simple {@link Fragment} subclass. | |
*/ | |
public class SMSFragment extends Fragment { | |
Button send; | |
EditText contact,msg; | |
View view; | |
public SMSFragment() { | |
// Required empty public constructor | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
view = inflater.inflate(R.layout.fragment_sm, container, false); | |
send=(Button) view.findViewById(R.id.btn_Send); | |
contact=(EditText) view.findViewById(R.id.txt_Number); | |
msg=(EditText) view.findViewById(R.id.txt_Msg); | |
send.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Dexter.withActivity(getActivity()) | |
.withPermission(Manifest.permission.SEND_SMS) | |
.withListener(new PermissionListener() { | |
@Override | |
public void onPermissionGranted(PermissionGrantedResponse response) { | |
//Toast.makeText(view.getContext(),"err",Toast.LENGTH_LONG); | |
final String con=contact.getText().toString(); | |
final String msg1=msg.getText().toString(); | |
//Toast.makeText(view.getContext(),"values accepted",Toast.LENGTH_LONG); | |
try{ | |
SmsManager.getDefault().sendTextMessage(con,null,msg1,null,null); | |
}catch (Exception e1){ | |
// Toast.makeText(view.getContext(),"massege not sent",Toast.LENGTH_LONG); | |
} | |
/*Intent smsintent=new Intent(Intent.ACTION_VIEW); | |
smsintent.setData(Uri.parse("smsto:")); | |
smsintent.setType("vnd.android-dir/mms-sms"); | |
smsintent.putExtra("address" , contact.getText().toString()); | |
smsintent.putExtra("sms_body" , "Test SMS to Angilla"); | |
try { | |
startActivity(smsintent); | |
//finish(); | |
Log.i("Finished sending SMS...", ""); | |
} catch (android.content.ActivityNotFoundException ex) { | |
Toast.makeText(getContext(), | |
"SMS faild, please try again later.", Toast.LENGTH_SHORT).show(); | |
}*/ | |
} | |
@Override | |
public void onPermissionDenied(PermissionDeniedResponse response) { | |
} | |
@Override | |
public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { | |
} | |
}).onSameThread().check(); | |
} | |
}); | |
return view; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment