سؤال

لم أتطور أبدًا لنظام Android من قبل ، لذا يرجى النظر لي بنسبة 100 ٪ عند الإجابة :)

أرغب في إنشاء قاذفة تطبيق سيفتح متصفح الويب الافتراضي على عنوان URL معين. بمعنى آخر ، أريد إنشاء أيقونة مع شعار موقع الويب الخاص بي ، وعندما تنقر عليها ، فإنه يفتح الموقع في متصفح الويب الافتراضي الخاص بك.

هل يمكن لأي شخص أن يوجهني نحو صفحة تعليمية/وثائق لتحقيق ذلك؟ أو إذا كان الأمر بسيطًا حقًا ، فربما أرني بعض التعليمات البرمجية هنا؟

شكرا على وقتك!

ص

هل كانت مفيدة؟

المحلول

إذا فهمت ما تحتاجه بشكل صحيح ، فيمكنك فقط إنشاء تطبيق بسيط مع نشاط واحد فقط وإلصاق هذا في oncreate:

Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.yourwebsite.com"));  
startActivity(viewIntent);

وهنا بعض الموارد على إنشاء تطبيق بسيط:

http://developer.android.com/resources/samples/apidemos/src/com/example/android/apis/appis/helloworld.html

وهنا بعض المعلومات حول كيفية تعيين أيقونة التطبيق الخاصة بك:

http://www.connorgarvey.com/blog/؟p=97

نصائح أخرى

لقد كتبت برنامج تعليمي لهذا فقط: = د

http://www.anddev.org/code-snippets-for-droid-f33/button-to-open-web-browser-t48534.html

النسخة المعدلة:

package com.blundell.twitterlink;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sendToTwitter();         // Open the browser
        finish();                // Close this launcher app
    }

    protected void sendToTwitter() {
        String url = "http://twitter.com/blundell_apps"; // You could have this at the top of the class as a constant, or pass it in as a method variable, if you wish to send to multiple websites
        Intent i = new Intent(Intent.ACTION_VIEW); // Create a new intent - stating you want to 'view something'
        i.setData(Uri.parse(url));  // Add the url data (allowing android to realise you want to open the browser)
        startActivity(i); // Go go go!
    }
}

إجابة سطر واحد

startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));

لماذا تريد إنشاء تطبيق للقيام بذلك؟ يمكنك فقط إنشاء اختصار مباشرة على شاشتك الرئيسية.

هذا ما يجب القيام به:
1. انتقل إلى الموقع في متصفحك
2. أضف إشارة مرجعية للموقع (القائمة ، إضافة إشارة مرجعية)
3. انتقل إلى الشاشة الرئيسية حيث تريد الشعار
4. اضغط مع الاستمرار على الشاشة ، عندما تنبثق القائمة حدد "إضافة اختصار"
5. حدد "مرجعية"
6. ابحث عن المرجعية التي قمت بإنشائها للتو وانقر عليها

انتهيت!!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top