请问解决这个问题的最佳方法是什么?我在我的 android 应用程序中设置了 GCM 通知,它工作正常,但是,当单击状态栏上的通知以打开位于 src/www/中的 index.html 时,我需要它。
请。认真等待您的预期帮助。谢谢。
最佳答案
您可以创建一个 Activity ,该 Activity 可以在布局中使用 webView 访问您的 src/www/index.html
只需编写以下代码:
在assets中制作www文件夹
String mFileName = "file:///android_asset/www/index.html";
WebView mWebView = (WebView) findViewById(R.id.web_view);
WebSettings settings = mWebView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
mWebView.loadUrl(mFileName);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().length() == 0) {
return false;
}
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} catch (Exception e) {
CustomizeCrouton.showCrouton(R.string.no_browser, AboutUsActivity.this);
return false;
}
}
@Override
public void onPageFinished(WebView view, String url) {
mSpinnerDlg.dismiss();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
mSpinnerDlg.dismiss();
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
然后在点击通知时通过 PendingIntent 调用这个 Activity
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, RawFolderContentActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
关于android - 如何从 android gcm 通知打开 src/www/index.html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27484364/