質問編集履歴

2

書式の改善

2017/10/07 10:47

投稿

S.I
S.I

スコア48

test CHANGED
File without changes
test CHANGED
@@ -2,27 +2,27 @@
2
2
 
3
3
  プログラミング初心者です。android studioでのアプリ開発について。
4
4
 
5
- ボタンを押したら自作の”Qr Code Scanner”というプロジェクトへ画面遷移させたいのですが、エミュレーターで実行するとボタンを押したらエラーになります。どなたか回答よろしくお願いします。
5
+ ボタンを押したら自作の”Qr Code Scanner”というへ画面遷移させたいのですが、エミュレーターで実行するとボタンを押したらエラーになります。どなたか回答よろしくお願いします。
6
6
 
7
7
 
8
8
 
9
+
10
+
11
+ ボタンを配置しているアクティビティのクラス
12
+
9
13
  ```java
10
14
 
11
- package com.example.a1881.myapplication;
15
+ package com.example.nakahara.sample;
12
16
 
13
17
 
14
18
 
15
19
  import android.content.Intent;
16
-
17
- import android.net.Uri;
18
20
 
19
21
  import android.support.v7.app.AppCompatActivity;
20
22
 
21
23
  import android.os.Bundle;
22
24
 
23
25
  import android.view.View;
24
-
25
- import android.widget.Button;
26
26
 
27
27
 
28
28
 
@@ -40,40 +40,126 @@
40
40
 
41
41
 
42
42
 
43
- Button btn = (Button)findViewById(R.id.button);
44
-
45
- btn.setOnClickListener(new View.OnClickListener() {
46
-
47
-
48
-
49
- @Override
50
-
51
- public void onClick(View v) {
52
-
53
- // TODO Auto-generated method stub
54
-
55
- // インテントのインスタンス生成
56
-
57
- Intent intent = new Intent();
58
-
59
- // インテントにアクション及びURLをセット
60
-
61
- intent.setAction(Intent.ACTION_VIEW);
62
-
63
- intent.setData(Uri.parse("QrCodeScanner"));
64
-
65
- // ブラウザ起動
66
-
67
- startActivityForResult(intent, Integer.parseInt("QrCodeScanner"));
68
-
69
- }
70
-
71
- });
72
-
73
- }
74
-
75
43
  }
76
44
 
77
45
 
78
46
 
47
+ public void openQrCodeScanner(View view){
48
+
49
+ // インテントを生成する
50
+
51
+ Intent intent = new Intent();
52
+
53
+
54
+
55
+ // アクションを指定する
56
+
57
+ intent.setAction(Intent.ACTION_MAIN);
58
+
59
+
60
+
61
+ // カテゴリを追加する(サンプルでは独自のカテゴリを指定しています)
62
+
63
+ //intent.addCategory(Intent.CATEGORY_DEFAULT);
64
+
65
+ intent.addCategory("QrCodeScanner");
66
+
67
+
68
+
69
+ // アプリを起動する
70
+
71
+ startActivity(intent) ;
72
+
73
+
74
+
75
+ }
76
+
77
+ }
78
+
79
79
  ```
80
+
81
+
82
+
83
+ "Qr Code Scanner"のマニフェストファイルです
84
+
85
+ ```java
86
+
87
+ <?xml version="1.0" encoding="utf-8"?>
88
+
89
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
90
+
91
+ package="com.kaola.qrcodescanner">
92
+
93
+
94
+
95
+ <uses-permission android:name="android.permission.CAMERA"/>
96
+
97
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
98
+
99
+ <uses-permission android:name="android.permission.VIBRATE"/>
100
+
101
+
102
+
103
+ <uses-feature
104
+
105
+ android:name="android.hardware.camera"
106
+
107
+ android:required="false"/>
108
+
109
+ <uses-feature
110
+
111
+ android:name="android.hardware.camera.flash"
112
+
113
+ android:required="false"/>
114
+
115
+
116
+
117
+ <application
118
+
119
+ android:name=".qrcode.QrCodeApplication"
120
+
121
+ android:allowBackup="true"
122
+
123
+ android:icon="@mipmap/ic_launcher"
124
+
125
+ android:label="@string/app_name"
126
+
127
+ android:supportsRtl="true"
128
+
129
+ android:theme="@style/Theme.AppCompat.NoActionBar">
130
+
131
+ <activity android:name=".qrcode.QrCodeActivity">
132
+
133
+ <intent-filter>
134
+
135
+ <action android:name="android.intent.action.MAIN"/>
136
+
137
+ <category android:name="android.intent.category.LAUNCHER"/>
138
+
139
+ </intent-filter>
140
+
141
+ <intent-filter>
142
+
143
+ <action android:name="android.intent.action.MAIN" />
144
+
145
+ <category android:name="android.intent.category.DEFAULT" />
146
+
147
+ <category android:name="android.intent.category.BROWSABLE" />
148
+
149
+ <data android:scheme="http" />
150
+
151
+ </intent-filter>
152
+
153
+
154
+
155
+ </activity>
156
+
157
+ </application>
158
+
159
+
160
+
161
+ </manifest>
162
+
163
+
164
+
165
+ ```

1

コード記述に変更

2017/10/07 10:47

投稿

S.I
S.I

スコア48

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
-
9
+ ```java
10
10
 
11
11
  package com.example.a1881.myapplication;
12
12
 
@@ -73,3 +73,7 @@
73
73
  }
74
74
 
75
75
  }
76
+
77
+
78
+
79
+ ```