常规功能

1 发送SMS
权限 <uses-permission android:name="android.permission.SEND_SMS"/>
代码 SmsManager m = SmsManager.getDefault();
String destinationNumber ="0123456789";
String text = "Hello, MOTO!";
m.sendTextMessage(destinationNumber, null, text, null, null);

2 显示Toast
权限
代码 Toast.makeText(this, "Put your message here", Toast.LENGTH_SHORT).show();

3 状态栏通知
权限
代码 int notificationID = 10;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create the notification
Notification notification = new Notification(R.drawable.yourIconId, "Put your notification text here", System.currentTimeMillis());
// Create the notification expanded message
// When the user clicks on it, it opens your activity
Intent intent = new Intent(this, YourActivityName.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "Put your title here", "Put your text here", pendingIntent);
// Show notification
notificationManager.notify(notificationID, notification);

4 在给定时间内震动手机
权限 <uses-permission android:name="android.permission.VIBRATE"/>
代码 // Vibrate for 1000 miliseconds
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);

5 在开关模式后震动手机
权限 <uses-permission android:name="android.permission.VIBRATE"/>
代码 // Vibrate in a Pattern with 0ms off(start immediately), 200ms on, 100ms off, 100ms on, 500ms off, 500ms on,
// repeating the pattern starting from index 4 - 100ms on.
// Note that you'll have to call vibrator.cancel() in order to stop vibrator.
// Change second parameter to -1 if you want play the pattern only once.
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(new long[] {0, 200, 100, 100, 500, 500}, 4);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值