Last active
August 24, 2016 13:50
-
-
Save kltz/0947ce7ebdf6c957d7a89e1905bfeb2b to your computer and use it in GitHub Desktop.
Android emulator call log generator for developers.
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
import android.content.ContentResolver; | |
import android.content.ContentValues; | |
import android.os.Bundle; | |
import android.provider.CallLog; | |
import android.support.v7.app.AppCompatActivity; | |
import java.sql.Timestamp; | |
import java.util.Date; | |
import java.util.Random; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_call_log_generator); | |
final Random random = new Random(); | |
phoneNumberGenerator(150, random); | |
} | |
public void phoneNumberGenerator(int count, Random random) { | |
int num1, num2, num3; | |
int set2, set3; | |
for (int i = 0; i < count; i++) { | |
num1 = random.nextInt(7) + 1; | |
num2 = random.nextInt(8); | |
num3 = random.nextInt(8); | |
set2 = random.nextInt(643) + 100; | |
set3 = random.nextInt(8999) + 1000; | |
insertPlaceholderCall(getContentResolver(), "+" + num1 + num2 + num3 + set2 + set3, random); | |
} | |
} | |
public void insertPlaceholderCall(ContentResolver contentResolver, String number, Random random) { | |
ContentValues values = new ContentValues(); | |
values.put(CallLog.Calls.NUMBER, number); | |
values.put(CallLog.Calls.DATE, dateGenerator()); | |
values.put(CallLog.Calls.DURATION, random.nextInt(3600)); | |
values.put(CallLog.Calls.TYPE, random.nextInt(3) + 1); | |
values.put(CallLog.Calls.NEW, 1); | |
contentResolver.insert(CallLog.Calls.CONTENT_URI, values); | |
} | |
public long dateGenerator() { | |
long offset = Timestamp.valueOf("2016-01-01 00:00:00").getTime(); | |
long end = new Date().getTime(); | |
long diff = end - offset + 1; | |
Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff)); | |
return rand.getTime(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment