Android, Snackbar没有可见view怎么显示?
Android, How to display Snackbar without visible view?
我正在尝试显示在 snakbar 中收到的任何 SMS,即使用户不在我的应用程序中,是否可以显示它?
这是我之前使用 Toast 的代码:
public class SmsReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String message = sms.getDisplayMessageBody();
Toast toast= Toast.makeText(context ,message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 150);
toast.show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
参考http://developer.android.com/reference/android/support/design/widget/Snackbar.html
Snackbar will try and find a parent view to hold Snackbar's view from the value given to view.
在这种情况下,您应该使用 Toast 或 Notification!
我正在尝试显示在 snakbar 中收到的任何 SMS,即使用户不在我的应用程序中,是否可以显示它?
这是我之前使用 Toast 的代码:
public class SmsReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String message = sms.getDisplayMessageBody();
Toast toast= Toast.makeText(context ,message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 150);
toast.show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
参考http://developer.android.com/reference/android/support/design/widget/Snackbar.html
Snackbar will try and find a parent view to hold Snackbar's view from the value given to view.
在这种情况下,您应该使用 Toast 或 Notification!