G
G
GadZini2014-06-01 01:40:52
Android
GadZini, 2014-06-01 01:40:52

How to launch a component through an intent?

There are two activities. On 1- there is a "Create notification" button, after which the "notification creator" is launched on a separate activity, a notification is created (sorry for the tautology) through which the link goes. How to create an intention to call WebView on 1 activity, so that this link opened in it, not in the browser
public void onClick(View view) {
Context context = getApplicationContext();
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(" dtrek.dp.ua "));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("Look at the replacements")
.setTicker("Warning!").setWhen(System.currentTimeMillis()) // java.lang.System.currentTimeMillis()
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND).setAutoCancel (true)
.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ID, builder.build());
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
belozerow, 2014-06-01
@GadZini

Somehow the question is not very clearly formulated, but as I understand it, you need to open the activity from the webview by clicking on the notification. Now you are creating an Intent that all applications can process according to a certain scheme, but you need your specific Activity.

Intent notificationIntent = new Intent(context, MyWebViewActivity.class);
notificationIntent.putExtra("url", "dtrek.dp.ua");
...

And in MyWebViewActivity in onCreate method
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl(getIntent().getStringExtra("url"));

F
FoxInSox, 2014-06-01
@FoxInSox

What does "to call WebView" mean? A WebView is not "called", it's a UI component, like a Button, TextView, or ImageView. Accordingly, WebView must be present in the activity:

WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("http://slashdot.org/");

Documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question