Programming Mobile Applications for Android Handheld Systems by Dr. Adam Porter

 

 

Lab - Intents

启动程序

Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
    private void startExplicitActivation() {
        Log.i(TAG,"Entered startExplicitActivation()");        
        // TODO - Create a new intent to launch the ExplicitlyLoadedActivity class
        Intent intent=new Intent(ActivityLoaderActivity.this, ExplicitlyLoadedActivity.class);
        startActivityForResult(intent, 0);
        // TODO - Start an Activity using that intent and the request code defined above
    }
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
private void startImplicitActivation() {

        Log.i(TAG, "Entered startImplicitActivation()");

        // TODO - Create a base intent for viewing a URL 
        // (HINT:  second parameter uses parse() from the Uri class)
        Uri webpage = Uri.parse("http://www.google.com");
        Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
        
        // TODO - Create a chooser intent, for choosing which Activity
        // will carry out the baseIntent. Store the Intent in the 
        // chooserIntent variable below. HINT: using the Intent class‘ 
        // createChooser
        
        Intent chooserIntent = Intent.createChooser(webIntent, "CHOOSER");
        Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
        // TODO - Start the chooser Activity, using the chooser intent
        startActivity(chooserIntent);
    }
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter

关联程序

Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
        <activity
            android:name=".MyBrowserActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
                  <category android:name="android.intent.category.BROWSABLE" />
                 <data android:scheme="http" />
            </intent-filter>
  
            <!-- TODO - Add necessary intent filter information so that this
                            Activity will accept Intents with the 
                            action "android.intent.action.VIEW" and with an "http" 
                            schemed URL -->
        </activity>
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter

 

Lab - Permissions

读取书签--使用权限

<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
private void loadBookmarks() {

        Log.i(TAG, "Entered loadBookmarks()");

        String text = "";

        Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI,
                projection, null, null, null);

        query.moveToFirst();
        while (query.moveToNext()) {

            text += query.getString(query
                    .getColumnIndex(Browser.BookmarkColumns.TITLE));
            text += "\n";
            text += query.getString(query
                    .getColumnIndex(Browser.BookmarkColumns.URL));
            text += "\n\n";

        }

        TextView box = (TextView) findViewById(R.id.text);
        box.setText(text);

        Log.i(TAG, "Bookmarks loaded");
    }
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter

自定义权限

Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter
    <permission android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM" android:protectionLevel="dangerous"></permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <!-- TODO - enforce the custom permission on this Activity -->

        <activity
            android:name=".DangerousActivity"
            android:label="@string/app_name" >

            <!--
                 TODO - add additional intent filter info so that this Activity
                  will respond to an Implicit Intent with the action
                  "course.labs.permissions.DANGEROUS_ACTIVITY"
            -->


            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="course.labs.permissions.DANGEROUS_ACTIVITY"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
Programming Mobile Applications for Android Handheld Systems by 
Dr. Adam Porter

Programming Mobile Applications for Android Handheld Systems by Dr. Adam Porter

上一篇:android 之WIFI操作


下一篇:Android接收短信