How to choose a Phone Call in Android - android

When I click phone call button, how to choose skype, viber, sim1 or sim2, ect. Now, it is called by sim2. I want to choose. I search on Google, no found my problem.
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
Permissions in Manifest
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Reset App preferences before starting intent
Settings->Apps/Application Manager -> Default/Downloaded Apps -> Click on overflow icon (i.e. three dots icon on top right of the screen) -> Reset App Preferences.
Your code looks fine.
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}

You need to create a sim chooser dialog and set sim 1 and sim 2 options and set simNumber variable according to the choosen sim number(0 for sim1 and 1 for sim2)
Here is the code that I have implemented for calling from specific sim i.e. SIM 1 or SIM 2.
code:
private final static String simSlotName[] = {
"extra_asus_dial_use_dualsim",
"com.android.phone.extra.slot",
"slot",
"simslot",
"sim_slot",
"subscription",
"Subscription",
"phone",
"com.android.phone.DialingMode",
"simSlot",
"slot_id",
"simId",
"simnum",
"phone_type",
"slotId",
"slotIdx"
};
int simNumber = 0 or 1; //0 for sim1 and 1 for sim2
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ phoneNumber));
callIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Add slots here since different device needs different key so put all together
for (String s : simSlotName)
intent.putExtra(s, simNumber);
//This will only work on API 22 or up
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) SimSlotHelper.getAccountHandles(context).get(simNumber))
context.startActivity(intent);
Here is a class for sim slot helper which will get phone account handle list by using telecom manager for both sims
code:
public class SimSlotHelper {
public static List getAccountHandles(Context context) {
Class c;
Method m;
TelecomManager telecomManager;
List<PhoneAccountHandle> accountHandles;
TelephonyManager telephony;
telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
c = Class.forName("android.telecom.TelecomManager");
Method m1 = c.getMethod("from", Context.class);
telecomManager = (TelecomManager) m1.invoke(null, context);
m = c.getMethod("getCallCapablePhoneAccounts");
accountHandles = (List<PhoneAccountHandle>) m.invoke(telecomManager);
return accountHandles;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}

Try using .ACTION_DIAL instead of .ACTION_CALL . This opens a Dialog chooser with apps installed in the device with capability of calling.
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}

Related

Solution For getting Mobile Number in Android [duplicate]

This question already has answers here:
MSISDN : Is it a SIM Card Data? Why all The Provided Function (from Blackberry and Android) to fetch MSISDN not reliable?
(3 answers)
Closed 5 years ago.
Using Telephony Manager returns null value for Mobile number, I want to get Mobile Number directly in to the app without asking user.
You can use the TelephonyManager to do this:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The getLine1Number() will return null if the number is "unavailable", but it does not say when the number might be unavailable.
You'll need to give your application permission to make this query by adding the following to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Try the given below method for generating country code
private void getCountryCode() {
int code = 0;
TelephonyManager telephonyManager = (TelephonyManager) getActivity().
getSystemService(Context.TELEPHONY_SERVICE);
String CountryISO = telephonyManager.getSimCountryIso().toString().toUpperCase();
;
//String NetworkCountryIso = telephonyManager.getNetworkCountryIso().toString();
String number = telephonyManager.getLine1Number();
code = getCountryCodeForRegion(CountryISO);
Log.i("CountryISO", "CountryISO " + CountryISO);
Log.i("code", "code " + code);
Log.i("number ", "number " + number);
}
Gets CountryCode from regionCode
public int getCountryCodeForRegion(String regionCode) {
int result = -1;
try {
Class c = Class.forName("com.android.i18n.phonenumbers.PhoneNumberUtil");
Method getInstance = c.getDeclaredMethod("getInstance");
Method getCountryCodeForRegion = c.getDeclaredMethod("getCountryCodeForRegion", String.class);
Object instance = getInstance.invoke(null);
Integer code = (Integer) getCountryCodeForRegion.invoke(instance, regionCode);
result = code;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} finally {
return result;
}
}
Don't forget to add permission in AndroidManifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

How to wait until user enables mobile data and send mail?

