int start =editText.getSelectionStart();
editText.getText().insert(start, ((Button) v).getText());
editText.requestFocus();
editText.setSelection(start+1);
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.readlogcatTest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.READ_LOGS" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".ReadLogcatActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
package com.readlogcatTest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ReadLogcatActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { Process process = Runtime.getRuntime().exec("logcat -d"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); StringBuilder log=new StringBuilder(); String line = ""; while ((line = bufferedReader.readLine()) != null) { log.append(line); } TextView tv = (TextView)findViewById(R.id.logcat); tv.setText(log.toString()); bufferedReader.close(); process.destroy(); } catch (IOException e) {e.printStackTrace(); } } }
package com.outsms.test; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class StartAtBootServiceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { Intent i = new Intent(); i.setAction("com.outsms.test.StartAtBootService"); context.startService(i); } } }
package com.outsms.test; import android.app.Service; import android.os.IBinder; public class OutGoingSMSTestService extends Service { @Override public void onCreate() { /* Do whatever you want when Srevice first created before started */ } @Override public int onStartCommand(Intent intent, int flags, int startId) { /* DO WHATEVER you want when service is started */ } @Override public void onDestroy() { /* do whatever you want when Service destroyed */ super.onDestroy(); } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.outsms.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <service android:name=".OutGoingSMSTestService"> <intent-filter> <action android:name="com.outsms.test.StartAtBootService"> </action> </intent-filter> </service> <receiver android:name=".StartAtBootServiceReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"> </action> <category android:name="android.intent.category.HOME"> </category> </intent-filter> </receiver> </application> </manifest>
//this is JSON String to put your information inside it String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"deviceid\":\""+deviceid+"\"}}"; HttpClient httpClient = new DefaultHttpClient(); // Post method to send data to server HttpPost post = new HttpPost(); post.setURI(new URI("http://myserver.com/myphppage.php")); // set your post data inside post method post.setEntity(new StringEntity(postData)); // execute post request here HttpResponse response = httpClient.execute(post);
package com.android.internal.telephony; public interface ITelephony { boolean endCall(); void answerRingingCall(); void silenceRinger(); }3. Create BroadCastReceiver in your project's package com.mydomain.testoutgoingcalls (your choice for packagename)
package com.mydomain.testoutgoingcalls; import java.lang.reflect.Method; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.Toast; import com.android.internal.telephony.ITelephony; public class CallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if(null == bundle) return; String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); String info = "Detect Calls sample application\nOutgoing number: " + phonenumber; Toast.makeText(context, info, Toast.LENGTH_LONG).show(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm); telephonyService.endCall(); } catch (Exception e) { System.out.println("error on end call : "+e.getMessage()); e.printStackTrace(); } } }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mydomain.testoutgoingcalls" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name=".MyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".CallReceiver"> <intent-filter> <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> <action android:name="android.intent.action.PHONE_STATE"/> </intent-filter> </receiver> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> </manifest>Now start debug and test it will work fine.