मैंने आपके कार्यक्रम में लोगों से मदद मांगी, और ऐसा लगता है कि यह काम करेगा। अगर मैं काम करने के लिए थ्रेडिंग/asynctask प्राप्त कर सकते हैं। मैंने पहले से ही थ्रेडिंग पर काम करने की कोशिश की और मुझे इसे काम नहीं मिला। कारण मैं थ्रेडिंग करने की कोशिश कर रहा हूं क्योंकि मेरा प्रोग्राम इसे लोड करते समय दुर्घटनाग्रस्त हो जाता है, और मूल रूप से ऐसा करने का अनुमान है कि अगर कोई कॉल कर रहा है तो ईमेल भेजना है, क्योंकि मैं हमेशा अपने फोन को गलत जगह देता हूं या चुप रहता हूं, और मैं मुझे इसके बारे में पता नहीं है।क्या कोई मुझे मेरे कार्यक्रम के लिए थ्रेडिंग समझने में मदद कर सकता है?
public class MainActivity extends Activity {
//Callservice callservice = new Callservice();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startService(new Intent(this,Callservice.class));
}
// your code here...
और सुनिश्चित करें कि आपके:
सेवा-
public class Callservice extends Service {
PhoneStateListener listener;
TelephonyManager tm;
@Override
public void onCreate()
{
Toast.makeText(getApplicationContext(), "Service has started", Toast.LENGTH_LONG).show();
listener = new MyphoneStateListener();
tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
public class MyphoneStateListener extends PhoneStateListener
{
public void onCallStateChanged(int state, String incomingNumber)
{
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_RINGING:
sendemail();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
private void sendemail()
{
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT , "phone is ringing");
i.putExtra(Intent.EXTRA_TEXT , "email successfully sent");
startActivity(Intent.createChooser(i, "send mail..."));
Toast.makeText(getApplicationContext(), "Email has been sent", Toast.LENGTH_LONG).show();
try
{
startActivity(Intent.createChooser(i, "Send Email..."));
}
catch(android.content.ActivityNotFoundException ex)
{
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
गतिविधि-
public class MainActivity extends Activity {
Callservice callservice = new Callservice();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callservice.onCreate();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
अपनी लॉग कैट संलग्न करें। –
यहाँ या जाओ। http://pastebin.com/GnyKatuS – andyADD
@ user1884552: क्या है क्रिएट (MainActivity.java:26) आपकी गतिविधि को लाइन करें? –