I have a task in which I have to send E-Mail each day once.
I used Service triggered by AlarmManager to achieve this. It's working properly. But the problem is the mail gets send only if the mobile data is available. So I tried to turn on the data connection and send mail. Mobile data is enabled but, Mail not sending. I have posted here what I've tried. Someone please suggest a method to wait until the user turn on mobile data and send mail. Thank you.
cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
ni=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
isConnected=ni!=null&&ni.isConnected();
Mail m=new Mail("xxxxxxxxx#gmail.com","xxxxxxx");
String[] strTo={"xxxxxxxxx#gmail.com"};
m.setTo(strTo);
m.setFrom("xxxxxxxxxx#gmail.com");
m.setSubject("Subject");
m.setBody("Please find the attachment");
try{
m.addAttachment(Environment.getExternalStorageDirectory() + "/xxxxx/xxxxxx.xx");
if (isConnected){
m.send();
}else {
ConnectivityManager dataManager;
dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd = null;
try {
dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
dataMtd.setAccessible(true);
try {
dataMtd.invoke(dataManager, true);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
NetworkInfo netInfo=dataManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isOnline=netInfo!=null&&netInfo.isConnected();
if(isOnline){
if (m.send()){
ConnectivityManager dataManager1;
dataManager1 = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd1 = null;
try {
dataMtd1 = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
dataMtd1.setAccessible(false);
try {
dataMtd1.invoke(dataManager1, false);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}catch (final Exception e){
e.printStackTrace();
Log.v("My_Service",e.toString());
}
You need to have BroadcastReceiver listening to change in data connectivity. Refer to - http://developer.android.com/reference/android/content/BroadcastReceiver.html
Check this for reference specific to network connectivity - Check INTENT internet connection
Don't relay on Google shit api... Info to the user to enable data + post delayed eg time task :) u can not handle all problems by enabling data.. But u can check for most : There could by a firewall issue , DNS issue, TTL issue when theter etc
You can register a BroadcastReceiver to be notified when a Mobile data is enabled.
Register the BroadcastReceiver:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(broadcastReceiver, intentFilter);
And then in your BroadcastReceiver do something like this:
#Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION))) {
if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)){
// data connection was lost
} else {
// do your stuff
}
}
}
For more info, see the documentation for BroadcastReceiver
You can use below link to send mail :
How to send mail without user interaction from another application

Pairing two android bluetooth devices without any passkey popup

I want to pair two android bluetooth devices (Kitkat) without any popup for passkey exchange. I tried setpin() and cancelPairingUserInput() methods inside the broadcast receiver for PAIRING_REQUEST intent using reflection, but got no results. Can anyone help me with that ?
if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)){
BluetoothDevice localBluetoothDevice = (BluetoothDevice)intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
try {
Log.d("setPin()", "Try to set the PIN");
Method m = localBluetoothDevice.getClass().getMethod("setPin", byte[].class);
m.invoke(localBluetoothDevice, ByteBuffer.allocate(4).putInt(1234).array());
Log.d("setPin()", "Success to add the PIN.");
} catch (Exception e) {
Log.e("setPin()", e.getMessage());
}
Class localClass = localBluetoothDevice.getClass();
Class[] arrayOfClass = new Class[0];
try {
localClass.getMethod("setPairingConfirmation", boolean.class).invoke(localBluetoothDevice, true);
localClass.getMethod("cancelPairingUserInput", arrayOfClass).invoke(localBluetoothDevice, null);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Did you try calling createBond() through reflection?
This works for me, with device being a BluetoothDevice:
Method m = device.getClass().getMethod("createBond", (Class[]) null);
m.invoke(device, (Object[]) null);
Get the device and the PIN (or the pairing key) from the given Intent
if the given PIN is not -1, set it in the device
invoke the device's .setPairingConfirmation() method
My code (which achieves this) in the .bluetoothEventReceived() callback method, looks something like this:
private void bluetoothEventRecieved(Context context, Intent intent)
{
if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int pin = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, -1);
if (pin != -1) {
byte[] pinBytes = String.format(Locale.US, "%04d", pin).getBytes();
device.setPin(pinBytes);
}
device.setPairingConfirmation(true);
}
}

How to pair Bluetooth device programmatically Android

I am developing an application where I want to connect a Bluetooth device main issue is I don't want user to enter required pin instead application should do that by himself...I don't have any connection related issue...Only want to insert and complete pin authentication process by application itself.
I found following code I am sure it is working but not sure on how to add pin in this code??
private void pairDevice(BluetoothDevice device) {
try {
Log.d("pairDevice()", "Start Pairing...");
Method m = device.getClass().getMethod("createBond", (Class[]) null);
m.invoke(device, (Object[]) null);
Log.d("pairDevice()", "Pairing finished.");
} catch (Exception e) {
Log.e("pairDevice()", e.getMessage());
}
}
Does anyone know how to enter pin in above code or any similar code to solve problem..
Thank You
How can I avoid or dismiss Android's Bluetooth pairing notification when I am doing programmatic pairing?
This seems to give you the answer, with the pin entering and all. It involves sending .setPin() whenever you get the message.
So, I had this question, if someone needs the answer to this working in android 4.4.2.
IntentFilter filter = new IntentFilter(
"android.bluetooth.device.action.PAIRING_REQUEST");
/*
* Registering a new BTBroadcast receiver from the Main Activity context
* with pairing request event
*/
registerReceiver(
new PairingRequest(), filter);
And the code for the Receiver.
public static class PairingRequest extends BroadcastReceiver {
public PairingRequest() {
super();
}
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) {
try {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int pin=intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 0);
//the pin in case you need to accept for an specific pin
Log.d("PIN", " " + intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY",0));
//maybe you look for a name or address
Log.d("Bonded", device.getName());
byte[] pinBytes;
pinBytes = (""+pin).getBytes("UTF-8");
device.setPin(pinBytes);
//setPairing confirmation if neeeded
device.setPairingConfirmation(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
And in the manifest file.
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
And the broadcastReceiver.
<receiver android:name=".MainActivity$PairingRequest">
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
<action android:name="android.bluetooth.device.action.PAIRING_CANCEL" />
</intent-filter>
</receiver>
How to set the pin code has been answered above (and that helped me). Yet, I share my simple code below which works with Android 6:
BluetoothAdapter mBTA = BluetoothAdapter.getDefaultAdapter();
if (mBTA.isDiscovering()) mBTA.cancelDiscovery();
mBTA.startDiscovery();
...
/** In a broadcast receiver: */
if (BluetoothDevice.ACTION_FOUND.equals(action)) { // One device found.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.d(TAG, "Start Pairing... with: " + device.getName());
device.createBond();
}
// If you want to auto-input the pin#:
else if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)){
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
device.setPin("1234".getBytes());
}
Try this code:
public void pairDevice(BluetoothDevice device)
{
String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
Intent intent = new Intent(ACTION_PAIRING_REQUEST);
String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
intent.putExtra(EXTRA_DEVICE, device);
String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
int PAIRING_VARIANT_PIN = 0;
intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);
intent.putExtra(EXTRA_DEVICE, device);
int PAIRING_VARIANT_PIN = 272;
intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
sendBroadcast(intent);
Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
startActivityForResult(intent, REQUEST_PAIR_DEVICE);
I hope this helps
Reference: http://pastebin.com/N8dR4Aa1
Register a BluetoothDevice.ACTION_PAIRING_REQUEST receiver onCreate()
val pairingRequestFilter = IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST)
registerReceiver(pairingReceiver, pairingRequestFilter)
on receiver set your pin using setPin() and call abortBroadcast()
val PAIRING_PIN=1234
private var pairingReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent!!.action
if (BluetoothDevice.ACTION_PAIRING_REQUEST == action) {
val device: BluetoothDevice? =intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
val type =intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR)
if (type == BluetoothDevice.PAIRING_VARIANT_PIN) {
device?.setPin(PAIRING_PIN.toByteArray())
abortBroadcast()
}
}
}
}
Don't forget to unregister receiver on onDestroy()
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(pairingReceiver)
}
if it doesn't work for you, try setting hight priority to receiver
val pairingRequestFilter = IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST)
pairingRequestFilter.priority = IntentFilter.SYSTEM_HIGH_PRIORITY - 1
registerReceiver(pairingReceiver, pairingRequestFilter)
Also you can register a receiver with BluetoothDevice.ACTION_BOND_STATE_CHANGED to read status of pairing
val filter = IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
registerReceiver(receiver, filter)
Try this,
BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
device.getClass().getMethod("cancelPairingUserInput", boolean.class).invoke(device);
BluetoothSocket bluetoothSocket = null;
try {
bluetoothSocket = device.createRfcommSocketToServiceRecord(UUID.fromString(UUID_DIVING));
} catch (IOException e) {
Log.i("Bluetooth", "IOException = " + e.getMessage());
e.printStackTrace();
}
try {
byte[] pin = (byte[]) BluetoothDevice.class.getMethod("convertPinToBytes", String.class).invoke(BluetoothDevice.class, "0000");
Method m = device.getClass().getMethod("setPin", byte[].class);
m.invoke(device, (Object) pin);
device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Log.i("Bluetooth", "IOException = " + e.getMessage());
e.printStackTrace();
}
try {
if (bluetoothSocket != null) {
bluetoothSocket.connect();
Log.i("Bluetooth", "bluetoothSocket.connect() ");
InputStream inputStream = bluetoothSocket.getInputStream();
OutputStream outputStream = bluetoothSocket.getOutputStream();
}
} catch (IOException e) {
e.printStackTrace();
}
bluetoothDevice.createBond method , you can use for paring
For checking paring status , you have to register broadcast receiver
BluetoothDevice.ACTION_BOND_STATE_CHANGED
In your receiver class, you can check blueToothDevice.getBondState

Create new local calendar in android pre ICS

I have been struggelig for weeks on this, so now I hope someone here can give me some clarity.
The project I'm working on(pre ICS) includes logging on to my company's server, getting my future work schedule and store this on my phone in a seperate calendar. This calendar should them be viewable in all the major calendar apps (Jorte, Business Calendar, Smooth Calendar ++).
I got the schedule parsed and stored on the phone in an SQLite database. But my struggle is getting from there to create a seperate local calendar and store all the events there. I assumed I had to create an account for this (not to mess up any other account on the phone. That worked well with the code:
AccountManager man = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account acc = new Account("myCalendar", "com.lumabyte.mycalendar");
But I thought creating a calendar on that account would be quite easy with:
ContentValues calendar = new ContentValues();
calendar.put("_sync_account", "myCalendar"); // My account
calendar.put("_sync_account_type","com.lumabyte.mycalendar");
calendar.put("name", "myCalendar");
calendar.put("displayName", "myCalendar");
calendar.put("hidden",0);
calendar.put("color",0xFF008080);
calendar.put("access_level", 700);
calendar.put("sync_events", 1);
calendar.put("timezone", "Europe/Paris");
calendar.put("ownerAccount", sync_account);
Uri calendarUri = Uri.parse(getCalendarUriBase() + "calendars");
this.getContentResolver().insert(calendarUri, calendar);
The function getCalendarUriBase():
private String getCalendarUriBase() {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = this.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = this.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
managedCursor.close();
return calendarUriBase;
}
The manifest includes:
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MAMAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CALENDAR">
<uses-permission android:name="android.permission.WRITE_CALENDAR">
and my authenticator.xml is like this:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.lumabyte.mycalendar"
android:icon="#drawable/icon"
android:smallIcon="#drawable/icon"
android:label="#string/authenticator_label"
/>
I do not get any error messages, but only the account is created, and not the calendar. Is there a small error in the code, or have I misunderstood the whole concept. I know there is no API pre ICS, and that there is risks involved. But I need it done anyway. Prefeably stable on as many phones as possible. Any help or examples would be greatly appreciated.
I'll work with ICS later as I understand they now have i public API for that.
r
hiii rudder............. I have add a calender in 2.3.6 using the following code after lot of R&D.........
ContentValues calendar=new ContentValues();
Uri calendarUri =Uri.parse(getBaseCalUri() + "/calendars");
calendar.put("_sync_account", "Test1");
calendar.put("_sync_account_type", "LOCAL");
calendar.put("name", "CalenTest");
calendar.put("displayName", "calDispName");
calendar.put("color", 0xFF008080);
calendar.put("access_level", 700);
calendar.put("ownerAccount", true);
calendar.put("sync_events", 1);
calendarUri = calendarUri.buildUpon()
.appendQueryParameter("_sync_account", "Test1")
.appendQueryParameter("_sync_account_type", "LOCAL")
.build();
Uri result = getContentResolver().insert(calendarUri, calendar);
and my getBaseCalUri() is
private Uri getBaseCalUri(){
Class<?> calendarProviderClass;
Field uriField;
Uri calendarUri=null;
try {
calendarProviderClass = Class.forName("android.provider.Calendar");
uriField = calendarProviderClass.getField("CONTENT_URI");
calendarUri = (Uri) uriField.get(null);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return calendarUri;
}
try this....
Just add a records in the calendar.db
/data/data/com.android.providers.calendar/databases/calendar.db
as
sqlite3 calendar.db "insert into Calendars (_id,name,displayName,access_level) values (0,'Local','MyCal',700)"
This is a good way that I tried, I hope it helps:
/**
* Add a calendar event.
*/
private void addCalendarEvent(){
Context context = getContext();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("beginTime", stTime);
intent.putExtra("allDay", true);
intent.putExtra("description", description);
intent.putExtra("eventLocation", place);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", enTime);
intent.putExtra("title", category);
context.startActivity(intent);
}

Categories

Resources